For TZReadOnlyQuery, not in TZQuery, sorting on a DATE field does not work correctly. So this problem is different from my topic posted yesterday "Sorting of TWideMemo-field"
The reason seems to be in ZDbcMySqlResultSet.pas, in method "GetTimestamp", which is called on sorting for a date, a time and a datetime field. I think it is remarkable that this only results in sorting problems, and not in date fields generally being read wrongly.
The original code :
Code: Select all
function TZAbstractMySQLResultSet.GetTimestamp(ColumnIndex: Integer): TDateTime;
[...]
if (Buffer+2)^ = ':' then
Result := RawSQLTimeToDateTime(Buffer, Len, ConSettings^.ReadFormatSettings, Failed{%H-})
else
if (ConSettings^.ReadFormatSettings.DateTimeFormatLen - Len) <= 4 then
Result := RawSQLTimeStampToDateTime(Buffer, Len, ConSettings^.ReadFormatSettings, Failed)
else
Result := RawSQLTimeToDateTime(Buffer, Len, ConSettings^.ReadFormatSettings, Failed); ///**********
[...]
I have changed this to :
Code: Select all
function TZAbstractMySQLResultSet.GetTimestamp(ColumnIndex: Integer): TDateTime;
[...]
if (Buffer+2)^ = ':' then
Result := RawSQLTimeToDateTime(Buffer, Len, ConSettings^.ReadFormatSettings, Failed{%H-})
else
if (ConSettings^.ReadFormatSettings.DateTimeFormatLen - Len) <= 4 then
Result := RawSQLTimeStampToDateTime(Buffer, Len, ConSettings^.ReadFormatSettings, Failed)
else
Result := RawSQLDateToDateTime(Buffer, Len, ConSettings^.ReadFormatSettings, Failed); ///*********
[...]
Note that this same logic (and the same mistake) also occurs in the method TZAbstractMySQLPreparedResultSet.GetTimeStamp, in the case statement for the case FIELD_TYPE_STRING,FIELD_TYPE_ENUM,FIELD_TYPE_SET. So also line 2525 in r3986 should be changed accordingly, I think.