* Split out processing of SQL so it can be used in editor. Correct LoadFromFile

git-svn-id: trunk@42005 -
This commit is contained in:
michael 2019-05-06 07:38:00 +00:00
parent b91f374e3d
commit 79cbfe53a5

View File

@ -49,6 +49,7 @@ Const
JSONSchemaRoot = 'schema';
JSONResourcesRoot = 'resources';
JSONConnectionsRoot = 'connections';
JSONConnectionName = 'connectionName';
Type
@ -200,6 +201,7 @@ Type
function GetFieldList(aListKind: TFieldListKind; ASep : String = ''): UTF8String;
function GetFieldArray(aListKind: TFieldListKind): TSQLDBRestFieldArray;
Function GetResolvedSQl(aKind : TSQLKind; Const AWhere : UTF8String; Const aOrderBy : UTF8String = ''; aLimit : UTF8String = '') : UTF8String;
Function ProcessSQl(aSQL : String; Const AWhere : UTF8String; Const aOrderBy : UTF8String = ''; aLimit : UTF8String = '') : UTF8String;
Procedure PopulateFieldsFromFieldDefs(Defs : TFieldDefs; aIndexFields : TStringArray; aProcessIdentifier : TProcessIdentifier; aMinFieldOpts : TRestFieldOptions);
Property SQL [aKind : TSQLKind] : TStrings Read GetSQLTyped;
Property BusinessProcessor : TSQLDBRestCustomBusinessProcessor Read FBusinessProcessor;
@ -521,7 +523,7 @@ end;
function TSQLDBRestSchema.AsJSON(const aPropName: UTF8String): TJSONData;
begin
Result:=TJSONObject.Create([JSONResourcesRoot,Resources.AsJSON(),'connectionName',ConnectionName]);
Result:=TJSONObject.Create([JSONResourcesRoot,Resources.AsJSON(),JSONConnectionName,ConnectionName]);
if (aPropName<>'') then
Result:=TJSONObject.Create([aPropName,Result]);
end;
@ -559,8 +561,10 @@ Var
begin
J:=aData as TJSONObject;
if (aPropName<>'') then
J:=J.Objects[aPropName];
Resources.FromJSON(J,JSONResourcesRoot);
ConnectionName:=J.Get(aPropName,'');
ConnectionName:=J.Get(JSONConnectionName,'');
AttachAllProcessors;
end;
@ -1159,13 +1163,21 @@ function TSQLDBRestResource.GetResolvedSQl(aKind: TSQLKind;
const AWhere: UTF8String; const aOrderBy: UTF8String; aLimit: UTF8String
): UTF8String;
Var
S : UTF8String;
begin
Result:=SQL[aKind].Text;
if (Result='') then
Result:=GenerateDefaultSQL(aKind);
Result:=ProcessSQL(Result,aWhere,aOrderBy,aLimit);
end;
function TSQLDBRestResource.ProcessSQl(aSQL: String; const AWhere: UTF8String;
const aOrderBy: UTF8String; aLimit: UTF8String): UTF8String;
Var
S : UTF8String;
begin
Result:=aSQL;
if (aWhere<>'') then
S:='WHERE '+aWhere
else
@ -1240,6 +1252,7 @@ begin
Exclude(O,foFilter);
end;
F:=Fields.AddField(FN,RFT,O);
F.NativeFieldType:=FD.DataType;
if F.FieldType=rftString then
F.MaxLen:=FD.Size;
F.PublicName:=PN;