diff options
author | unknown <georg@lmy002.wdf.sap.corp> | 2005-07-16 07:13:40 +0200 |
---|---|---|
committer | unknown <georg@lmy002.wdf.sap.corp> | 2005-07-16 07:13:40 +0200 |
commit | 90002cdc7b2f482c59a461184bc570c604f6a977 (patch) | |
tree | fffbb4b0689e1af8793fa34c85f75e5f2b2be98d | |
parent | e54cc5b995c2b6cdb8a45664474bdb945c05ed70 (diff) | |
download | mariadb-git-90002cdc7b2f482c59a461184bc570c604f6a977.tar.gz |
Restore previous used client charset in mysql_reconnect
Moved mysql_set_character_set function to client.c
Changed function prototype for mysql_set_character_set (as suggested
by Konstantin)
include/mysql.h:
Changed function prototype
libmysql/libmysql.c:
moved mysql_set_character_set to client.c
sql-common/client.c:
moved mysql_set_character_set to client.c
-rw-r--r-- | include/mysql.h | 2 | ||||
-rw-r--r-- | libmysql/libmysql.c | 33 | ||||
-rw-r--r-- | sql-common/client.c | 44 |
3 files changed, 44 insertions, 35 deletions
diff --git a/include/mysql.h b/include/mysql.h index daa29f70e16..2ba41e6d367 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -396,7 +396,7 @@ unsigned int STDCALL mysql_warning_count(MYSQL *mysql); const char * STDCALL mysql_info(MYSQL *mysql); unsigned long STDCALL mysql_thread_id(MYSQL *mysql); const char * STDCALL mysql_character_set_name(MYSQL *mysql); -int STDCALL mysql_set_character_set(MYSQL *mysql, char *csname); +int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname); MYSQL * STDCALL mysql_init(MYSQL *mysql); my_bool STDCALL mysql_ssl_set(MYSQL *mysql, const char *key, diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 097983cbbd3..f9ddf7fa665 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -1511,39 +1511,6 @@ void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *csinfo) csinfo->dir = charsets_dir; } -int STDCALL mysql_set_character_set(MYSQL *mysql, char *cs_name) -{ - struct charset_info_st *cs; - const char *save_csdir= charsets_dir; - - if (mysql->options.charset_dir) - charsets_dir= mysql->options.charset_dir; - - if ((cs= get_charset_by_csname(cs_name, MY_CS_PRIMARY, MYF(0)))) - { - char buff[MY_CS_NAME_SIZE + 10]; - charsets_dir= save_csdir; - sprintf(buff, "SET NAMES %s", cs_name); - if (!mysql_query(mysql, buff)) - { - mysql->charset= cs; - } - } - else - { - char cs_dir_name[FN_REFLEN]; - get_charsets_dir(cs_dir_name); - mysql->net.last_errno= CR_CANT_READ_CHARSET; - strmov(mysql->net.sqlstate, unknown_sqlstate); - my_snprintf(mysql->net.last_error, sizeof(mysql->net.last_error) - 1, - ER(mysql->net.last_errno), cs_name, cs_dir_name); - - } - charsets_dir= save_csdir; - return mysql->net.last_errno; -} - - uint STDCALL mysql_thread_safe(void) { #ifdef THREAD diff --git a/sql-common/client.c b/sql-common/client.c index c736acae857..4ecc8d26fc7 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -2206,7 +2206,8 @@ my_bool mysql_reconnect(MYSQL *mysql) tmp_mysql.rpl_pivot = mysql->rpl_pivot; if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd, mysql->db, mysql->port, mysql->unix_socket, - mysql->client_flag | CLIENT_REMEMBER_OPTIONS)) + mysql->client_flag | CLIENT_REMEMBER_OPTIONS) || + mysql_set_character_set(&tmp_mysql, mysql->charset->csname)) { mysql->net.last_errno= tmp_mysql.net.last_errno; strmov(mysql->net.last_error, tmp_mysql.net.last_error); @@ -2778,8 +2779,49 @@ uint STDCALL mysql_errno(MYSQL *mysql) return mysql->net.last_errno; } + const char * STDCALL mysql_error(MYSQL *mysql) { return mysql->net.last_error; } +/* + mysql_set_character_set function sends SET NAMES cs_name to + the server (which changes character_set_client, character_set_result + and character_set_connection) and updates mysql->charset so other + functions like mysql_real_escape will work correctly. +*/ +int STDCALL mysql_set_character_set(MYSQL *mysql, const char *cs_name) +{ + struct charset_info_st *cs; + const char *save_csdir= charsets_dir; + + if (mysql->options.charset_dir) + charsets_dir= mysql->options.charset_dir; + + if (strlen(cs_name) < MY_CS_NAME_SIZE && + (cs= get_charset_by_csname(cs_name, MY_CS_PRIMARY, MYF(0)))) + { + char buff[MY_CS_NAME_SIZE + 10]; + charsets_dir= save_csdir; + sprintf(buff, "SET NAMES %s", cs_name); + if (!mysql_real_query(mysql, buff, strlen(buff))) + { + mysql->charset= cs; + } + } + else + { + char cs_dir_name[FN_REFLEN]; + get_charsets_dir(cs_dir_name); + mysql->net.last_errno= CR_CANT_READ_CHARSET; + strmov(mysql->net.sqlstate, unknown_sqlstate); + my_snprintf(mysql->net.last_error, sizeof(mysql->net.last_error) - 1, + ER(mysql->net.last_errno), cs_name, cs_dir_name); + + } + charsets_dir= save_csdir; + return mysql->net.last_errno; +} + + |