#1 2015-02-01 22:30:49

Celso
Member
Registered: 2013-05-14
Posts: 55

To SQLite3

Good night.
I saw that there is a function RowsToSQLite3.
How do I export JSON or ClientDataset for SQLite3?

Offline

#2 2015-02-02 10:18:10

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: To SQLite3

There is no direct method AFAIR, outside the scope of the ORM.
You have to write your low level code.
The easiest is to use TSQLTableJSON for reading the JSON content.
It would be then easy to fill the SQlite3 DB with it.

Offline

#3 2015-02-03 12:24:33

Celso
Member
Registered: 2013-05-14
Posts: 55

Re: To SQLite3

Thank you by return.
In my case, the data are sent by the server and comes in JSON.
I would like to use the functions ready for ORM. JSON for TSQLTable I have no problems in doing so. Can You give me an example of how I export for SQLite3?

Offline

#4 2015-02-03 13:16:33

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: To SQLite3

1. Create the TSQLRecord descendant corresponding to your table layout.
I will call it TSQLMyData below.

2. Define a model with this TSQLMyData and a SQlite3 ORM server - i.e. TSQLRestServerDB.
Fill the TSQLMyData table as in the SQlite3 DB from JSON:

var rec: TSQLMyData;
    batch: TSQLRestBatch;

batch := TSQLRestBach.Create(aServer,TSQLMyData,10000);
rec := TSQLMyData.CreateAndFillPrepare(aJSONFromClient);
try
  while rec.FillOne do
    batch.add(rec,true); // may be (rec,true,true) if you want to have the same IDs
  aServer.BatchSend(batch);
finally
  batch.Free;
  rec.Free;
end;

Offline

#5 2015-02-03 17:38:26

Celso
Member
Registered: 2013-05-14
Posts: 55

Re: To SQLite3

Thank you for your assistance.
My last question. As I transform my JSON in a ISQLDBRows?

Offline

#6 2015-02-04 10:04:49

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: To SQLite3

I do not understand your question, sorry.
Do you mean ISQLDBRows.FetchAllAsJSON method?

Offline

#7 2015-02-04 17:27:27

Celso
Member
Registered: 2013-05-14
Posts: 55

Re: To SQLite3

Exemple:

    Rows, Rows2: ISQLDBRows;
    fJSONBuffer: RawUTF8;

   Rows := Props.Execute(SQL,[],nil,True);
   fJSONBuffer := Rows.FetchAllAsJSON(false);
   Rows.free;

   ----> How do I to fJSONBuffer to Rows again?
   ----> like this -> Rows2 := JSONToRows(fJSONBuffer);

Offline

#8 2015-02-05 16:40:11

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: To SQLite3

There is no built-in method for creating directly a ISQLDBRows.
But you can use the TSQLTableJSON to access the JSON by row.

Offline

#9 2015-02-08 12:48:47

ruth
Member
Registered: 2015-02-08
Posts: 2

Re: To SQLite3

If you don't want to code it, it may be helpful to first convert the JSON data to CSV by using a tool like https://json-csv.com

Last edited by ruth (2015-02-08 12:49:02)

Offline

#10 2015-02-08 16:30:30

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: To SQLite3

?????? CSV converted online ????
There is already a JSON to CSV fast conversion in TSQLTableJson.

Offline

Board footer

Powered by FluxBB