MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Jim Winstead Date:December 23 2008 8:53pm
Subject:bzr commit into libmysql branch (jimw:2797) Bug#41071
View as plain text  
#At file:///Users/jimw/my/libmysql-1.0/ based on revid:jimw@stripped

 2797 Jim Winstead	2008-12-23
      Automatically fall back to 3-byte UTF-8 on pre-6.0 servers when connecting
      (or changing users). (Bug #41071, patch by Georg Richter)
modified:
  libmysql/client.c
  libmysql/libmysql.c
  unittest/libmysql/basic-t.c

=== modified file 'libmysql/client.c'
--- a/libmysql/client.c	2008-12-23 18:33:52 +0000
+++ b/libmysql/client.c	2008-12-23 20:52:19 +0000
@@ -2257,6 +2257,15 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
     int4store(buff,client_flag);
     int4store(buff+4, net->max_packet_size);
     buff[8]= (char) mysql->charset->number;
+    /*
+      Character set 45 (4-byte UTF-8) is not available on servers
+      before version 6.0, so we need to go ahead and switch to utf8_mb3.
+    */
+    if (mysql->charset->number == 45 && mysql->server_version[0] < '6')
+      buff[8]= 33;
+    else
+      buff[8]= (char)mysql->charset->number;
+
     bzero(buff+9, 32-9);
     end= buff+32;
   }

=== modified file 'libmysql/libmysql.c'
--- a/libmysql/libmysql.c	2008-12-14 11:36:15 +0000
+++ b/libmysql/libmysql.c	2008-12-23 20:52:19 +0000
@@ -437,7 +437,14 @@ my_bool	STDCALL mysql_change_user(MYSQL 
 
   if (mysql->server_capabilities & CLIENT_SECURE_CONNECTION)
   {
-    int2store(end, (ushort) mysql->charset->number);
+    /*
+      Character set 45 (4-byte UTF-8) is not available on servers
+      before version 6.0, so we need to go ahead and switch to utf8_mb3.
+    */
+    if (mysql->charset->number == 45 && mysql->server_version[0] < '6')
+      int2store(end, 33);
+    else
+      int2store(end, (ushort) mysql->charset->number);
     end+= 2;
   }
 

=== modified file 'unittest/libmysql/basic-t.c'
--- a/unittest/libmysql/basic-t.c	2008-12-16 18:25:17 +0000
+++ b/unittest/libmysql/basic-t.c	2008-12-23 20:52:19 +0000
@@ -20,6 +20,8 @@
 #include <tap.h>
 #include <mysql.h>
 
+#include <string.h>
+
 static const char *test_host= NULL, *test_user= NULL,
                   *test_passwd= NULL, *test_db= "test",
                   *test_socket= NULL;
@@ -34,7 +36,6 @@ const char *basic_connect(void)
   if (!my)
     return "mysql_init() failed";
 
-  /* XXX just connects to "test" on default port/socket */
   if (mysql_real_connect(my, test_host, test_user, test_passwd, test_db,
                          test_port, test_socket, 0) == NULL)
     return mysql_error(my);
@@ -61,6 +62,44 @@ const char *basic_connect(void)
 }
 
 
+const char *use_utf8(void)
+{
+  MYSQL_ROW row;
+  MYSQL_RES *res;
+
+  MYSQL *my= mysql_init(NULL);
+  if (!my)
+    return "mysql_init() failed";
+
+  if (mysql_options(my, MYSQL_SET_CHARSET_NAME, "utf8") != 0)
+    return "MYSQL_SET_CHARSET_NAME failed";
+
+  if (mysql_real_connect(my, test_host, test_user, test_passwd, test_db,
+                         test_port, test_socket, 0) == NULL)
+    return mysql_error(my);
+
+  /* Make sure that we actually ended up with utf8. */
+  if (mysql_query(my, "SELECT @@character_set_connection") != 0)
+    return mysql_error(my);
+
+  res= mysql_store_result(my);
+  if (!res)
+    return mysql_error(my);
+
+  while ((row= mysql_fetch_row(res)) != NULL)
+  {
+    if (strcmp(row[0], "utf8") != 0)
+      return "wrong character set";
+  }
+  if (mysql_errno(my) != 0)
+    return mysql_error(my);
+
+  mysql_close(my);
+
+  return NULL;
+}
+
+
 int
 main(void)
 {
@@ -79,10 +118,13 @@ main(void)
   if ((result= getenv("MYSQL_TEST_SOCKET")))
     test_socket= result;
 
-  plan(1);
+  plan(2);
 
   result= basic_connect();
   ok(result == NULL, result ? result : "basic_connect");
 
+  result= use_utf8();
+  ok(result == NULL, result ? result : "use_utf8");
+
   return exit_status();
 }

Thread
bzr commit into libmysql branch (jimw:2797) Bug#41071Jim Winstead23 Dec