The mysql protocol is broken design-wise a couple of places, this is one of them. The server sends us a string, but doesn't tell which encoding it's in.

Rewrite the old code a bit to make the automatic PChar->WideString conversion explicit, also add a block of code that tries to guess if the server is sending UTF-8 and react properly to that.

A step on the way to fixing issue #994.
This commit is contained in:
rosenfield.albert
2009-03-31 04:39:43 +00:00
parent eecd5423b4
commit f2ecca5dcd

View File

@@ -262,9 +262,18 @@ begin
begin
FieldFlags := FPlainDriver.GetFieldFlags(FieldHandle);
ColumnLabel := FPlainDriver.GetFieldName(FieldHandle);
ColumnName := FPlainDriver.GetFieldOrigName(FieldHandle);
TableName := FPlainDriver.GetFieldTable(FieldHandle);
// Note: the server does not tell us which character set these are
// encoded in, it's not part of the protocol spec. Have to
// make a more or less qualified guess, unfortunately.
if not ((Statement.GetConnection) as IZMySQLConnection).GetAnsiMode then begin
ColumnLabel := UTF8Decode(FPlainDriver.GetFieldName(FieldHandle));
ColumnName := UTF8Decode(FPlainDriver.GetFieldOrigName(FieldHandle));
TableName := UTF8Decode(FPlainDriver.GetFieldTable(FieldHandle));
end else begin
ColumnLabel := WideString(FPlainDriver.GetFieldName(FieldHandle));
ColumnName := WideString(FPlainDriver.GetFieldOrigName(FieldHandle));
TableName := WideString(FPlainDriver.GetFieldTable(FieldHandle));
end;
ReadOnly := (FPlainDriver.GetFieldTable(FieldHandle) = '');
Writable := not ReadOnly;
ColumnType := ConvertMySQLHandleToSQLType(FPlainDriver, FieldHandle, FieldFlags, Bug10491);