Browse Source

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

git-svn-id: trunk@42005 -
michael 6 years ago
parent
commit
79cbfe53a5
1 changed files with 18 additions and 5 deletions
  1. 18 5
      packages/fcl-web/src/restbridge/sqldbrestschema.pp

+ 18 - 5
packages/fcl-web/src/restbridge/sqldbrestschema.pp

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