Link to home
Start Free TrialLog in
Avatar of Andi4553
Andi4553

asked on

Interbase Sorting

Hi i have a problem :
I use a TIBQuery and a TIBDataSet. Selecting about 5000 rows of Data. After that, i load the data in a TDBGrid. Than i want to let the user to sort for some columns (or for more columns at the same time.) But i only know the way to Build a new SQL-Statement and Fill the Querys with new Data (This needs about 20 seconds) because of many columns and so .
Is there a way to sort them localy (not load the data new from the Interbase Server ?)
Avatar of bego
bego

As far as I know, there is no easy way to sort the result set locally. In general, it is not a goodd practice to use dbgrids in client/server applications. Is it really important for your users to view all 5000 records at a time?
TIBTable does have IndexFieldNames, and IndexName properties, I would give them a try. But I suspect that the results won't be impressive.
Alternatively, I would try to copy TIBQuery's result set to a TClientDataSet, view the data from TClientDataSet and see if the performance is better.

FWIW,

bego
Avatar of Andi4553

ASKER

Yes, it is important for the user to view all the records.
But how to do this with the TIBDataSet ?
Ok, I did some testing. If you have some higher versions of Delphi, you can use TClientDataSet.
Below is my test case:

1. Drop TIBDatabase, TIBTransaction, TIBDataSet, TClientDataSet, TDataSource, and TDBGrid on a form.
2. Set TIBDatabase, and TIBTransaction properties so that you can connect the database.
3. Set TIBDataSet's SelectSQL property to get your data.
4. Right click ClientDataSet1 and select Assign Local data from the menu. Select IBDataSet1 from the list. (There shouldn't be more, anyway :-)).
5. Eventually, specify FileName for the local file.
6. In my case, things were somewhat slow, but see my notes below.
7. Assign DataSource1's Dataset to ClientDataSet1 and finally, set DBGrid's DataSource to ClientDataSet1.
8. Write an event handler to DBGrid1's OnTitleClick event:

procedure TForm1.DBGrid1TitleClick(Column: TColumn);
begin
  ClientDataSet1.IndexFieldNames := Column.Title.Caption;
end;

That's all. Tested on some 40,000 records table (The table had 20 Columns, mostly numeric (double precision)). The response time was good (always less than 1 sec, obviously 200-300 msec). Tested with IB 6, D 5 Ent,
Pentium II 300 MHz / 128 MB.

HTH,

bego
But how can i copy the Data from the TIBDataSet into TClientDataSet ? (I have to copy the data at runtime !)
How can i make the changes, which are made in TClientDataSet write to the TIBDataSet ?
Avatar of Wim ten Brink
Reading...
ASKER CERTIFIED SOLUTION
Avatar of bego
bego

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanxs ! It's the right direction ...