Description:
When using mysql_use_result, the mysql_fetch_row_nonblocking() function does not increment the number of rows, so that after all the rows are fetched, mysql_num_rows() will return the incorrect number of rows.
How to repeat:
Make the following modifications to the client test. They change the code to use mysql_use_result instead of mysql_store_result_nonblocking and then check mysql_num_rows() after the rows are fetched. Without the fix the test will fail.
diff --git a/testclients/mysql_client_test.cc b/testclients/mysql_client_test.cc
index 2c45d41da89..d272c5c4cdc 100644
--- a/testclients/mysql_client_test.cc
+++ b/testclients/mysql_client_test.cc
@@ -20225,18 +20225,8 @@ static void test_wl11381() {
} else {
fprintf(stdout, "\n mysql_real_query_nonblocking() passed");
}
- status = mysql_store_result_nonblocking(mysql_local, &result);
- /* do some other task */
- perform_arithmatic();
- while (status == NET_ASYNC_NOT_READY) {
- status = mysql_store_result_nonblocking(mysql_local, &result);
- }
- if (!result) {
- fprintf(stdout, "\n mysql_store_result_nonblocking() fetched 0 records");
- exit(1);
- } else {
- fprintf(stdout, "\n mysql_store_result_nonblocking() passed");
- }
+
+ result = mysql_use_result(mysql_local);
row = mysql_fetch_row(result);
DIE_UNLESS(strcmp(row[0], "10") == 0);
@@ -20263,6 +20253,7 @@ static void test_wl11381() {
fprintf(stdout, "\n mysql_fetch_row_nonblocking() passed");
}
+ DIE_UNLESS(mysql_num_rows(result) == 3);
while ((status = mysql_free_result_nonblocking(result)) != NET_ASYNC_COMPLETE)
;
fprintf(stdout, "\n mysql_free_result_nonblocking() passed");
Suggested fix:
diff --git a/sql-common/client.cc b/sql-common/client.cc
index fd36e9950cf..60ca2e3340b 100644
--- a/sql-common/client.cc
+++ b/sql-common/client.cc
@@ -7534,6 +7534,7 @@ net_async_status STDCALL mysql_fetch_row_nonblocking(MYSQL_RES *res,
}
if (!ret) {
+ res->row_count++;
*row = res->current_row = res->row;
goto end;
}
Description: When using mysql_use_result, the mysql_fetch_row_nonblocking() function does not increment the number of rows, so that after all the rows are fetched, mysql_num_rows() will return the incorrect number of rows. How to repeat: Make the following modifications to the client test. They change the code to use mysql_use_result instead of mysql_store_result_nonblocking and then check mysql_num_rows() after the rows are fetched. Without the fix the test will fail. diff --git a/testclients/mysql_client_test.cc b/testclients/mysql_client_test.cc index 2c45d41da89..d272c5c4cdc 100644 --- a/testclients/mysql_client_test.cc +++ b/testclients/mysql_client_test.cc @@ -20225,18 +20225,8 @@ static void test_wl11381() { } else { fprintf(stdout, "\n mysql_real_query_nonblocking() passed"); } - status = mysql_store_result_nonblocking(mysql_local, &result); - /* do some other task */ - perform_arithmatic(); - while (status == NET_ASYNC_NOT_READY) { - status = mysql_store_result_nonblocking(mysql_local, &result); - } - if (!result) { - fprintf(stdout, "\n mysql_store_result_nonblocking() fetched 0 records"); - exit(1); - } else { - fprintf(stdout, "\n mysql_store_result_nonblocking() passed"); - } + + result = mysql_use_result(mysql_local); row = mysql_fetch_row(result); DIE_UNLESS(strcmp(row[0], "10") == 0); @@ -20263,6 +20253,7 @@ static void test_wl11381() { fprintf(stdout, "\n mysql_fetch_row_nonblocking() passed"); } + DIE_UNLESS(mysql_num_rows(result) == 3); while ((status = mysql_free_result_nonblocking(result)) != NET_ASYNC_COMPLETE) ; fprintf(stdout, "\n mysql_free_result_nonblocking() passed"); Suggested fix: diff --git a/sql-common/client.cc b/sql-common/client.cc index fd36e9950cf..60ca2e3340b 100644 --- a/sql-common/client.cc +++ b/sql-common/client.cc @@ -7534,6 +7534,7 @@ net_async_status STDCALL mysql_fetch_row_nonblocking(MYSQL_RES *res, } if (!ret) { + res->row_count++; *row = res->current_row = res->row; goto end; }