summaryrefslogtreecommitdiff
path: root/ext/pdo_dblib/dblib_stmt.c
diff options
context:
space:
mode:
authorfandrieu <fandrieu@gmail.com>2017-10-17 14:16:38 -0400
committerAdam Baratz <adambaratz@php.net>2017-10-17 14:16:38 -0400
commit014fd21b482cd1aa8e3fc8662936c18cee300670 (patch)
treea5417a29cbc6b0d9bcc8c9928ec52bebebb4bce4 /ext/pdo_dblib/dblib_stmt.c
parentf16b918e471de6cef38f7768f51b5f3deb2c211d (diff)
downloadphp-git-014fd21b482cd1aa8e3fc8662936c18cee300670.tar.gz
Implemented request #69592: allow 0-column rowsets to be skipped automatically
This adds a new attribute PDO::DBLIB_ATTR_SKIP_EMPTY_ROWSETS to enable automatic skipping of empty rowsets. This happens with some SQL commands (like PRINT or SET): a rowset with 0 columns is returned by the driver. With this option enabled, 0 columns rowsets are automatically skipped, mirroring the behavior of the deprecated mssql extension. Credits go to MiRacLe-RPZ for developping and promoting this patch.
Diffstat (limited to 'ext/pdo_dblib/dblib_stmt.c')
-rw-r--r--ext/pdo_dblib/dblib_stmt.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/ext/pdo_dblib/dblib_stmt.c b/ext/pdo_dblib/dblib_stmt.c
index 6c8427da6b..469bd790de 100644
--- a/ext/pdo_dblib/dblib_stmt.c
+++ b/ext/pdo_dblib/dblib_stmt.c
@@ -124,20 +124,29 @@ 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;
RETCODE ret;
+ int num_fields;
+
+ do {
+ ret = dbresults(H->link);
+ num_fields = dbnumcols(H->link);
+ } while (H->skip_empty_rowsets && num_fields <= 0 && ret == SUCCEED);
- ret = dbresults(H->link);
if (FAIL == ret) {
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO_DBLIB: dbresults() returned FAIL");
return 0;
}
- if(NO_MORE_RESULTS == ret) {
+ if (NO_MORE_RESULTS == ret) {
+ return 0;
+ }
+
+ if (H->skip_empty_rowsets && num_fields <= 0) {
return 0;
}
stmt->row_count = DBCOUNT(H->link);
- stmt->column_count = dbnumcols(H->link);
+ stmt->column_count = num_fields;
return 1;
}