From b017a998efef5d1ee530dc6fd2b9816fef1d259a Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Sun, 16 Dec 2018 17:21:39 +0300 Subject: [PATCH] Fix GH-282: Mysql's fetch_row() is broken Fix both MySQL and PostgreSQL drivers to return an error when fetch_row() is called after retrieving all rows in the result set. --- src/drivers/mysql/drv_mysql.c | 4 +++- src/drivers/pgsql/drv_pgsql.c | 2 +- tests/include/api_sql_common.sh | 24 ++++++++++++++++++++++++ tests/t/api_sql_mysql.t | 14 ++++++++++++++ tests/t/api_sql_pgsql.t | 14 ++++++++++++++ 5 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/drivers/mysql/drv_mysql.c b/src/drivers/mysql/drv_mysql.c index f2f0afc56..1c7f8d7a5 100644 --- a/src/drivers/mysql/drv_mysql.c +++ b/src/drivers/mysql/drv_mysql.c @@ -969,8 +969,10 @@ int mysql_drv_fetch_row(db_result_t *rs, db_row_t *row) DEBUG("mysql_fetch_row(%p) = %p", rs->ptr, my_row); unsigned long *lengths = mysql_fetch_lengths(rs->ptr); + DEBUG("mysql_fetch_lengths(%p) = %p", rs->ptr, lengths); + if (lengths == NULL) - return DB_ERROR_NONE; + return DB_ERROR_IGNORABLE; for (size_t i = 0; i < rs->nfields; i++) { diff --git a/src/drivers/pgsql/drv_pgsql.c b/src/drivers/pgsql/drv_pgsql.c index f7fceea15..7c2ffe2f7 100644 --- a/src/drivers/pgsql/drv_pgsql.c +++ b/src/drivers/pgsql/drv_pgsql.c @@ -721,7 +721,7 @@ int pgsql_drv_fetch_row(db_result_t *rs, db_row_t *row) */ rownum = (intptr_t) row->ptr; if (rownum >= (int) rs->nrows) - return DB_ERROR_NONE; + return DB_ERROR_IGNORABLE; for (i = 0; i < (int) rs->nfields; i++) { diff --git a/tests/include/api_sql_common.sh b/tests/include/api_sql_common.sh index 3d9c0f8e8..959e30473 100644 --- a/tests/include/api_sql_common.sh +++ b/tests/include/api_sql_common.sh @@ -181,9 +181,11 @@ EOF sysbench $SB_ARGS run +cat <$CRAMTMP/api_sql.lua <$CRAMTMP/api_sql.lua <$CRAMTMP/api_sql.lua <$CRAMTMP/api_sql.lua <