Indexes in TUniTable

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Ivan_Carpio89
Posts: 29
Joined: Mon 10 Dec 2018 23:49

Indexes in TUniTable

Post by Ivan_Carpio89 » Fri 14 Dec 2018 00:43

Hello,

I see that the property "TUniTable.Indexes" does not exist. Does this property have another name, or does the use of indexes in the TUniTable not exist?

I am interested in using the UniDAC components, but so far I have not found how to make the following code:

Code: Select all

FDTable1.IndexName:= FDTable1.IndexDefs.Items[0].Name;
if not FDTable1.FindKey(['001', 'F']) then
    raise exception.Create('Row not found!');
   
Any suggestions?

Thanks in advance.

frickler
Posts: 9
Joined: Wed 04 Apr 2018 08:30

Re: Indexes in TUniTable

Post by frickler » Fri 14 Dec 2018 07:53

Use "indexFieldNames" instead of "IndexName", as described in the documentation:
https://www.devart.com/unidac/docs/deva ... dnames.htm

Ivan_Carpio89
Posts: 29
Joined: Mon 10 Dec 2018 23:49

Re: Indexes in TUniTable

Post by Ivan_Carpio89 » Fri 14 Dec 2018 17:09

And the FindKey(), looks for the row, based on the fields indicated in "IndexFieldNames"?

The code in which we work, more than 50% is focused on working with the TFDTable's, browsing the records based on the indexes that have the physical tables in the Database, are the same as the TFDTable's, that is, for perform:

-FindKey
-FindNearest
-SetRange
-Etc.

Stellar
Devart Team
Posts: 235
Joined: Tue 03 Oct 2017 11:00

Re: Indexes in TUniTable

Post by Stellar » Mon 17 Dec 2018 15:00

TUniQuery and TUniTable do not have the IndexName property, because modern DBMSs automatically use server indexes when executing an SQL statement on the server side. The IndexFieldNames property is used for getting or setting up the list of fields, which a set of records is sorted by on the client side. Also, sorting a dataset by setting the IndexFieldNames property increases performance of records search in a dataset.

The sample of using the LocateEx method for moving the cursor to a specific record instead of calling the FindKey and FindNearest methods:

Code: Select all

UniQuery1.SQL.Text := 'SELECT DeptNO, DName, LOC FROM Dept';
UniQuery1.KeyFields := 'DeptNO';
UniQuery1.Open;

//FindKey
UniQuery1.LocateEx(UniQuery1.KeyFields, VarArrayOf([8]), []);

//FindNearest
UniQuery1.LocateEx(UniQuery1.KeyFields, VarArrayOf([21]), [lxNearest]);
The sample of using the SetRange method in UniDAC for setting the scope and applying it to a a dataset:

Code: Select all

UniQuery1.SQL.Text := 'SELECT DeptNO, DName, LOC FROM Dept';
UniQuery1.IndexFieldNames := 'DeptNO';
UniQuery1.Open;
UniQuery1.SetRange([8], [12]);
More information about FindKey:
https://www.devart.com/sdac/docs/devart ... ect[]).htm

More information about FindNearest:
https://www.devart.com/sdac/docs/devart ... ect[]).htm

More information about SetRange:
https://www.devart.com/sdac/docs/devart ... olean).htm

Ivan_Carpio89
Posts: 29
Joined: Mon 10 Dec 2018 23:49

Re: Indexes in TUniTable

Post by Ivan_Carpio89 » Wed 19 Dec 2018 18:07

Thank you very much for your support.

Regards.

Post Reply