Bug #56677 SQLNumResultCols() causes the driver to return only first row in the resultset
Submitted: 9 Sep 2010 8:55 Modified: 16 Sep 2010 16:31
Reporter: Bogdan Degtyariov Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / ODBC Severity:S2 (Serious)
Version:5.1.7 OS:Any
Assigned to: Lawrenty Novitsky CPU Architecture:Any

[9 Sep 2010 8:55] Bogdan Degtyariov
Description:
When SQLNumResultCols() is called between SQLPrepare() and SQLExecute() the driver runs "SET @@sql_select_limit=1", which limits the resultset to just one row.

How to repeat:
See the test case uploaded later
[9 Sep 2010 10:05] Bogdan Degtyariov
/* test case */
/*
  Bug #56677 - SQLNumResultCols() causes the driver to return 
  only first row in the resultset
*/
DECLARE_TEST(t_bug56677)
{
  SQLINTEGER nData;
  SQLCHAR szData[16];
  SQLUSMALLINT rgfRowStatus;
  SQLULEN rowCount;
  SQLSMALLINT colCount;

  ok_sql(hstmt, "drop table if exists bug56677");
  ok_sql(hstmt, "CREATE TABLE bug56677 ("\
                "tt_int INT PRIMARY KEY auto_increment,"\
                "tt_varchar VARCHAR(128) NOT NULL)");
  ok_sql(hstmt, "INSERT INTO bug56677 VALUES "\
                "(100, 'string 1'),"\
                "(200, 'string 2'),"\
                "(300, 'string 3'),"\
                "(400, 'string 4')");

  ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));

  ok_stmt(hstmt, SQLPrepare(hstmt, "select * from bug56677", SQL_NTS));
  ok_stmt(hstmt, SQLNumResultCols(hstmt, &colCount));
  
  is_num(colCount, 2);

  ok_stmt(hstmt, SQLBindCol(hstmt, 1, SQL_C_LONG, &nData, 0, NULL));
  ok_stmt(hstmt, SQLBindCol(hstmt, 2, SQL_C_CHAR, szData, sizeof(szData),
                            NULL));

  ok_stmt(hstmt, SQLExecute(hstmt));

  ok_stmt(hstmt, SQLFetch(hstmt));
  is_num(nData, 100);
  is_str(szData, "string 1", 8);

  ok_stmt(hstmt, SQLFetch(hstmt));
  is_num(nData, 200);
  is_str(szData, "string 2", 8);

  ok_stmt(hstmt, SQLFetch(hstmt));
  is_num(nData, 300);
  is_str(szData, "string 3", 8);

  ok_stmt(hstmt, SQLFetch(hstmt));
  is_num(nData, 400);
  is_str(szData, "string 4", 8);

  ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
  ok_sql(hstmt, "drop table if exists bug56677");

  return OK;
}
[13 Sep 2010 16:48] Lawrenty Novitsky
patch has actually been pushed to the trunk as rev#928.
will post a diff here in a second.
[13 Sep 2010 16:49] Lawrenty Novitsky
the patch

Attachment: bug56677.patch (application/octet-stream, text), 0 bytes.

[14 Sep 2010 12:35] Lawrenty Novitsky
something went wrong at 1st attempt

Attachment: bug56677.patch (application/octet-stream, text), 2.44 KiB.

[16 Sep 2010 16:31] Tony Bedford
An entry has been added to the 5.1.8 changelog:

When SQLNumResultCols() was called between SQLPrepare() and SQLExecute() the driver ran SET @@sql_select_limit=1, which limited the resultset to just one row.