summaryrefslogtreecommitdiff
path: root/libmysql
diff options
context:
space:
mode:
authorunknown <georg@lmy002.wdf.sap.corp>2005-05-13 15:06:11 +0200
committerunknown <georg@lmy002.wdf.sap.corp>2005-05-13 15:06:11 +0200
commit29f3f4a27fd2afa4a7fc57aaba86bb102e7cebe1 (patch)
tree73d80ebc495edaab921ce8b51e02295cbd8fa882 /libmysql
parentcbbc4ff6a25accdd3e11a0e2719c2201d23a7b68 (diff)
downloadmariadb-git-29f3f4a27fd2afa4a7fc57aaba86bb102e7cebe1.tar.gz
added function mysql_set_character_set (reviewed by Monty)
as a work around for #8317 and #9637 This function sends SET NAMES command and changes mysql->charset so mysql_real_escape_string will work as expected. libmysql/libmysql.def: added new function mysql_set_character_set
Diffstat (limited to 'libmysql')
-rw-r--r--libmysql/libmysql.c30
-rw-r--r--libmysql/libmysql.def1
2 files changed, 31 insertions, 0 deletions
diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c
index c663dab7476..4c9f06df38e 100644
--- a/libmysql/libmysql.c
+++ b/libmysql/libmysql.c
@@ -1509,6 +1509,36 @@ const char * STDCALL mysql_character_set_name(MYSQL *mysql)
return mysql->charset->csname;
}
+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)
{
diff --git a/libmysql/libmysql.def b/libmysql/libmysql.def
index c5579e9ec2b..57c97ab08ee 100644
--- a/libmysql/libmysql.def
+++ b/libmysql/libmysql.def
@@ -146,4 +146,5 @@ EXPORTS
mysql_rpl_query_type
mysql_slave_query
mysql_embedded
+ mysql_set_character_set
get_defaults_files