Setting Query->IndexFieldNames="" does nothing

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
NoComprende
Posts: 135
Joined: Tue 09 Jan 2007 13:44

Setting Query->IndexFieldNames="" does nothing

Post by NoComprende » Fri 13 Apr 2007 20:47

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.

NoComprende
Posts: 135
Joined: Tue 09 Jan 2007 13:44

Post by NoComprende » Sat 14 Apr 2007 14:48

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.

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Mon 16 Apr 2007 08:05

This is designed MyDAC behaviour. MyDAC does not store default record order because of performance reason.

NoComprende
Posts: 135
Joined: Tue 09 Jan 2007 13:44

Post by NoComprende » Mon 16 Apr 2007 11:05

Antaeus, shouldn't it at least refetch the data and maintain the record position?

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Tue 17 Apr 2007 09:47

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).

Post Reply