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 ?)
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 ?)
ASKER
Yes, it is important for the user to view all the records.
But how to do this with the TIBDataSet ?
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(C olumn: TColumn);
begin
ClientDataSet1.IndexFieldN ames := 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
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(C
begin
ClientDataSet1.IndexFieldN
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
ASKER
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 ?
How can i make the changes, which are made in TClientDataSet write to the TIBDataSet ?
Reading...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanxs ! It's the right direction ...
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