com php-src: PHP bug 67130: nextRowset should work with unfetched rows: ext/pdo_dblib/dblib_stmt.c ext/pdo_dblib/tests/bug_ 67130.phpt
| From: | Adam Baratz | Date: | Wed, 21 Sep 2016 18:27:23 +0000 |
| Subject: | com php-src: PHP bug 67130: nextRowset should work with unfetched rows: ext/pdo_dblib/dblib_stmt.c ext/pdo_dblib/tests/bug_ 67130.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-94611@lists.php.net to get a copy of this message | ||
Commit: dfd6baee0c7ca832140302694c88802dbebe4da1
Author: Peter LeBrun <plebrun@wayfair.com> Fri, 1 Jul 2016 15:44:06 -0400
Committer: Adam Baratz <adambaratz@php.net> Wed, 21 Sep 2016 14:27:23 -0400
Parents: b29ad29b916c367527732f8d529bf11fc2854bb0
Branches: PHP-7.0
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=dfd6baee0c7ca832140302694c88802dbebe4da1
Log:
PHP bug 67130: nextRowset should work with unfetched rows
Bugs:
https://bugs.php.net/67130
Changed paths:
M ext/pdo_dblib/dblib_stmt.c
A ext/pdo_dblib/tests/bug_67130.phpt
Diff:
diff --git a/ext/pdo_dblib/dblib_stmt.c b/ext/pdo_dblib/dblib_stmt.c
index 1c0577e..a230db2 100644
--- a/ext/pdo_dblib/dblib_stmt.c
+++ b/ext/pdo_dblib/dblib_stmt.c
@@ -119,7 +119,7 @@ static int pdo_dblib_stmt_dtor(pdo_stmt_t *stmt)
return 1;
}
-static int pdo_dblib_stmt_next_rowset(pdo_stmt_t *stmt)
+static int pdo_dblib_stmt_next_rowset_no_cancel(pdo_stmt_t *stmt)
{
pdo_dblib_stmt *S = (pdo_dblib_stmt*)stmt->driver_data;
pdo_dblib_db_handle *H = S->H;
@@ -142,6 +142,27 @@ static int pdo_dblib_stmt_next_rowset(pdo_stmt_t *stmt)
return 1;
}
+static int pdo_dblib_stmt_next_rowset(pdo_stmt_t *stmt)
+{
+ pdo_dblib_stmt *S = (pdo_dblib_stmt*)stmt->driver_data;
+ pdo_dblib_db_handle *H = S->H;
+ RETCODE ret = SUCCESS;
+
+ /* Ideally use dbcanquery here, but there is a bug in FreeTDS's implementation of dbcanquery
+ * It has been resolved but is currently only available in nightly builds
+ */
+ while (NO_MORE_ROWS != ret) {
+ ret = dbnextrow(H->link);
+
+ if (FAIL == ret) {
+ pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO_DBLIB: dbnextrow()
returned FAIL");
+ return 0;
+ }
+ }
+
+ return pdo_dblib_stmt_next_rowset_no_cancel(stmt);
+}
+
static int pdo_dblib_stmt_execute(pdo_stmt_t *stmt)
{
pdo_dblib_stmt *S = (pdo_dblib_stmt*)stmt->driver_data;
@@ -160,7 +181,7 @@ static int pdo_dblib_stmt_execute(pdo_stmt_t *stmt)
return 0;
}
- ret = pdo_dblib_stmt_next_rowset(stmt);
+ ret = pdo_dblib_stmt_next_rowset_no_cancel(stmt);
stmt->row_count = DBCOUNT(H->link);
stmt->column_count = dbnumcols(H->link);
diff --git a/ext/pdo_dblib/tests/bug_67130.phpt b/ext/pdo_dblib/tests/bug_67130.phpt
new file mode 100644
index 0000000..4cfb66f
--- /dev/null
+++ b/ext/pdo_dblib/tests/bug_67130.phpt
@@ -0,0 +1,36 @@
+--TEST--
+PDO_DBLIB: \PDOStatement::nextRowset() should succeed when all rows in current rowset haven't
been fetched
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo_dblib')) die('skip not loaded');
+require dirname(__FILE__) . '/config.inc';
+?>
+--FILE--
+<?php
+require dirname(__FILE__) . '/config.inc';
+
+$stmt = $db->query('SELECT 1; SELECT 2; SELECT 3;');
+var_dump($stmt->fetch());
+var_dump($stmt->fetch());
+var_dump($stmt->nextRowset());
+var_dump($stmt->nextRowset());
+var_dump($stmt->fetch());
+var_dump($stmt->nextRowset());
+?>
+--EXPECT--
+array(2) {
+ ["computed"]=>
+ int(1)
+ [0]=>
+ int(1)
+}
+bool(false)
+bool(true)
+bool(true)
+array(2) {
+ ["computed"]=>
+ int(3)
+ [0]=>
+ int(3)
+}
+bool(false)