Skip to content

Commit

Permalink
Do not search charset in mysql_real_connect if already set
Browse files Browse the repository at this point in the history
In mysql_init() charset is set to NULL .
In mysql_read_connect() charset is not changed if already set

This allows proxysql to change it outside the library
  • Loading branch information
renecannao committed Jan 14, 2021
1 parent ccc0887 commit 1ecb00f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ mariadb-client-library/mariadb_client/libmariadb/libmariadbclient.a: libssl/open
# cd mariadb-client-library/mariadb_client && cmake . -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl # this is needed on MacOSX
cd mariadb-client-library/mariadb_client && patch libmariadb/mariadb_stmt.c < ../mariadb_stmt.c.patch
cd mariadb-client-library/mariadb_client && patch libmariadb/mariadb_lib.c < ../mariadb_lib.c.patch
cd mariadb-client-library/mariadb_client && patch libmariadb/mariadb_lib.c < ../mariadb_lib.c.collation.patch # make sure this path is applied after mariadb_lib.c.patch
# cd mariadb-client-library/mariadb_client && patch libmariadb/net.c < ../net.c.patch
cd mariadb-client-library/mariadb_client && patch libmariadb/mariadb_async.c < ../mariadb_async.c.patch
cd mariadb-client-library/mariadb_client && patch libmariadb/ma_password.c < ../ma_password.c.patch
Expand Down
33 changes: 33 additions & 0 deletions deps/mariadb-client-library/mariadb_lib.c.collation.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@@ -1017,7 +1017,10 @@ mysql_init(MYSQL *mysql)
goto error;
mysql->options.report_data_truncation= 1;
mysql->options.connect_timeout=CONNECT_TIMEOUT;
- mysql->charset= mysql_find_charset_name(MARIADB_DEFAULT_CHARSET);
+ // in proxysql we set mysql->charset to NULL during mysql_init()
+ // proxysql will explicitly set it a value if needed
+ mysql->charset = NULL;
+ //mysql->charset= mysql_find_charset_name(MARIADB_DEFAULT_CHARSET);
mysql->methods= &MARIADB_DEFAULT_METHODS;
strcpy(mysql->net.sqlstate, "00000");
mysql->net.last_error[0]= mysql->net.last_errno= 0;
@@ -1497,11 +1500,15 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql
}
}

- /* Set character set */
- if (mysql->options.charset_name)
- mysql->charset= mysql_find_charset_name(mysql->options.charset_name);
- else
- mysql->charset=mysql_find_charset_name(MARIADB_DEFAULT_CHARSET);
+ if (!mysql->charset) { // in proxysql we do not set charset during mysql_init
+ /* Set character set */
+ if (mysql->options.charset_name)
+ mysql->charset= mysql_find_charset_name(mysql->options.charset_name);
+ else
+ mysql->charset=mysql_find_charset_name(MARIADB_DEFAULT_CHARSET);
+ } else {
+ // proxysql has explicitly set charset
+ }

if (!mysql->charset)
{
3 changes: 2 additions & 1 deletion lib/mysql_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,8 @@ void MySQL_Connection::connect_start() {
mysql_variables.server_set_value(myds->sess, SQL_CHARACTER_SET_CONNECTION, ss.str().c_str());
mysql_variables.server_set_value(myds->sess, SQL_COLLATION_CONNECTION, ss.str().c_str());
}
mysql_options(mysql, MYSQL_SET_CHARSET_NAME, c->csname);
//mysql_options(mysql, MYSQL_SET_CHARSET_NAME, c->csname);
mysql->charset = c;
unsigned long client_flags = 0;
//if (mysql_thread___client_found_rows)
// client_flags += CLIENT_FOUND_ROWS;
Expand Down

0 comments on commit 1ecb00f

Please sign in to comment.