[CONC-344] mysql_stmt_num_rows() delivers wrong result Created: 2018-06-28  Updated: 2018-08-08  Resolved: 2018-06-28

Status: Closed
Project: MariaDB Connector/C
Component/s: None
Affects Version/s: 3.0.5
Fix Version/s: 3.0.6

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


 Description   

After fetching all rows from an unbuffered prepared statement result set, a new call to mysql_stmt_execute() doesn't reset internal number of rows (stmt->result.rows).

Test case:

static int test_num_rows(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;
}

Output:

# num_rows: 6
# Error: expected 1 row


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