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

Fix for conc-75: options not handled correctly after a reconnect occured

This commit is contained in:
Georg Richter
2014-02-07 11:31:30 +01:00
parent 74b3bbc6b5
commit 4f63028905
2 changed files with 54 additions and 1 deletions

View File

@@ -1968,8 +1968,21 @@ static my_bool mysql_reconnect(MYSQL *mysql)
my_set_error(mysql, CR_SERVER_GONE_ERROR, SQLSTATE_UNKNOWN, 0);
DBUG_RETURN(1);
}
mysql_init(&tmp_mysql);
tmp_mysql.options=mysql->options;
/* don't reread options from configuration files */
tmp_mysql.options.my_cnf_group= tmp_mysql.options.my_cnf_file= NULL;
/* make sure that we reconnect with the same character set */
if (!tmp_mysql.options.charset_name ||
strcmp(tmp_mysql.options.charset_name, mysql->charset->csname))
{
my_free(tmp_mysql.options.charset_name, MYF(MY_ALLOW_ZERO_PTR));
tmp_mysql.options.charset_name= my_strdup(mysql->charset->csname, MYF(MY_WME));
}
tmp_mysql.reconnect= mysql->reconnect;
bzero((char*) &mysql->options,sizeof(mysql->options));
if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd,
@@ -1981,10 +1994,11 @@ static my_bool mysql_reconnect(MYSQL *mysql)
tmp_mysql.net.last_error);
DBUG_RETURN(1);
}
tmp_mysql.free_me=mysql->free_me;
mysql->free_me=0;
mysql_close(mysql);
memset(&mysql->options, 0, sizeof(mysql->options));
*mysql=tmp_mysql;
mysql->reconnect= 1;
net_clear(&mysql->net);
mysql->affected_rows= ~(my_ulonglong) 0;

View File

@@ -30,6 +30,44 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "my_test.h"
#include "ma_common.h"
static int test_conc75(MYSQL *my)
{
int rc;
MYSQL *mysql;
int i;
mysql= mysql_init(NULL);
mysql_options(mysql, MYSQL_OPT_RECONNECT,(const char *)"true");
mysql_real_connect(mysql, hostname, username, password, schema, port, socketname, 0| CLIENT_MULTI_RESULTS | CLIENT_REMEMBER_OPTIONS);
rc= mysql_query(mysql, "DROP TABLE IF EXISTS a");
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "CREATE TABLE a (a varchar(200))");
check_mysql_rc(rc, mysql);
rc= mysql_set_character_set(mysql, "utf8");
check_mysql_rc(rc, mysql);
for (i=0; i < 10; i++)
{
ulong thread_id= mysql_thread_id(mysql);
/* force reconnect */
mysql_kill(my, thread_id);
sleep(1);
rc= mysql_query(mysql, "load data local infile './nonexistingfile.csv' into table a (`a`)");
FAIL_IF(!test(mysql->options.client_flag | CLIENT_LOCAL_FILES), "client_flags not correct");
FAIL_IF(thread_id == mysql_thread_id(mysql), "new thread id expected");
FAIL_IF(strcmp(mysql->charset->csname, "utf8"), "wrong character set");
}
mysql_close(mysql);
return OK;
}
static int test_conc74(MYSQL *my)
{
int rc;
@@ -703,6 +741,7 @@ static int test_compressed(MYSQL *my)
}
struct my_tests_st my_tests[] = {
{"test_conc75", test_conc75, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc74", test_conc74, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc71", test_conc71, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc70", test_conc70, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},