Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-12

JSON Dataset in FCL-DB.

9 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Van Canneyt

Hello,

I just committed a JSON dataset in fcl-db.

This is a dataset which stores its data in JSON objects (as in fpjson) in memory. The records are in a JSON array, each record can be a JSON object or array. (not mixed)

The dataset is read-write. It can be used to create JSON data from scratch: just add definitions to the fielddefs properties, and call 'Open'. At the end, call SaveToStream().

There are 2 descendents which read/write ExtJS JSON data packages (Objects or Arrays) from streams but they are usable to handle any kind of JSON data. Currently, the dataset does not yet support propagating changes (deltas) back to a server.

I would be glad to recieve feedback, comments.

Michael.

Reply by email

Leonardo M. Ramé
to Michael Van Canneyt

From: Michael Van Canneyt

Show quoted text 19 lines
To: FPC mailing list ; Lazarus mailing list Sent: Friday, December 16, 2011 1:37 PM Subject: [fpc-pascal] JSON Dataset in FCL-DB. Hello, I just committed a JSON dataset in fcl-db. This is a dataset which stores its data in JSON objects (as in fpjson) in memory. The records are in a JSON array, each record can be a JSON object or array. (not mixed) The dataset is read-write. It can be used to create JSON data from scratch: just add definitions to the fielddefs properties, and call 'Open'. At the end, call SaveToStream(). There are 2 descendents which read/write ExtJS JSON data packages (Objects or Arrays) from streams but they are usable to handle any kind of JSON data. Currently, the dataset does not yet support propagating changes (deltas) back to a server. I would be glad to recieve feedback, comments. Michael.

Does this allow executing selects against an sql database and traverse the results using this JSON dataset?  
-- 
Leonardo M. Ramé
http://leonardorame.blogspot.com

Reply by email

Michael Van Canneyt
to Leonardo M. Ramé
Leonardo M. Ramé wrote 24 lines
From: Michael Van Canneyt > To: FPC mailing list ; Lazarus mailing list > Sent: Friday, December 16, 2011 1:37 PM > Subject: [fpc-pascal] JSON Dataset in FCL-DB. > > > Hello, > > I just committed a JSON dataset in fcl-db. > > This is a dataset which stores its data in JSON objects (as in fpjson) in memory. The records are in a JSON array, each record can be a JSON object or array. > (not mixed) > > The dataset is read-write. It can be used to create JSON data from scratch: just add definitions to the fielddefs properties, and call 'Open'. At the end, call SaveToStream(). > > There are 2 descendents which read/write ExtJS JSON data packages (Objects or Arrays) from streams but they are usable to handle any kind of JSON data. Currently, the dataset does not yet support propagating changes (deltas) back to a server. > > I would be glad to recieve feedback, comments. > > Michael. Does this allow executing selects against an sql database and traverse the results using this JSON dataset?

Yes. I use it as follows:

Normally, Fcl-web server using the sql-db and fpwebdata sends JSON-Formatted data to a browser.

I have now a lazarus-written client app which sends a HTTP request to the same webserver, reads the returned JSON, and then opens a dataset with the JSON as source of the data.

Combined with the Ext.Direct RPC, I intend to use this for N-tier apps where the client can be a native app or a browser.

What is missing currently is the delta to update data on the server, but that should be easily added.

Michael.

Reply by email

Leonardo M. Ramé
to Michael Van Canneyt

----- Original Message -----

Show quoted text 62 lines
From: Michael Van Canneyt To: FPC-Pascal users discussions Cc: Lazarus mailing list Sent: Friday, December 16, 2011 2:53 PM Subject: Re: [fpc-pascal] JSON Dataset in FCL-DB. On Fri, 16 Dec 2011, Leonardo M. Ramé wrote: > From: Michael Van Canneyt >> To: FPC mailing list ; Lazarus mailing list >> Sent: Friday, December 16, 2011 1:37 PM >> Subject: [fpc-pascal] JSON Dataset in FCL-DB. >> >> >> Hello, >> >> I just committed a JSON dataset in fcl-db. >> >> This is a dataset which stores its data in JSON objects (as in fpjson) in memory. The records are in a JSON array, each record can be a JSON object or array. >> (not mixed) >> >> The dataset is read-write. It can be used to create JSON data from scratch: just add definitions to the fielddefs properties, and call 'Open'. At the end, call SaveToStream(). >> >> There are 2 descendents which read/write ExtJS JSON data packages (Objects or Arrays) from streams but they are usable to handle any kind of JSON data. Currently, the dataset does not yet support propagating changes (deltas) back to a server. >> >> I would be glad to recieve feedback, comments. >> >> Michael. > > > > Does this allow executing selects against an sql database and traverse the results using this JSON dataset? Yes. I use it as follows: Normally, Fcl-web server using the sql-db and fpwebdata sends JSON-Formatted data to a browser. I have now a lazarus-written client app which sends a HTTP request to the same webserver, reads the returned JSON, and then opens a dataset with the JSON as source of the data. Combined with the Ext.Direct RPC, I intend to use this for N-tier apps where the client can be a native app or a browser. What is missing currently is the delta to update data on the server, but that should be easily added. Michael.

Thanks. 

Btw. I've found this dependency related error when I tried to compile.

...
PPU Loading /usr/local/lib/fpc/2.7.1/units/x86_64-linux/fcl-web/fpwebdata.ppu Recompiling fpwebdata, checksum changed for db
Fatal: Can't find unit fpwebdata used by fpjsondataset ...

--  
Leonardo M. Ramé
http://leonardorame.blogspot.com

Reply by email

