@@ -979,11 +979,28 @@ - (void)_updateConnectionVariables
979979 // connection, it may be overridden by init_connect commands or connection state changes.
980980 // Default to latin1 for older server versions.
981981 NSString *retrievedEncoding = @" latin1" ;
982+ // character_set_results is the charset the strings received from the server will be in
982983 if ([variables objectForKey: @" character_set_results" ]) {
983984 retrievedEncoding = [variables objectForKey: @" character_set_results" ];
984- } else if ([variables objectForKey: @" character_set" ]) {
985+ }
986+ // not used in 4.1+ (?)
987+ else if ([variables objectForKey: @" character_set" ]) {
985988 retrievedEncoding = [variables objectForKey: @" character_set" ];
986989 }
990+ // character_set_client is the charset the server expects strings transmitted by us to be in
991+ else if ([variables objectForKey: @" character_set_client" ]) {
992+ retrievedEncoding = [variables objectForKey: @" character_set_client" ]; // fallback for sphinxql
993+ }
994+ // character_set_connection is used internally by the server for comparisons.
995+ // String literals (without a cast) will always be converted from character_set_client to character_set_connection first.
996+ // As an example:
997+ // * Use a client with "SET NAMES utf8"
998+ // * Do a "set @@session.character_set_connection = 'latin1';"
999+ // * Finally try a "SELECT '犬';" (also try "select _utf8'犬';" for completeness)
1000+ // * The result will just show a "?"
1001+ // So even though we told the server that the client uses utf8 and the results
1002+ // should be encoded in utf8, too, the character got lost.
1003+ // This happened because the server did a roundtrip of utf8 -> latin1 -> utf8.
9871004
9881005 // Update instance variables
9891006 if (encoding) [encoding release ];
0 commit comments