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

client side implemetation for MDEV-10340:

int STDCALL mysql_reset_connection(MYSQL *mysql)
This commit is contained in:
Georg Richter
2016-12-29 19:10:35 +01:00
parent cae391f7bf
commit 87e861c360
10 changed files with 215 additions and 5 deletions

View File

@@ -1006,7 +1006,57 @@ static int test_unix_socket_close(MYSQL *unused __attribute__((unused)))
return OK;
}
static int test_reset(MYSQL *mysql)
{
int rc;
MYSQL_RES *res;
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "CREATE TABLE t1 (a int)");
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1),(2),(3)");
check_mysql_rc(rc, mysql);
FAIL_IF(mysql_affected_rows(mysql) != 3, "Expected 3 rows");
rc= mysql_reset_connection(mysql);
check_mysql_rc(rc, mysql);
FAIL_IF(mysql_affected_rows(mysql) != ~(unsigned long)0, "Expected 0 rows");
rc= mysql_query(mysql, "SELECT a FROM t1");
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "SELECT 1 FROM DUAL");
FAIL_IF(!rc, "Error expected");
rc= mysql_reset_connection(mysql);
check_mysql_rc(rc, mysql);
res= mysql_store_result(mysql);
FAIL_IF(res, "expected no result");
rc= mysql_query(mysql, "SELECT a FROM t1");
check_mysql_rc(rc, mysql);
res= mysql_use_result(mysql);
FAIL_IF(!res, "expected result");
rc= mysql_reset_connection(mysql);
check_mysql_rc(rc, mysql);
FAIL_IF(mysql_fetch_row(res), "expected error");
mysql_free_result(res);
return OK;
}
struct my_tests_st my_tests[] = {
{"test_reset", test_reset, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_unix_socket_close", test_unix_socket_close, TEST_CONNECTION_NONE, 0, NULL, NULL},
{"test_sess_track_db", test_sess_track_db, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_get_options", test_get_options, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},

View File

@@ -1180,8 +1180,84 @@ static int test_server_status(MYSQL *mysql)
return OK;
}
static int test_wl6797(MYSQL *mysql)
{
MYSQL_STMT *stmt;
int rc;
const char *stmt_text;
my_ulonglong res;
if (mysql_get_server_version(mysql) < 50703 ||
(mariadb_connection(mysql) && mysql_get_server_version(mysql) < 100203))
{
diag("Skipping test_wl6797: "
"tested feature does not exist in versions before MySQL 5.7.3 and MariaDB 10.2\n");
return OK;
}
/* clean up the session */
rc= mysql_reset_connection(mysql);
FAIL_UNLESS(rc == 0, "");
/* do prepare of a query */
mysql_query(mysql, "use test");
mysql_query(mysql, "DROP TABLE IF EXISTS t1");
mysql_query(mysql, "CREATE TABLE t1 (a int)");
stmt= mysql_stmt_init(mysql);
stmt_text= "INSERT INTO t1 VALUES (1), (2)";
rc= mysql_stmt_prepare(stmt, stmt_text, (ulong)strlen(stmt_text));
check_mysql_rc(rc, mysql);
/* Execute the insert statement */
rc= mysql_stmt_execute(stmt);
check_mysql_rc(rc, mysql);
/*
clean the session this should remove the prepare statement
from the cache.
*/
rc= mysql_reset_connection(mysql);
FAIL_UNLESS(rc == 0, "");
/* this below stmt should report error */
rc= mysql_stmt_execute(stmt);
FAIL_IF(rc == 0, "");
/*
bug#17653288: MYSQL_RESET_CONNECTION DOES NOT RESET LAST_INSERT_ID
*/
mysql_query(mysql, "DROP TABLE IF EXISTS t2");
rc= mysql_query(mysql, "CREATE TABLE t2 (a int NOT NULL PRIMARY KEY"\
" auto_increment)");
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "INSERT INTO t2 VALUES (null)");
check_mysql_rc(rc, mysql);
res= mysql_insert_id(mysql);
FAIL_UNLESS(res == 1, "");
rc= mysql_reset_connection(mysql);
FAIL_UNLESS(rc == 0, "");
res= mysql_insert_id(mysql);
FAIL_UNLESS(res == 0, "");
rc= mysql_query(mysql, "INSERT INTO t2 VALUES (last_insert_id(100))");
check_mysql_rc(rc, mysql);
res= mysql_insert_id(mysql);
FAIL_UNLESS(res == 100, "");
rc= mysql_reset_connection(mysql);
FAIL_UNLESS(rc == 0, "");
res= mysql_insert_id(mysql);
FAIL_UNLESS(res == 0, "");
mysql_query(mysql, "DROP TABLE IF EXISTS t1");
mysql_query(mysql, "DROP TABLE IF EXISTS t2");
mysql_stmt_close(stmt);
return OK;
}
struct my_tests_st my_tests[] = {
{"test_wl6797", test_wl6797, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_server_status", test_server_status, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_read_timeout", test_read_timeout, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_zerofill", test_zerofill, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},

View File

@@ -4501,7 +4501,36 @@ static int test_conc217(MYSQL *mysql)
return OK;
}
static int test_conc208(MYSQL *mysql)
{
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
int rc;
int data;
MYSQL_BIND bind;
rc= mysql_stmt_prepare(stmt, "SELECT \"100\" UNION SELECT \"88\" UNION SELECT \"389789\"", -1);
check_stmt_rc(rc, stmt);
memset(&bind, 0, sizeof(MYSQL_BIND));
bind.buffer_type= MYSQL_TYPE_LONG;
bind.buffer= (void *)&data;
rc= mysql_stmt_execute(stmt);
check_stmt_rc(rc, stmt);
rc= mysql_stmt_bind_result(stmt, &bind);
while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
{
diag("data=%d", data);
FAIL_IF(data != 100 && data != 88 && data != 389789, "Wrong value");
}
mysql_stmt_close(stmt);
return OK;
}
struct my_tests_st my_tests[] = {
{"test_conc208", test_conc208, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc217", test_conc217, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc205", test_conc205, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc198", test_conc198, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},