#1 2025-11-15 12:14:07

anouri
Member
Registered: 2024-02-11
Posts: 139

Problem in serializing json

Hi,

how can I serialize json in fast way (like mormot itself):

GetCustomerList is serialize with mormot and takes 650ms but my GetCustomerList2 takes 2100ms. 3 times slower.

https://gist.github.com/a-nouri/f0a0036 … 29ea86e345

where is my buttlenck.

Offline

#2 2025-11-15 13:07:21

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,276
Website

Re: Problem in serializing json

How many items do you have in the resultset?
Sounds like a lot of time to take 2 seconds with TDocVariantData process.

Anyway, what I would do in your case may be just:

var LJson: RawUtf8;
...
dbStmt.ExecutePreparedAndFetchAllAsJson(True, LJson);
Result.Status := HTTP_SUCCESS;
Result.Content := '{"status":"success","data":' + LJson + '}';

Offline

#3 2025-11-15 13:10:04

anouri
Member
Registered: 2024-02-11
Posts: 139

Re: Problem in serializing json

hahahaha. it was easy!

thank you smile

Offline

#4 2025-11-15 13:22:02

anouri
Member
Registered: 2024-02-11
Posts: 139

Re: Problem in serializing json

Another problem
i have field in mysql like this

`code` varbinary(6)

ExecutePreparedAndFetchAllAsJson return this field as garbage character (￰MDAwMDAx). but
LJson := dbStmt.FetchAllToDocVariantArray();

TDocVariantData(LJson).ToJson return '000001' that it is correct!

Last edited by anouri (2025-11-15 13:31:36)

Offline

#5 2025-11-15 13:27:08

anouri
Member
Registered: 2024-02-11
Posts: 139

Re: Problem in serializing json

I know that
select CAST(code AS CHAR(10)) code,descr from table
solve the problem. but why there is difference between two functions?

Last edited by anouri (2025-11-15 13:27:32)

Offline

#6 2025-11-15 13:54:13

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,276
Website

Re: Problem in serializing json

VarBinary is a BLOB, so it is encoded as base-64 - not garbage.
Use an only tool: MDAwMDAx is the base64 encoded value of 000001.

Cast() in SQL forces conversion to text - this is the expected way to consume this field.

How many rows do you return?
Which compiler, DB and connection properties class are you using?

Offline

#7 Yesterday 13:44:03

anouri
Member
Registered: 2024-02-11
Posts: 139

Re: Problem in serializing json

Yes. You are right
Thanks

Offline

Board footer

Powered by FluxBB