#1 2018-10-30 20:36:23

triguinhu
Member
From: Brazil
Registered: 2016-07-28
Posts: 27

Load records in a TUniQuery and in a TIBQuery (IBX)

Hi all,

We use Mormot on a new project with extreme success, but we are working on using mormot in an old legacy project that basically uses UNIQuery and IBQuery Datasets.

We want to load the records in these DataSets, but it has not worked well using the JSONTODataset implementation

It works

DbGrid1.DataSource.DataSet: = JSONToDataSet (Self, fService.Execute (aSQL, True, False));

but this does not work

UniQuery1: = TUniQuery (JSONToDataSet (Self, fService.Execute (aSQL, True, False)));

How do we proceed?

Offline

#2 2018-10-31 07:30:37

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

Re: Load records in a TUniQuery and in a TIBQuery (IBX)

The class instance returend by JSONToDataSet is not a TUniQuery, so hard casting as you do is properly invalid.
The following won't compile:

UniQuery1: = JSONToDataSet (Self, fService.Execute (aSQL, True, False))) as TUniQuery;

I think you have to change the UniQuery1 type to a plain TDataSet....

Offline

#3 2018-10-31 13:41:08

triguinhu
Member
From: Brazil
Registered: 2016-07-28
Posts: 27

Re: Load records in a TUniQuery and in a TIBQuery (IBX)

Thanks Ab

Now it works

I have one more newbie question

In this case, UniQuery1 has named added TFields, for example:

UniQuery1ID_TABLE INTEGER
UniQuery1NAME STRING

and

fService.Execute ('SELECT ID_TABLE, NAME FROM COMPANIES', True, True) returns correctly

In UniQuery1 I can correctly access the values in TUniQuery using UniQuery1.Fields [0] and UniQuery1.Fields [1]

I can also access using UniQuery1.FieldByName ('ID_TABLE') AsInteger and UniQuery1.FieldByName ('NAME') AsString and UniQuery.RecordCount is correct

But I can not directly access UniQuery1ID_TABLE.AsInteger nor UniQuery1NAME.ASString and this is used in my legacy code
The values come empty when I access the fields directly

How do we proceed?

Last edited by triguinhu (2018-10-31 13:44:03)

Offline

#4 2018-11-05 17:17:24

triguinhu
Member
From: Brazil
Registered: 2016-07-28
Posts: 27

Re: Load records in a TUniQuery and in a TIBQuery (IBX)

This notation used in our legacy application repeats thousands of times throughout the code.

I would like some help from you to get out of this question if possible, otherwise it will not be approved by our directors to change the legacy code to use mormot in this application

Offline

#5 2018-11-20 11:42:33

triguinhu
Member
From: Brazil
Registered: 2016-07-28
Posts: 27

Re: Load records in a TUniQuery and in a TIBQuery (IBX)

Hello guys

What would be the best way to keep the reference to the Query object without creating a new reference by assigning JSOntoDataset to a Query?

When I do MyUniQuery := JSONTODataset (something) I create a new reference and I can not access the named TFields among other things ..

How do I get the result of JSONtoDataset in the same reference of my UniQuery?

Last edited by triguinhu (2018-11-20 11:43:29)

Offline

#6 2018-11-21 14:34:22

Andry
Member
Registered: 2018-11-21
Posts: 1

Re: Load records in a TUniQuery and in a TIBQuery (IBX)

This is because you use persistence field in your legacy application.
You have to adapt all direct call to persisted field UniQuery1ID_TABLE to UniQuery.FieldByName('ID_TABLE').Asxxxxxx.
Andry

Offline

Board footer

Powered by FluxBB