diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index e702c8a2..8049259c 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -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; diff --git a/unittest/libmariadb/basic-t.c b/unittest/libmariadb/basic-t.c index f8cae7c0..46041da0 100644 --- a/unittest/libmariadb/basic-t.c +++ b/unittest/libmariadb/basic-t.c @@ -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},