Explorar o código

* Auto-detect JSON type

michael %!s(int64=6) %!d(string=hai) anos
pai
achega
e2494de422
Modificáronse 1 ficheiros con 9 adicións e 1 borrados
  1. 9 1
      packages/fcl-db/jsondataset.pas

+ 9 - 1
packages/fcl-db/jsondataset.pas

@@ -332,7 +332,7 @@ type
     // Format JSON date to from DT for Field F
     function FormatDateTimeField(DT : TDateTime; F: TField): String; virtual;
     // Create fieldmapper. A descendent MUST implement this.
-    Function CreateFieldMapper : TJSONFieldMapper; virtual; abstract;
+    Function CreateFieldMapper : TJSONFieldMapper; virtual;
     // If True, then the dataset will free MetaData and FRows when it is closed.
     Property OwnsData : Boolean Read FownsData Write FOwnsData;
     // set to true if unknown field types should be handled as string fields.
@@ -1569,6 +1569,14 @@ begin
     Result:=FormatDateTime(ptrn,DT);
 end;
 
+function TBaseJSONDataSet.CreateFieldMapper: TJSONFieldMapper;
+begin
+  if FRowType=rtJSONArray then
+    Result:=TJSONArrayFieldMapper.Create
+  else
+    Result:=TJSONObjectFieldMapper.Create;
+end;
+
 function TBaseJSONDataSet.GetFieldData(Field: TField; Buffer: TDatarecord): JSValue;
 
 var