1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-08 14:02:17 +03:00

10.2-integration: Added support for character set "auto":

character set auto sets the character set to the corresponding locale or
codepage (windows)
This commit is contained in:
Georg Richter
2016-05-08 12:28:37 +02:00
parent c70128b50c
commit 6126e668ca
5 changed files with 67 additions and 17 deletions

View File

@@ -57,6 +57,8 @@ CHECK_FUNCTION_EXISTS (mlock HAVE_MLOCK)
CHECK_FUNCTION_EXISTS (mlockall HAVE_MLOCKALL)
CHECK_FUNCTION_EXISTS (mmap HAVE_MMAP)
CHECK_FUNCTION_EXISTS (mmap64 HAVE_MMAP64)
CHECK_FUNCTION_EXISTS (nl_langinfo HAVE_NL_LANGINFO)
CHECK_FUNCTION_EXISTS (setlocale HAVE_SETLOCALE)
CHECK_FUNCTION_EXISTS (perror HAVE_PERROR)
CHECK_FUNCTION_EXISTS (poll HAVE_POLL)
CHECK_FUNCTION_EXISTS (pread HAVE_PREAD)

View File

@@ -3,6 +3,8 @@
* Include file constants (processed in LibmysqlIncludeFiles.txt 1
*/
#cmakedefine HAVE_ALLOCA_H 1
#cmakedefine HAVE_SETLOCALE 1
#cmakedefine HAVE_NL_LANGINFO 1
#cmakedefine HAVE_ARPA_INET_H 1
#cmakedefine HAVE_CRYPT_H 1
#cmakedefine HAVE_DIRENT_H 1

View File

@@ -59,6 +59,12 @@
#include <iconv.h>
#endif
#if defined(HAVE_NL_LANGINFO) && defined(HAVE_SETLOCALE)
#include <locale.h>
#include <langinfo.h>
#endif
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
@@ -690,9 +696,15 @@ const MARIADB_CHARSET_INFO * mysql_find_charset_nr(unsigned int charsetnr)
MARIADB_CHARSET_INFO * mysql_find_charset_name(const char *name)
{
MARIADB_CHARSET_INFO *c = (MARIADB_CHARSET_INFO *)mariadb_compiled_charsets;
char *csname;
if (!strcasecmp(name, MADB_AUTODETECT_CHARSET_NAME))
csname= madb_get_os_character_set();
else
csname= (char *)name;
do {
if (!strcasecmp(c->csname, name)) {
if (!strcasecmp(c->csname, csname)) {
return(c);
}
++c;

View File

@@ -1417,19 +1417,7 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user,
/* Set character set */
if (mysql->options.charset_name)
{
if (!strcmp(mysql->options.charset_name, MADB_AUTODETECT_CHARSET_NAME))
{
char *csname= madb_get_os_character_set();
if (csname)
{
if (mysql->charset= mysql_find_charset_name(csname))
mysql_options(mysql, MYSQL_SET_CHARSET_NAME, csname);
}
}
else
mysql->charset= mysql_find_charset_name(mysql->options.charset_name);
}
else if (mysql->server_language)
mysql->charset= mysql_find_charset_nr(mysql->server_language);
else
@@ -2629,7 +2617,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...)
OPT_SET_VALUE_STR(&mysql->options, charset_dir, arg1);
break;
case MYSQL_SET_CHARSET_NAME:
OPT_SET_VALUE_STR(&mysql->options, charset_name, (char *)arg1);
OPT_SET_VALUE_STR(&mysql->options, charset_name, arg1);
break;
case MYSQL_OPT_RECONNECT:
mysql->options.reconnect= *(my_bool *)arg1;
@@ -3016,6 +3004,9 @@ mysql_get_optionv(MYSQL *mysql, enum mysql_option option, void *arg, ...)
*((char **)arg)= NULL;
break;
case MYSQL_SET_CHARSET_NAME:
if (mysql->charset)
*((char **)arg)= mysql->charset->csname;
else
*((char **)arg)= mysql->options.charset_name;
break;
case MYSQL_OPT_RECONNECT:

View File

@@ -726,7 +726,50 @@ static int test_utf16_utf32_noboms(MYSQL *mysql)
return OK;
}
static int charset_auto(MYSQL *my)
{
const char *csname1, *csname2;
char *osname;
MYSQL *mysql= mysql_init(NULL);
int rc;
osname= madb_get_os_character_set();
mysql_options(mysql, MYSQL_SET_CHARSET_NAME, "auto");
FAIL_IF(!mysql_real_connect(mysql, hostname, username,
password, schema, port, socketname, 0),
mysql_error(mysql));
csname1= mysql_character_set_name(mysql);
diag("Character set: %s os charset: %s", csname1, osname);
FAIL_IF(strcmp(osname, csname1), "character set is not os character set");
if (strcmp(osname, "utf8"))
{
rc= mysql_set_character_set(mysql, "utf8");
check_mysql_rc(rc, mysql);
csname2= mysql_character_set_name(mysql);
diag("Character set: %s", csname2);
FAIL_IF(!strcmp(csname2, csname1), "Wrong charset: expected utf8");
rc= mysql_set_character_set(mysql, "auto");
check_mysql_rc(rc, mysql);
csname2= mysql_character_set_name(mysql);
diag("Character set: %s", csname2);
FAIL_IF(strcmp(csname2, osname), "Wrong charset: expected os charset");
}
mysql_close(mysql);
return OK;
}
struct my_tests_st my_tests[] = {
{"charset_auto", charset_auto, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"bug_8378: mysql_real_escape with gbk", bug_8378, TEST_CONNECTION_NEW, 0, opt_bug8378, NULL},
{"test_client_character_set", test_client_character_set, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"bug_10214: mysql_real_escape with NO_BACKSLASH_ESCAPES", bug_10214, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},