diff --git a/source/pdo_sqlsrv/pdo_stmt.cpp b/source/pdo_sqlsrv/pdo_stmt.cpp index 549de06f..b74ca360 100644 --- a/source/pdo_sqlsrv/pdo_stmt.cpp +++ b/source/pdo_sqlsrv/pdo_stmt.cpp @@ -1067,12 +1067,16 @@ 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" ); - // Make sure that the result set is not null, i.e. SQLNumResultCols() does not - // return 0. Normally this error is handled in core_sqlsrv_fetch, but if the - // user calls nextRowset() before fetch() the error is never shown so 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(); + // Make sure that the result set is not null. Null means SQLNumResultCols returns 0 + // and SQLRowCount is not > 0. Normally this error is handled in core_sqlsrv_fetch(), + // but if the user calls nextRowset() before fetch() the error is never shown + // so we handle it here. + bool has_result = core_sqlsrv_has_any_result( driver_stmt ); + + if(!driver_stmt->fetch_called){ + CHECK_CUSTOM_ERROR( !has_result, driver_stmt, SQLSRV_ERROR_NO_FIELDS ) { + throw core::CoreException(); + } } core_sqlsrv_next_result( static_cast( stmt->driver_data ) TSRMLS_CC ); diff --git a/source/sqlsrv/stmt.cpp b/source/sqlsrv/stmt.cpp index 57be959b..3feb2c5b 100644 --- a/source/sqlsrv/stmt.cpp +++ b/source/sqlsrv/stmt.cpp @@ -561,6 +561,18 @@ PHP_FUNCTION( sqlsrv_next_result ) try { + // Make sure that the result set is not null. Null means SQLNumResultCols returns 0 + // and SQLRowCount is not > 0. Normally this error is handled in core_sqlsrv_fetch(), + // but if the user calls sqlsrv_next_result() before fetch() the error is never shown + // so we handle it here. + bool has_result = core_sqlsrv_has_any_result( stmt ); + + if(!stmt->fetch_called){ + CHECK_CUSTOM_ERROR( !has_result, stmt, SQLSRV_ERROR_NO_FIELDS ) { + throw core::CoreException(); + } + } + core_sqlsrv_next_result( stmt TSRMLS_CC, true ); if( stmt->past_next_result_end ) { diff --git a/test/functional/sqlsrv/sqlsrv_empty_result_error.phpt b/test/functional/sqlsrv/sqlsrv_empty_result_error.phpt index 68fedaa3..f073d4e5 100644 --- a/test/functional/sqlsrv/sqlsrv_empty_result_error.phpt +++ b/test/functional/sqlsrv/sqlsrv_empty_result_error.phpt @@ -56,7 +56,7 @@ print_r(sqlsrv_errors()); $stmt = sqlsrv_query($conn, "DROP TABLE TestEmptySetTable"); $stmt = sqlsrv_query($conn, "DROP PROCEDURE TestEmptySetProc"); -sqlsrv_free($conn); +sqlsrv_close($conn); ?> --EXPECT-- Return a nonempty result set: @@ -68,16 +68,6 @@ Array Array ( [0] => Array - ( - [0] => IMSSP - [SQLSTATE] => IMSSP - [1] => -26 - [code] => -26 - [2] => There are no more results returned by the query. - [message] => There are no more results returned by the query. - ) - - [1] => Array ( [0] => HY010 [SQLSTATE] => HY010