[CONC-504] mysql_stmt_num_rows returns accumulated number of rows of all stored resultsets Created: 2020-10-01  Updated: 2020-10-05  Resolved: 2020-10-02

Status: Closed
Project: MariaDB Connector/C
Component/s: None
Affects Version/s: 3.1.10
Fix Version/s: 3.1.11

Type: Bug Priority: Major
Reporter: Lawrin Novitsky Assignee: Georg Richter
Resolution: Fixed Votes: 0
Labels: None


 Description   

The KnowledgeBase says, that "mysql_stmt_num_rows ... Returns the number of rows in the result set." But it looks like in case of multiple results, the number returned by mysql_stmt_num_rows is accumulated number of rows in all stored to the moment resultsets.

 MYSQL      *ma;
 MYSQL_STMT *stmt;
 
 if (!mysql_real_connect(ma, "localhost", "uid", "pwd", "test", 3306, NULL, 0))
  {
    printf("Could not connect: %s\n", mysql_error(ma));
    exit(1);
  }
  stmt = mysql_stmt_init(ma);
 
  mysql_query(ma, "DROP PROCEDURE IF EXISTS p");
  mysql_query(ma, "CREATE PROCEDURE p() BEGIN SELECT 1; SELECT 2; SELECT 3; END;");
 
  mysql_stmt_prepare(stmt, "call p()", -1);
 
  mysql_stmt_execute(stmt);
 
  mysql_stmt_store_result(stmt);
  printf("Number of rows: %llu\n", mysql_stmt_num_rows(stmt));
 
  mysql_stmt_next_result(stmt);
  mysql_stmt_store_result(stmt);
 
  printf("Number of rows: %llu\n", mysql_stmt_num_rows(stmt));
 
  mysql_stmt_next_result(stmt);
  mysql_stmt_store_result(stmt);
  printf("Number of rows: %llu\n", mysql_stmt_num_rows(stmt));
 
  mysql_stmt_close(stmt);
  mysql_close(ma);

I'd say, that stmt->result.rows should be reset by mysql_stmt_next_result somewhere at the end of function - like before or after
stmt->field_count= stmt->mysql->field_count;



 Comments   
Comment by Georg Richter [ 2020-10-02 ]

Fixed in rev. 55a64c1bd5319cb2cd11c9f8bc67508d427dc378

Generated at Thu Feb 08 03:05:47 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.