Page 1 of 1

Setting Query->IndexFieldNames="" does nothing

Posted: Fri 13 Apr 2007 20:47
by NoComprende
Hi, if I'm viewing a query result set in a grid and set

Query->IndexFieldNames="Field1";

the result set is ordered by Field1 and record position is maintained (as you would expect). If I then set

Query->IndexFieldNames="";

nothing happens. I could follow that with the command

Query->Refresh();

and that will reset the order to the default but, that often results in loss of record position.

Posted: Sat 14 Apr 2007 14:48
by NoComprende
A way round this is

Query->IndexFieldNames=Query->GetOrderBy();
// above results in Query being sorted on default order with record position maintained
Query->IndexFieldNames="";
// does nothing but is a reminder that Query is sorted on default order

The only problem with the above solution is that a) GetOrderBy() may return an empty string (it also returns an incorrect result if the Query is sorted by a 'GROUP BY' clause as opposed to an 'ORDER BY' clause) and b) even if it doesn't, there's no guarantee the fields returned by GetOrderBy() will be present in the actual result set.

Posted: Mon 16 Apr 2007 08:05
by Antaeus
This is designed MyDAC behaviour. MyDAC does not store default record order because of performance reason.

Posted: Mon 16 Apr 2007 11:05
by NoComprende
Antaeus, shouldn't it at least refetch the data and maintain the record position?

Posted: Tue 17 Apr 2007 09:47
by Antaeus
TMyQuery tries to restore position of the current record if it is possible (there is a key field that can be used to locate the record).