andrey                                   Mon, 14 Jun 2010 18:19:13 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=300436

Log:
And a fix for MySQL Server which is pre 5.1.23, which doesn't support
preserving of the charset when performing change_user. This is libmysql
only code.

Changed paths:
    U   php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_api.c
    U   php/php-src/branches/PHP_5_3/ext/mysqli/php_mysqli_structs.h
    U   php/php-src/trunk/ext/mysqli/mysqli_api.c
    U   php/php-src/trunk/ext/mysqli/php_mysqli_structs.h

Modified: php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_api.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_api.c        2010-06-14 
17:16:20 UTC (rev 300435)
+++ php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_api.c        2010-06-14 
18:19:13 UTC (rev 300436)
@@ -521,18 +521,35 @@
        char            *user, *password, *dbname;
        int                     user_len, password_len, dbname_len;
        ulong           rc;
+#if !defined(MYSQLI_USE_MYSQLND) && defined(HAVE_MYSQLI_SET_CHARSET)
+       const           CHARSET_INFO * old_charset;
+#endif

        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), 
"Osss", &mysql_link, mysqli_link_class_entry, &user, &user_len, &password, 
&password_len, &dbname, &dbname_len) == FAILURE) {
                return;
        }
        MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);

+#if !defined(MYSQLI_USE_MYSQLND) && defined(HAVE_MYSQLI_SET_CHARSET)
+       old_charset = mysql->mysql->charset;
+#endif
+
        rc = mysql_change_user(mysql->mysql, user, password, dbname);
        MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);

        if (rc) {
                RETURN_FALSE;
        }
+#if !defined(MYSQLI_USE_MYSQLND) && defined(HAVE_MYSQLI_SET_CHARSET)
+       if (mysql_get_server_version(mysql->mysql) < 501023L) {
+               /*
+                 Request the current charset, or it will be reset to the 
system one.
+                 5.0 doesn't support it. Support added in 5.1.23 by fixing the 
following bug :
+                 Bug #30472 libmysql doesn't reset charset, insert_id after 
succ. mysql_change_user() call
+               */
+               rc = mysql_set_character_set(mysql->mysql, old_charset->csname);
+       }
+#endif

        RETURN_TRUE;
 }

Modified: php/php-src/branches/PHP_5_3/ext/mysqli/php_mysqli_structs.h
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqli/php_mysqli_structs.h        
2010-06-14 17:16:20 UTC (rev 300435)
+++ php/php-src/branches/PHP_5_3/ext/mysqli/php_mysqli_structs.h        
2010-06-14 18:19:13 UTC (rev 300436)
@@ -40,8 +40,44 @@
 #include "ext/mysqlnd/mysqlnd.h"
 #include "mysqli_mysqlnd.h"
 #else
+
+/*
+  The libmysql headers (a PITA) also define it and there will be an warning.
+  Undef it and later we might need to define it again.
+*/
+#ifdef HAVE_MBRLEN
+#undef HAVE_MBRLEN
+#define WE_HAD_MBRLEN
+#endif
+#ifdef HAVE_MBSTATE_T
+#undef HAVE_MBSTATE_T
+#define WE_HAD_MBSTATE_T
+#endif
+
+#include <my_global.h>
+
+#if !defined(HAVE_MBRLEN) && defined(WE_HAD_MBRLEN)
+#define HAVE_MBRLEN 1
+#endif
+
+#if !defined(HAVE_MBSTATE_T) && defined(WE_HAD_MBSTATE_T)
+#define HAVE_MBSTATE_T 1
+#endif
+
+/*
+  We need more than mysql.h because we need CHARSET_INFO in one place.
+  This order has been borrowed from the ODBC driver. Nothing can be removed
+  from the list of headers :(
+*/
+
+#include <my_sys.h>
 #include <mysql.h>
 #include <errmsg.h>
