From f2ecca5dcd38337a21454794feb53aef36da36b6 Mon Sep 17 00:00:00 2001 From: "rosenfield.albert" Date: Tue, 31 Mar 2009 04:39:43 +0000 Subject: [PATCH] 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. --- components/zeosdbo/src/dbc/ZDbcMySqlResultSet.pas | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/components/zeosdbo/src/dbc/ZDbcMySqlResultSet.pas b/components/zeosdbo/src/dbc/ZDbcMySqlResultSet.pas index 015ed59e..ab3f5944 100644 --- a/components/zeosdbo/src/dbc/ZDbcMySqlResultSet.pas +++ b/components/zeosdbo/src/dbc/ZDbcMySqlResultSet.pas @@ -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);