mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 07:45:54 +01:00
Added TMVCActiveRecord.TryGetSQLQuery<T> and TMVCActiveRecord.TryGetRQLQuery<T>
This commit is contained in:
parent
62a1344896
commit
7f6c3e2ea2
@ -645,7 +645,11 @@ type
|
||||
class function CountRQLByNamedQuery<T: TMVCActiveRecord, constructor>(
|
||||
const QueryName: string;
|
||||
const Params: array of const): Int64;
|
||||
|
||||
class function TryGetSQLQuery<T: TMVCActiveRecord, constructor>(
|
||||
const QueryName: String;
|
||||
out NamedSQLQuery: TSQLQueryWithName): Boolean; overload;
|
||||
class function TryGetRQLQuery<T: TMVCActiveRecord, constructor>(
|
||||
const QueryName: String; out NamedRQLQuery: TRQLQueryWithName): Boolean;
|
||||
{ RTTI }
|
||||
class function CreateMVCActiveRecord<T: TMVCActiveRecord>(AQualifiedClassName: string; const AParams: TArray<TValue> = nil): T;
|
||||
end;
|
||||
@ -2125,6 +2129,32 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
class function TMVCActiveRecordHelper.TryGetSQLQuery<T>(
|
||||
const QueryName: String; out NamedSQLQuery: TSQLQueryWithName): Boolean;
|
||||
var
|
||||
lT: T;
|
||||
begin
|
||||
lT := T.Create;
|
||||
try
|
||||
Result := lT.FindSQLQueryByName(QueryName, NamedSQLQuery);
|
||||
finally
|
||||
lT.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
class function TMVCActiveRecordHelper.TryGetRQLQuery<T>(
|
||||
const QueryName: String; out NamedRQLQuery: TRQLQueryWithName): Boolean;
|
||||
var
|
||||
lT: T;
|
||||
begin
|
||||
lT := T.Create;
|
||||
try
|
||||
Result := lT.FindRQLQueryByName(QueryName, NamedRQLQuery);
|
||||
finally
|
||||
lT.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
class function TMVCActiveRecord.CurrentConnection: TFDConnection;
|
||||
begin
|
||||
Result := ActiveRecordConnectionsRegistry.GetCurrent;
|
||||
|
@ -72,6 +72,8 @@ type
|
||||
[Test]
|
||||
procedure TestNamedQuerySQL;
|
||||
[Test]
|
||||
procedure TestTryGetNamedQuery;
|
||||
[Test]
|
||||
procedure TestNamedQuerySQLByBackEnd;
|
||||
[Test]
|
||||
procedure TestStore;
|
||||
@ -1892,6 +1894,23 @@ begin
|
||||
|
||||
end;
|
||||
|
||||
procedure TTestActiveRecordBase.TestTryGetNamedQuery;
|
||||
var
|
||||
lTmpSQLQueryWithName: TSQLQueryWithName;
|
||||
lTmpRQLQueryWithName: TRQLQueryWithName;
|
||||
begin
|
||||
Assert.IsTrue(TMVCActiveRecord.TryGetSQLQuery<TCustomer>('ByTwoCities', lTmpSQLQueryWithName));
|
||||
Assert.AreEqual('ByTwoCities', lTmpSQLQueryWithName.Name);
|
||||
Assert.IsNotEmpty(lTmpSQLQueryWithName.SQLText);
|
||||
Assert.IsEmpty(lTmpSQLQueryWithName.BackEnd);
|
||||
Assert.IsFalse(TMVCActiveRecord.TryGetSQLQuery<TCustomer>('DO_NOT_EXISTS', lTmpSQLQueryWithName));
|
||||
|
||||
Assert.IsTrue(TMVCActiveRecord.TryGetRQLQuery<TCustomer>('CityRomeOrLondon', lTmpRQLQueryWithName));
|
||||
Assert.AreEqual('CityRomeOrLondon', lTmpRQLQueryWithName.Name);
|
||||
Assert.IsNotEmpty(lTmpRQLQueryWithName.RQLText);
|
||||
Assert.IsFalse(TMVCActiveRecord.TryGetRQLQuery<TCustomer>('DO_NOT_EXISTS', lTmpRQLQueryWithName));
|
||||
end;
|
||||
|
||||
procedure TTestActiveRecordBase.TestUpdateIfNotFound;
|
||||
var
|
||||
lCustomer: TCustomer;
|
||||
|
Loading…
Reference in New Issue
Block a user