#1 2014-10-03 05:24:15

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

Sample 4 / ExecuteList

When retrieving a record with sample 4 the raw JSON response from the server is something like:

[{"ID":1,"Time":135192192214,"Name":"Tim","Question":"Hello world"}]

but if a record isn't found instead of an empty JSON array which I expected you get an object:

{"fieldCount":4,"values":["ID","Time","Name","Question"],"rowCount":0}

Is this right? It uses the ExecuteList function which line 12331 of mORMot.pas says "/// Execute directly a SQL statement, expecting a list of resutls"

Offline

#2 2014-10-03 07:26:45

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

Re: Sample 4 / ExecuteList

Yes this is by design, and documented as such.

The response has even two formats, one standard list or a non expanded layout.
Please check the doc.

Offline

#3 2014-10-03 11:20:00

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

Re: Sample 4 / ExecuteList

I understand the different formats but sample 4 has NoAJAXJSON set to false so it should be using the expanded format. However, using EngineList on the client gets a response in the non expanded format if result is an empty list otherwise the response is expanded. This seems inconsistent.

Offline

#4 2014-10-03 17:59:59

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

Re: Sample 4 / ExecuteList

It is by design, so that column names are available.
Our clients handle it as expected.

Offline

#5 2014-10-05 16:55:32

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

Re: Sample 4 / ExecuteList

Okay but I would prefer the expanded format to return just an empty array if the result is empty. Then a javascript client wouldn't have to do a typeof check to see if the result is an object or array. This could be done by removing lines 4185-4192 in SynSQLite3.pas:

    if (result=0) and W.Expand then begin
      // we want the field names at least, even with no data: we allow RowCount=0
      W.Expand := false; //  {"FieldCount":2,"Values":["col1","col2"]}
      W.CancelAll;
      for i := 0 to FieldCount-1 do
        W.ColNames[i] := sqlite3.column_name(Request,i);
      W.AddColumns;
    end;

I can't see this breaking standard mORMot clients.

Offline

#6 2014-10-05 18:53:29

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

Re: Sample 4 / ExecuteList

Would it be worth adding a separate built in function to return basic model info or just field names? It could be accessed with a URI such as http://host/root/tablename/fieldnames

Offline

#7 2014-10-05 19:05:22

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

Re: Sample 4 / ExecuteList

I do not see any reason to remove this code.
This is not an issue, but a feature, needed by other users of the library (it was not my idea, but I did understand the point and found it interresting)! smile

Your AJAX client has to adapt to the format used, as official Delphi, FPC or SMS/AJAX clients do.
Use case is pretty easy to implement: if it does not return a JSON array, you can assume it contains no value. A single "if" in your client library.

For ORM information, you have every information already returned by mORMotWrapper.pas.
It is the same information used by the client wrappers.

Offline

#8 2014-10-05 19:14:48

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

Re: Sample 4 / ExecuteList

And I guess "if" can be an error. Thanks

Offline

Board footer

Powered by FluxBB