Michael Van Canneyt
to Leonardo M. Ramé
Leonardo M. Ramé wrote 10 lines
> What is missing currently is the delta to update data on the server, but that > should be easily added. > > Michael. Thanks.  Btw. I've found this dependency related error when I tried to compile.

Fixed in revision 19858.

Michael.

Reply by email

Leonardo M. Ramé
to Michael Van Canneyt

----- Original Message -----

Show quoted text 25 lines
From: Michael Van Canneyt To: FPC-Pascal users discussions Cc: Lazarus mailing list Sent: Friday, December 16, 2011 5:52 PM Subject: Re: [fpc-pascal] JSON Dataset in FCL-DB. On Fri, 16 Dec 2011, Leonardo M. Ramé wrote: >> What is missing currently is the delta to update data on the server, but that >> should be easily added. >> >> Michael. > > > Thanks.  > > Btw. I've found this dependency related error when I tried to compile. > Fixed in revision 19858. Michael.

Michael, could you apply this? Without it fpjsondataset unit is not found:

Index: fpmake.pp

===================================================================
--- fpmake.pp   (revision 19860)
+++ fpmake.pp   (working copy)
@@ -37,6 +37,7 @@
     P.SourcePath.Add('src/sqldb/examples');
     P.SourcePath.Add('src/sqldb/oracle');
     P.SourcePath.Add('src/sdf');
+    P.SourcePath.Add('src/json');
     P.SourcePath.Add('src/datadict');
     P.SourcePath.Add('src/memds');
     P.SourcePath.Add('src/codegen');
@@ -661,6 +662,9 @@
         end;
     T.ResourceStrings := True;
+    // JSON
+    T:=P.Targets.AddUnit('fpjsondataset.pp');
+
     P.ExamplePath.Add('tests');
     T:=P.Targets.AddExampleProgram('dbftoolsunit.pas');
     T:=P.Targets.AddExampleProgram('dbtestframework.pas');

 
Leonardo M. Ramé
http://leonardorame.blogspot.com

Reply by email

Leonardo M. Ramé
to Leonardo M. Ramé

----- Original Message -----

Show quoted text 65 lines
From: Leonardo M. Ramé To: FPC-Pascal users discussions Cc: Sent: Saturday, December 17, 2011 10:00 AM Subject: Re: [fpc-pascal] JSON Dataset in FCL-DB. ----- Original Message ----- > From: Michael Van Canneyt > To: FPC-Pascal users discussions > Cc: Lazarus mailing list > Sent: Friday, December 16, 2011 5:52 PM > Subject: Re: [fpc-pascal] JSON Dataset in FCL-DB. > > > > On Fri, 16 Dec 2011, Leonardo M. Ramé wrote: > >>>   What is missing currently is the delta to update data on the server, > but that >>>   should be easily added. >>> >>>   Michael. >> >> >>   Thanks.  >> >>   Btw. I've found this dependency related error when I tried to compile. >> > > Fixed in revision 19858. > > Michael. Michael, could you apply this? Without it fpjsondataset unit is not found: Index: fpmake.pp =================================================================== --- fpmake.pp   (revision 19860) +++ fpmake.pp   (working copy) @@ -37,6 +37,7 @@      P.SourcePath.Add('src/sqldb/examples');      P.SourcePath.Add('src/sqldb/oracle');      P.SourcePath.Add('src/sdf'); +    P.SourcePath.Add('src/json');      P.SourcePath.Add('src/datadict');      P.SourcePath.Add('src/memds');      P.SourcePath.Add('src/codegen'); @@ -661,6 +662,9 @@          end;      T.ResourceStrings := True; +    // JSON +    T:=P.Targets.AddUnit('fpjsondataset.pp'); +      P.ExamplePath.Add('tests');      T:=P.Targets.AddExampleProgram('dbftoolsunit.pas');      T:=P.Targets.AddExampleProgram('dbtestframework.pas');  

Also this on tests directory:

Index: testjsondataset.pp
=================================================================== --- testjsondataset.pp  (revision 19860)
+++ testjsondataset.pp  (working copy)
@@ -3,9 +3,8 @@
 {$mode objfpc}{$H+}

 uses
-  Classes, sysutils, DB, jsondataset, fpjson, jsonparser;
+  Classes, sysutils, DB, fpjsondataset, fpjson, jsonparser;

-{$R *.res}

 Function ExtractData(Const AFileName : string) : TJSONObject;

--  
Leonardo M. Ramé
http://leonardorame.blogspot.com

Reply by email

Michael Van Canneyt
to Leonardo M. Ramé: ----- Original Message ----- Michael, could you apply this? Without it fpjsondataset unit…
Leonardo M. Ramé wrote 13 lines
----- Original Message ----- > From: Michael Van Canneyt > To: FPC-Pascal users discussions > Cc: Lazarus mailing list > Sent: Friday, December 16, 2011 5:52 PM > Subject: Re: [fpc-pascal] JSON Dataset in FCL-DB. +      P.ExamplePath.Add('tests');      T:=P.Targets.AddExampleProgram('dbftoolsunit.pas');      T:=P.Targets.AddExampleProgram('dbtestframework.pas');

Done, thank you. Committed in rev. 19862.

Michael.

Reply by email

Michael Van Canneyt
to Leonardo M. Ramé: ----- Original Message ----- Also this on tests directory: Index: testjsondataset.pp…
Leonardo M. Ramé wrote 11 lines
----- Original Message ----- Also this on tests directory: Index: testjsondataset.pp =================================================================== --- testjsondataset.pp  (revision 19860) +++ testjsondataset.pp  (working copy) @@ -3,9 +3,8 @@  {$mode objfpc}{$H+}

Also done, thank you ! Rev. 19864.

Michael.

Reply by email