diff --git a/libmariadb/mariadb_stmt.c b/libmariadb/mariadb_stmt.c index 9630387e..5ed9e2c5 100644 --- a/libmariadb/mariadb_stmt.c +++ b/libmariadb/mariadb_stmt.c @@ -1977,8 +1977,9 @@ int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) { ma_free_root(&stmt->result.alloc, MYF(MY_KEEP_PREALLOC)); stmt->result_cursor= stmt->result.data= 0; - stmt->result.rows= 0; } + /* CONC-344: set row count to zero */ + stmt->result.rows= 0; if (stmt->array_size > 0) request= (char *)mysql_stmt_execute_generate_bulk_request(stmt, &request_len); else diff --git a/unittest/libmariadb/ps_bugs.c b/unittest/libmariadb/ps_bugs.c index d250835d..0ee6d365 100644 --- a/unittest/libmariadb/ps_bugs.c +++ b/unittest/libmariadb/ps_bugs.c @@ -4651,40 +4651,6 @@ static int test_compress(MYSQL *mysql) return OK; } -static int test_conc334(MYSQL *mysql) -{ - MYSQL_STMT *stmt= mysql_stmt_init(mysql); - MYSQL_RES *result; - MYSQL_FIELD *field; - int rc; - - rc= mysql_stmt_prepare(stmt, SL("SHOW ENGINES")); - check_stmt_rc(rc, stmt); - - rc= mysql_stmt_execute(stmt); - check_stmt_rc(rc, stmt); - - result= mysql_stmt_result_metadata(stmt); - if (!result) - { - diag("Coudn't retrieve result set"); - mysql_stmt_close(stmt); - return FAIL; - } - - mysql_field_seek(result, 0); - - while ((field= mysql_fetch_field(result))) - { - FAIL_IF(field->name_length == 0, "Invalid name length (0)"); - FAIL_IF(field->table_length == 0, "Invalid name length (0)"); - } - mysql_free_result(result); - mysql_stmt_close(stmt); - - return OK; -} - static int test_codbc138(MYSQL *mysql) { int rc; @@ -4753,7 +4719,70 @@ static int test_codbc138(MYSQL *mysql) return OK; } +static int test_conc334(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + MYSQL_RES *result; + MYSQL_FIELD *field; + int rc; + + rc= mysql_stmt_prepare(stmt, SL("SHOW ENGINES")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + result= mysql_stmt_result_metadata(stmt); + if (!result) + { + diag("Coudn't retrieve result set"); + mysql_stmt_close(stmt); + return FAIL; + } + + mysql_field_seek(result, 0); + + while ((field= mysql_fetch_field(result))) + { + FAIL_IF(field->name_length == 0, "Invalid name length (0)"); + FAIL_IF(field->table_length == 0, "Invalid name length (0)"); + } + mysql_free_result(result); + mysql_stmt_close(stmt); + + return OK; +} + +static int test_conc344(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + int rc; + + rc= mysql_query(mysql, "CREATE OR REPLACE TABLE t1 (a int, b int)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1,1), (2,2),(3,3),(4,4),(5,5)"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_prepare(stmt, SL("SELECT * FROM t1 ORDER BY a")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + while (!mysql_stmt_fetch(stmt)); + FAIL_IF(mysql_stmt_num_rows(stmt) != 5, "expected 5 rows"); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_fetch(stmt); + diag("num_rows: %lld", mysql_stmt_num_rows(stmt)); + FAIL_IF(mysql_stmt_num_rows(stmt) != 1, "expected 1 row"); + + mysql_stmt_close(stmt); + return OK; +} + struct my_tests_st my_tests[] = { + {"test_conc344", test_conc344, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_conc334", test_conc334, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_compress", test_compress, TEST_CONNECTION_NEW, CLIENT_COMPRESS, NULL, NULL}, {"test_codbc138", test_codbc138, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},