You've already forked mariadb-connector-c
mirror of
https://github.com/mariadb-corporation/mariadb-connector-c.git
synced 2025-08-08 14:02:17 +03:00
Fix for CONC-154:
set stmt->state to MYSQL_STMT_FETCH_DONE if - result set is empty (nothing to fetch) - when madb_stmt_reset was called
This commit is contained in:
@@ -1377,8 +1377,12 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt)
|
|||||||
|
|
||||||
stmt->result_cursor= stmt->result.data;
|
stmt->result_cursor= stmt->result.data;
|
||||||
stmt->fetch_row_func= stmt_buffered_fetch;
|
stmt->fetch_row_func= stmt_buffered_fetch;
|
||||||
stmt->mysql->status= MYSQL_STATUS_READY;
|
stmt->mysql->status= MYSQL_STATUS_READY;
|
||||||
stmt->state= MYSQL_STMT_USE_OR_STORE_CALLED;
|
|
||||||
|
if (!stmt->result.rows)
|
||||||
|
stmt->state= MYSQL_STMT_FETCH_DONE;
|
||||||
|
else
|
||||||
|
stmt->state= MYSQL_STMT_USE_OR_STORE_CALLED;
|
||||||
|
|
||||||
/* set affected rows: see bug 2247 */
|
/* set affected rows: see bug 2247 */
|
||||||
stmt->upsert_status.affected_rows= stmt->result.rows;
|
stmt->upsert_status.affected_rows= stmt->result.rows;
|
||||||
@@ -1643,6 +1647,7 @@ static my_bool madb_reset_stmt(MYSQL_STMT *stmt, unsigned int flags)
|
|||||||
stmt->result.rows= 0;
|
stmt->result.rows= 0;
|
||||||
stmt->result_cursor= NULL;
|
stmt->result_cursor= NULL;
|
||||||
stmt->mysql->status= MYSQL_STATUS_READY;
|
stmt->mysql->status= MYSQL_STATUS_READY;
|
||||||
|
stmt->state= MYSQL_STMT_FETCH_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if there is a pending result set, we will flush it */
|
/* if there is a pending result set, we will flush it */
|
||||||
|
@@ -3909,7 +3909,111 @@ static int test_conc141(MYSQL *mysql)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int test_conc154(MYSQL *mysql)
|
||||||
|
{
|
||||||
|
MYSQL_STMT *stmt;
|
||||||
|
const char *stmtstr= "SELECT * FROM t1";
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
/* 1st: empty result set without free_result */
|
||||||
|
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
|
||||||
|
check_mysql_rc(rc, mysql);
|
||||||
|
rc= mysql_query(mysql, "CREATE TABLE t1 (a varchar(20))");
|
||||||
|
check_mysql_rc(rc, mysql);
|
||||||
|
|
||||||
|
stmt= mysql_stmt_init(mysql);
|
||||||
|
rc= mysql_stmt_prepare(stmt, stmtstr, strlen(stmtstr));
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
rc= mysql_stmt_execute(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
rc= mysql_stmt_store_result(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
rc= mysql_stmt_execute(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
rc= mysql_stmt_store_result(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
mysql_stmt_close(stmt);
|
||||||
|
|
||||||
|
/* 2nd: empty result set with free_result */
|
||||||
|
stmt= mysql_stmt_init(mysql);
|
||||||
|
rc= mysql_stmt_prepare(stmt, stmtstr, strlen(stmtstr));
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
rc= mysql_stmt_execute(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
rc= mysql_stmt_store_result(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
rc= mysql_stmt_free_result(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
rc= mysql_stmt_execute(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
rc= mysql_stmt_store_result(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
rc= mysql_stmt_free_result(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
mysql_stmt_close(stmt);
|
||||||
|
|
||||||
|
/* 3rd: non empty result without free_result */
|
||||||
|
rc= mysql_query(mysql, "INSERT INTO t1 VALUES ('test_conc154')");
|
||||||
|
check_mysql_rc(rc, mysql);
|
||||||
|
|
||||||
|
stmt= mysql_stmt_init(mysql);
|
||||||
|
rc= mysql_stmt_prepare(stmt, stmtstr, strlen(stmtstr));
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
rc= mysql_stmt_execute(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
rc= mysql_stmt_store_result(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
rc= mysql_stmt_execute(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
rc= mysql_stmt_store_result(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
mysql_stmt_close(stmt);
|
||||||
|
|
||||||
|
/* 4th non empty result set with free_result */
|
||||||
|
stmt= mysql_stmt_init(mysql);
|
||||||
|
rc= mysql_stmt_prepare(stmt, stmtstr, strlen(stmtstr));
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
rc= mysql_stmt_execute(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
rc= mysql_stmt_store_result(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
rc= mysql_stmt_free_result(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
rc= mysql_stmt_execute(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
rc= mysql_stmt_store_result(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
rc= mysql_stmt_free_result(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
mysql_stmt_close(stmt);
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
struct my_tests_st my_tests[] = {
|
struct my_tests_st my_tests[] = {
|
||||||
|
{"test_conc154", test_conc154, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
|
||||||
{"test_conc141", test_conc141, TEST_CONNECTION_NEW, 0, NULL , NULL},
|
{"test_conc141", test_conc141, TEST_CONNECTION_NEW, 0, NULL , NULL},
|
||||||
{"test_conc67", test_conc67, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
|
{"test_conc67", test_conc67, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
|
||||||
{"test_conc_5", test_conc_5, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
|
{"test_conc_5", test_conc_5, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
|
||||||
|
Reference in New Issue
Block a user