Page 1 of 1

Problem with malformed json using sqlite

Posted: 10.09.2022, 10:43
by kjteng
I have a sqlite table with ID and DATA (Text, to store json data) fields as follows:
ID DATA
1 [1,2,3]
2 ["1","2","3"]
3 [1,2,3, [4,5,6]]
4 [1,2,3,{"AA":4, "BB":5, "CC":6}]
5 [1,2,3
6 [1]
7 {"AA":1}

When I query (using TZQuery) the table with SELECT ID, DATA, json(DATA) FROM TEST
it will raise exception (because record 5 is an invalid JSON) and the the program starts to behalve abnormally because there is memory leak.

I tried the same using TSQlite component, it returns records 1 to 4 and then raise exception. However there is no memory leak.

Is this a bug in the zeoslib component? How to solve this (other then using WHERE clause to filter out the invalid records)?

Attached test.zip (test1 project is using zeoslib and test2 is using TsqliteQuery)

I am using Lazarus 2.2.2 with zeoslib-code-0-r7860-trunk.

Re: Problem with malformed using sqlite

Posted: 10.09.2022, 15:42
by marsupilami
kjteng wrote: 10.09.2022, 10:43 When I query (using TZQuery) the table with SELECT ID, DATA, json(DATA) FROM TEST
it will raise exception (because record 5 is an invalid JSON) and the the program starts to behalve abnormally because there is memory leak.
The memory leak is a bug and needs to be fixed.

Raising the exception is normal behaviour. You need to filter the data if you don't want an exception. If an exception is generated then it is undefined wether you will see any data at all or no data. Also it is not defined which data you will see.

Re: Problem with malformed json using sqlite

Posted: 11.09.2022, 01:35
by kjteng
Thanks for your reply.