From 83631cdabcaf34a1ac8edc21ead4ccfd2c84433b Mon Sep 17 00:00:00 2001 From: David Puglielli Date: Thu, 7 Sep 2017 15:44:43 -0700 Subject: [PATCH] Added empty result set check to nextRowset() --- source/pdo_sqlsrv/pdo_stmt.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/pdo_sqlsrv/pdo_stmt.cpp b/source/pdo_sqlsrv/pdo_stmt.cpp index 85d726fd..d548d6bc 100644 --- a/source/pdo_sqlsrv/pdo_stmt.cpp +++ b/source/pdo_sqlsrv/pdo_stmt.cpp @@ -1067,6 +1067,14 @@ int pdo_sqlsrv_stmt_next_rowset( _Inout_ pdo_stmt_t *stmt TSRMLS_DC ) SQLSRV_ASSERT( driver_stmt != NULL, "pdo_sqlsrv_stmt_next_rowset: driver_data object was null" ); + // If SQLNumResultCols returns 0, the result set is empty. Normally this error is + // handled in core_sqlsrv_fetch, but if the user calls nextRowset() before fetch() + // the error message won't show up unless we handle it here. + SQLSMALLINT has_fields = core::SQLNumResultCols( driver_stmt TSRMLS_CC ); + CHECK_CUSTOM_ERROR( has_fields == 0, driver_stmt, SQLSRV_ERROR_NO_FIELDS ) { + throw core::CoreException(); + } + core_sqlsrv_next_result( static_cast( stmt->driver_data ) TSRMLS_CC ); // clear the current meta data since the new result will generate new meta data