You are not logged in.
Pages: 1
Hello everyone,
Our project has a server (TSQLRestServerFullMemory) with a service defined, and functions returining RawJSON.
We have a client (Windows) with Delphi.
These methods returning RawJSON are returning Rows of DataSet with ISQLDBRows : Rows.FetchAllAsJSON(false).
The code works great on Windows, but with Android... In fact, we used SynCommons, mORMot and mORMotVCL in order to have the RawJSON type and the JSONToDataSet function.
With Android and other mobile devices, we should use SynCrossPlatform*. But all our functions do not work anymore. For example we had on the client side :
function ...(int id) : TDataSet;
begin
JSON := Methods.GetTopics(id);
Result := JSONToDataSet(Nil, JSON);
end
What should we use now ? Is it still possible to keep our IMethods interface, with functions returning RawJSON ?
Our server is a web services which returns results of SQL requests with datasets, in fact the client needs data from the database and the server gives him the datasets as JSON.
Thanks for your help.
Offline
There is no TDataSet support in the SynCrossPlatform* units yet.
Idea is to fill the visual components with the data directly, using e.g.
Or to use the JSON features of latest TDataSet.
Of course, if you can, the perfect fit may be to contribute a new cross-platform unit, filling a TDataSet from data parsed as JSON from SynCrossPlatformJSON.pas.
Online
Hello again,
Okay, so we are still struggling a little bit in order to achieve our goal.
So far, we have changed a little bit the TSQLDBStatement.FetchAllToJSON function in order to save the data types in the JSON as the following :
{"fieldCount":2, "values": ["col1", "col2", "type1", "type2", "val11", "val12", "val21", "val22", ...] }
And we have created a function called JSONToDataSet which from a JSON string fills a TDataSet with the data in the JSON, using a TJSONTable for helping reading the JSON.
The problem is with handling blob fields. In the JSON it is stored base64 encoded, but in order to be used in the application, it should be decoded.
(we are doing : TBlobField(DataSet.Fields[ i ]).Value := JSONTable.RowValues[ i ])
Do you know how to do that ?
Thank you very much for your help.
Offline
Finally we achieved to do that with :
if ((DS.Fields[i].DataType = ftBlob) and (JSONTable.RowValues[i] <> Null)) then
begin
Base64JSONStringToBytes(JSONTable.RowValues[i], bytes);
TBlobField(DS.Fields[i]).Value := TBytes(bytes);
end
Offline
Great!
Would you like to have the code we modified in order to change the JSON creation (adding the datatypes) in TSQLDBStatement.FetchAllToJSON when the expanded is False?
And also our function JSONToDataSet which fills a TDataSet with the JSON using the JSON with the types in it?
Offline
Hello again!
Everything is working fine, but we are facing an issue; we would like to send from the client (cross-platform) a picture to the server. Everything is packed in a TDataSet and converted to JSON.
So the client is sending with the TJSONWriter from SynCommons:
var
Data: PByte;
blob: RawByteString;
Data := @DS.Fields.Fields[col].AsBytes[0];
with FromVarBlob(Data)
do SetString(blob, Ptr, Len);
Writer.WrBase64(Pointer(blob), Length(blob), True);
(This code is just like you are doing when transforming SQLDBRows to JSON when the server communicates with the client.)
The server receives the JSON and we use JSONToDataSet in order to get the TDataSet back.
But we could not achieve to get back the blob. We tried with TMemoryStream (TBlobField.SaveToStream), or even with TMemoryStream.WriteBuffer or Base64JSONStringToBytes...
Do you have an idea of what we are doing wrong?
Offline
Pages: 1