+#include <my_list.h>
+#include <m_string.h>
+#include <mysqld_error.h>
+#include <my_list.h>
+#include <m_ctype.h>
 #include "mysqli_libmysql.h"
 #endif


Modified: php/php-src/trunk/ext/mysqli/mysqli_api.c
===================================================================
--- php/php-src/trunk/ext/mysqli/mysqli_api.c   2010-06-14 17:16:20 UTC (rev 
300435)
+++ php/php-src/trunk/ext/mysqli/mysqli_api.c   2010-06-14 18:19:13 UTC (rev 
300436)
@@ -521,18 +521,35 @@
        char            *user, *password, *dbname;
        int                     user_len, password_len, dbname_len;
        ulong           rc;
+#if !defined(MYSQLI_USE_MYSQLND) && defined(HAVE_MYSQLI_SET_CHARSET)
+       const           CHARSET_INFO * old_charset;
+#endif

        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), 
"Osss", &mysql_link, mysqli_link_class_entry, &user, &user_len, &password, 
&password_len, &dbname, &dbname_len) == FAILURE) {
                return;
        }
        MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);

+#if !defined(MYSQLI_USE_MYSQLND) && defined(HAVE_MYSQLI_SET_CHARSET)
+       old_charset = mysql->mysql->charset;
+#endif
+
        rc = mysql_change_user(mysql->mysql, user, password, dbname);
        MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);

        if (rc) {
                RETURN_FALSE;
        }
+#if !defined(MYSQLI_USE_MYSQLND) && defined(HAVE_MYSQLI_SET_CHARSET)
+       if (mysql_get_server_version(mysql->mysql) < 501023L) {
+               /*
+                 Request the current charset, or it will be reset to the 
system one.
+                 5.0 doesn't support it. Support added in 5.1.23 by fixing the 
following bug :
+                 Bug #30472 libmysql doesn't reset charset, insert_id after 
succ. mysql_change_user() call
+               */
+               rc = mysql_set_character_set(mysql->mysql, old_charset->csname);
+       }
+#endif

        RETURN_TRUE;
 }

Modified: php/php-src/trunk/ext/mysqli/php_mysqli_structs.h
===================================================================
--- php/php-src/trunk/ext/mysqli/php_mysqli_structs.h   2010-06-14 17:16:20 UTC 
(rev 300435)
+++ php/php-src/trunk/ext/mysqli/php_mysqli_structs.h   2010-06-14 18:19:13 UTC 
(rev 300436)
@@ -42,8 +42,44 @@
 #include "ext/mysqlnd/mysqlnd.h"
 #include "mysqli_mysqlnd.h"
 #else
+
+/*
+  The libmysql headers (a PITA) also define it and there will be an warning.
+  Undef it and later we might need to define it again.
+*/
+#ifdef HAVE_MBRLEN
+#undef HAVE_MBRLEN
+#define WE_HAD_MBRLEN
+#endif
+#ifdef HAVE_MBSTATE_T
+#undef HAVE_MBSTATE_T
+#define WE_HAD_MBSTATE_T
+#endif
+
+#include <my_global.h>
+
+#if !defined(HAVE_MBRLEN) && defined(WE_HAD_MBRLEN)
+#define HAVE_MBRLEN 1
+#endif
+
+#if !defined(HAVE_MBSTATE_T) && defined(WE_HAD_MBSTATE_T)
+#define HAVE_MBSTATE_T 1
+#endif
+
+/*
+  We need more than mysql.h because we need CHARSET_INFO in one place.
+  This order has been borrowed from the ODBC driver. Nothing can be removed
+  from the list of headers :(
+*/
+
+#include <my_sys.h>
 #include <mysql.h>
 #include <errmsg.h>
+#include <my_list.h>
+#include <m_string.h>
+#include <mysqld_error.h>
+#include <my_list.h>
+#include <m_ctype.h>
 #include "mysqli_libmysql.h"
 #endif


-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to