#1 2015-09-02 11:08:43

hnb
Member
Registered: 2015-06-15
Posts: 291

Patch for "Expanded" TSQLDBStatement.FetchAllToJSON

For code like this (Expanded parameter is "True"):

LJSON := aProps.Execute(SQL,[]).FetchAllAsJSON(True);

for empty "aProps.Execute(SQL,[])" result the proper result of FetchAllAsJSON is:

[]

instead of:

{
	"fieldCount": 4,
	"values": 
	[
		"id",
		"x",
		"y",
		"z"
	],
	"rowCount": 0
}

for Count >= 1 result of "Expanded" FetchAllAsJSON is ok.

Patch attached:
https://drive.google.com/file/d/0B4PZhd … sp=sharing

best regards,
Maciej Izak


best regards,
Maciej Izak

Offline

#2 2015-09-02 12:10:10

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

Re: Patch for "Expanded" TSQLDBStatement.FetchAllToJSON

This is by design.

It allows to have the column names even if there is no data row.

Offline

#3 2015-09-02 12:22:39

hnb
Member
Registered: 2015-06-15
Posts: 291

Re: Patch for "Expanded" TSQLDBStatement.FetchAllToJSON

Maybe we need additional option for empty "[]" result? Current state can be problematic for some non-mORMotish clients.


best regards,
Maciej Izak

Offline

#4 2015-09-02 13:37:26

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

Re: Patch for "Expanded" TSQLDBStatement.FetchAllToJSON

I guess this is not difficult to let the client handle it.

If FetchAllAsJSON returns a { ... } JSON object, and not a [ .... ] JSON array, just handle the { .... } JSON as a void [] array.

Offline

#5 2016-01-10 19:45:42

EvaF
Member
Registered: 2014-07-19
Posts: 40

Re: Patch for "Expanded" TSQLDBStatement.FetchAllToJSON

Hi,
I also  intercede for the Maciej proposal.
I have to go to new version of mormot and I have to treat the result of FetchallToJSON(true) in many places - I know it's not difficult, but it makes imho more sense to return every time the same type

for Expanded = true  i would like to expect allways Array []
for Expanded = false  i would like to expect allways Object {}

Offline

#6 2016-01-10 19:58:40

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

Re: Patch for "Expanded" TSQLDBStatement.FetchAllToJSON

Did you try with the latest version of the framework?

We introduced ClientKind/ClientWriteAsJsonNotAsString feature some weeks ago, which re-format the output if the request comes from a browser (AJAX).

Offline

#7 2016-01-10 20:13:26

EvaF
Member
Registered: 2014-07-19
Posts: 40

Re: Patch for "Expanded" TSQLDBStatement.FetchAllToJSON

Ok, thanks a lot for tip, I will take a look at it

Offline

#8 2016-01-10 20:42:43

EvaF
Member
Registered: 2014-07-19
Posts: 40

Re: Patch for "Expanded" TSQLDBStatement.FetchAllToJSON

hm, so nothing - it doesn't help me...
I mainly use fetchAllToJSON for the results of MSSQL queries,further I perform a little bit more complicated calculations using these JSON objects and mormotize only the result of calculation.

Offline

Board footer

Powered by FluxBB