From 2c28d0bf312fc856258c1aaaf23d44c8c4e83059 Mon Sep 17 00:00:00 2001 From: David Puglielli Date: Fri, 22 Sep 2017 00:13:33 -0400 Subject: [PATCH 1/2] Update stmt.cpp --- source/sqlsrv/stmt.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/source/sqlsrv/stmt.cpp b/source/sqlsrv/stmt.cpp index 5251834e..cb7fbff6 100644 --- a/source/sqlsrv/stmt.cpp +++ b/source/sqlsrv/stmt.cpp @@ -560,8 +560,17 @@ PHP_FUNCTION( sqlsrv_next_result ) PROCESS_PARAMS( stmt, "r", _FN_, 0 ); try { - - core_sqlsrv_next_result( stmt TSRMLS_CC, true ); + + // 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 sqlsrv_next_result() before fetch() the error is never shown so + // we handle it here. + SQLSMALLINT has_fields = core::SQLNumResultCols( stmt TSRMLS_CC ); + CHECK_CUSTOM_ERROR( has_fields == 0, stmt, SQLSRV_ERROR_NO_FIELDS ) { + throw core::CoreException(); + } + + core_sqlsrv_next_result( stmt TSRMLS_CC, true ); if( stmt->past_next_result_end ) { @@ -1006,15 +1015,6 @@ PHP_FUNCTION( sqlsrv_send_stream_data ) try { - // 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 sqlsrv_next_result() before fetch() the error is never shown so - // we handle it here. - SQLSMALLINT has_fields = core::SQLNumResultCols( stmt TSRMLS_CC ); - CHECK_CUSTOM_ERROR( has_fields == 0, stmt, SQLSRV_ERROR_NO_FIELDS ) { - throw core::CoreException(); - } - // if everything was sent at execute time, just return that there is nothing more to send. if( stmt->send_streams_at_exec ) { RETURN_NULL(); From f11c2084f28054674585f6c80534af5ec1f69a99 Mon Sep 17 00:00:00 2001 From: David Puglielli Date: Fri, 22 Sep 2017 00:33:37 -0400 Subject: [PATCH 2/2] Update sqlsrv_empty_result_error.phpt --- test/functional/sqlsrv/sqlsrv_empty_result_error.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/sqlsrv/sqlsrv_empty_result_error.phpt b/test/functional/sqlsrv/sqlsrv_empty_result_error.phpt index 68fedaa3..c8cb6b1d 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: