Board index » delphi » TQuery result set - sorting without re-read ??

TQuery result set - sorting without re-read ??

Hiya
Can anybody tell me if this is possible -
I have a TQuery which is loading some large table and I provide a
buttons for sorting info by each field - do I have just to change SQL's
ORDER BY and to re-read all records or is there any better way to sort
already loaded records ?
 

Re:TQuery result set - sorting without re-read ??


In article <MPG.1023a25635b28a9e989...@forums.borland.com>,
orl...@hotmail.com says...
Quote
> Hiya
> Can anybody tell me if this is possible -
> I have a TQuery which is loading some large table and I provide a
> buttons for sorting info by each field - do I have just to change SQL's
> ORDER BY and to re-read all records or is there any better way to sort
> already loaded records ?

In short, when working with TQuery, changing the OrderBy will change the
order of the selected records, but it will also completely re-run the
SQL, which can be time consuming obviously. One might want to think twice
before re-running the query just to get the info in a different order.
But there are other alternatives, for example:

use TBatchMove to stick the data into some temporary place (like the
Windows Temp dir) And then reference that table via a TTable which, of
course can support many indexes.

another approach which I use all the time, is to use TClientDatasets.
These are only in Delphi C/S, but if you have them , they are fantastic.
Very fast, all in memory (like a TQuery) but I can change the data (can't
do that on certain queries, depending on the SQL) I can also use an index
by simply specifying the field names(s) iin the IndexFielnames property,
and it will dynamically crate that index (in memory as well)  if it does
not exists. With a TTable, you must explicitly create an index if it does
not exist.

so you have a few options, I recommend TClinetDataset if you have the
correct version.

--
Randall Sell
ByteWise Solutions

Other Threads