#1 2017-10-23 14:43:48

factor200x
Member
Registered: 2017-05-23
Posts: 15

I need help again...

Hello everyone,

I have the following understanding problem.

In my database field I store a JSON array:

Field names:

Filter, Type: RawUtf8
TestData, Type: Variant;

Field content:

Filter: Filter = Test
TestData: {"Contents":[{ID: 1, Data:"Test"}, {ID: 2, Data:"Help"}]}}

The line with the required data set is filtered via "Filter = Test" and gets the JSON value.

I hope by then I have been able to explain this clearly. :-)

Well, my problem:

How can I filter within the JSON array after ID = 2 filters?

In the documentary. I read about the function JsonGet (). But unfortunately I can't find an example of how to understand it.

Can someone give me a little example?

Many thanks in advance
Olaf

Offline

#2 2017-10-23 16:35:32

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

Re: I need help again...

Currently, JsonGet() could only retrieve one item in the array list by index, not search within the array...

So you will probably have to retrieve the values in the TSQLRecord, and search by hand using TDocVariant.

Offline

#3 2017-10-24 12:14:22

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

Re: I need help again...

use SQLITE's JSON1 syntax.


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#4 2017-10-24 14:14:59

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

Re: I need help again...

Yes, I forgot about it, IIRC we compiled SynSQLite3Static.pas including JSON1.
See https://sqlite.org/json1.html

But it will work with standard JSON, not our "extended" JSON standard.

Offline

#5 2017-10-24 16:47:07

factor200x
Member
Registered: 2017-05-23
Posts: 15

Re: I need help again...

Oh thank you very much for the helpful hint! That helps me a lot!

Offline

#6 2017-10-24 19:21:24

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

Re: I need help again...

If you use JSON1 remember to call TSQLDataBase.CacheFlush() after edits to keep the ORM cache in sync. I got caught out by that!

Offline

#7 2017-10-25 01:46:14

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

Re: I need help again...

@esmondb, that's a good hint!


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

Board footer

Powered by FluxBB