From 55a64c1bd5319cb2cd11c9f8bc67508d427dc378 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Fri, 2 Oct 2020 09:47:52 +0200 Subject: [PATCH] Fix for CONC-504: reset stmt->result.rows when executing mysql_stmt_next_result While in text protocol the number of rows is resetted in mysql_store/use_result in binary protocol we need to explicitly reset it when switching to next result set. --- libmariadb/mariadb_stmt.c | 1 + unittest/libmariadb/ps_bugs.c | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/libmariadb/mariadb_stmt.c b/libmariadb/mariadb_stmt.c index f72c0a56..1cb7cee7 100644 --- a/libmariadb/mariadb_stmt.c +++ b/libmariadb/mariadb_stmt.c @@ -2374,6 +2374,7 @@ int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt) } stmt->field_count= stmt->mysql->field_count; + stmt->result.rows= 0; return(rc); } diff --git a/unittest/libmariadb/ps_bugs.c b/unittest/libmariadb/ps_bugs.c index c9292b91..61f412a5 100644 --- a/unittest/libmariadb/ps_bugs.c +++ b/unittest/libmariadb/ps_bugs.c @@ -5232,7 +5232,50 @@ static int test_returning(MYSQL *mysql) return OK; } +static int test_conc504(MYSQL *mysql) +{ + int rc; + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + const char *sp= "CREATE PROCEDURE p1()\n" \ + "BEGIN\n"\ + " SELECT 1;\n"\ + " SELECT 2;\n"\ + " SELECT 3;\n"\ + "END"; + + rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, sp); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_prepare(stmt, SL("CALL p1()")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_store_result(stmt); + FAIL_IF(mysql_stmt_num_rows(stmt) != 1, "Expected 1 row"); + + mysql_stmt_next_result(stmt); + mysql_stmt_store_result(stmt); + FAIL_IF(mysql_stmt_num_rows(stmt) != 1, "Expected 1 row"); + + mysql_stmt_next_result(stmt); + mysql_stmt_store_result(stmt); + FAIL_IF(mysql_stmt_num_rows(stmt) != 1, "Expected 1 row"); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP PROCEDURE p1"); + check_mysql_rc(rc, mysql); + + return OK; +} + struct my_tests_st my_tests[] = { + {"test_conc504", test_conc504, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_returning", test_returning, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_mdev_21920", test_mdev_21920, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_maxparam", test_maxparam, TEST_CONNECTION_NEW, 0, NULL, NULL},