Skip to content


Add another fallback for charset detection (which might improve compa…
Browse files Browse the repository at this point in the history
…tibility with Sphinx)
  • Loading branch information
dmoagx committed Feb 5, 2016
1 parent 21062b7 commit 6457da2
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -979,11 +979,28 @@ - (void)_updateConnectionVariables
// connection, it may be overridden by init_connect commands or connection state changes.
// Default to latin1 for older server versions.
NSString *retrievedEncoding = @"latin1";
// character_set_results is the charset the strings received from the server will be in
if ([variables objectForKey:@"character_set_results"]) {
retrievedEncoding = [variables objectForKey:@"character_set_results"];
} else if ([variables objectForKey:@"character_set"]) {
// not used in 4.1+ (?)
else if ([variables objectForKey:@"character_set"]) {
retrievedEncoding = [variables objectForKey:@"character_set"];
// character_set_client is the charset the server expects strings transmitted by us to be in
else if ([variables objectForKey:@"character_set_client"]) {
retrievedEncoding = [variables objectForKey:@"character_set_client"]; // fallback for sphinxql
// character_set_connection is used internally by the server for comparisons.
// String literals (without a cast) will always be converted from character_set_client to character_set_connection first.
// As an example:
// * Use a client with "SET NAMES utf8"
// * Do a "set @@session.character_set_connection = 'latin1';"
// * Finally try a "SELECT '犬';" (also try "select _utf8'犬';" for completeness)
// * The result will just show a "?"
// So even though we told the server that the client uses utf8 and the results
// should be encoded in utf8, too, the character got lost.
// This happened because the server did a roundtrip of utf8 -> latin1 -> utf8.

// Update instance variables
if (encoding) [encoding release];
Expand Down

0 comments on commit 6457da2

Please sign in to comment.