From c1a1a0606166c1a3bd0a412e2306b4b5bbcde2e8 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Mon, 20 Mar 2017 15:58:57 -0700 Subject: [PATCH 1/2] fix crash from getting the numrow of a null buffered result set; add test --- source/shared/core_results.cpp | 7 ++++- ...v_330_numrow_null_buffered_result_set.phpt | 31 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/sqlsrv/srv_330_numrow_null_buffered_result_set.phpt diff --git a/source/shared/core_results.cpp b/source/shared/core_results.cpp index fd7209610..67c82e0e0 100644 --- a/source/shared/core_results.cpp +++ b/source/shared/core_results.cpp @@ -907,7 +907,12 @@ SQLLEN sqlsrv_buffered_result_set::row_count( TSRMLS_D ) { last_error = NULL; - return zend_hash_num_elements( cache ); + if ( cache ) { + return zend_hash_num_elements( cache ); + } + else { + return -1; + } } // private functions diff --git a/test/sqlsrv/srv_330_numrow_null_buffered_result_set.phpt b/test/sqlsrv/srv_330_numrow_null_buffered_result_set.phpt new file mode 100644 index 000000000..a9e3040ed --- /dev/null +++ b/test/sqlsrv/srv_330_numrow_null_buffered_result_set.phpt @@ -0,0 +1,31 @@ +--TEST-- +GitHub issue #330 - get numrow of null buffered result set +--DESCRIPTION-- +A variation of the example in GitHub issue 330. A -1 value returned as numrow of a null buffered result set. +--SKIPIF-- +--FILE-- + SQLSRV_CURSOR_CLIENT_BUFFERED]); + +if ($stmt) { + $hasRows = sqlsrv_has_rows($stmt); + $numRows = sqlsrv_num_rows($stmt); + echo "hasRows: "; + var_dump($hasRows); + echo "numRows: "; + var_dump($numRows); +} +?> +--EXPECT-- +hasRows: bool(false) +numRows: int(-1) \ No newline at end of file From d68300ff5350b7e68bd5297c5ed94c390b16a662 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Thu, 23 Mar 2017 10:52:02 -0700 Subject: [PATCH 2/2] Update core_results.cpp --- source/shared/core_results.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/source/shared/core_results.cpp b/source/shared/core_results.cpp index 67c82e0e0..7c2b1bfdf 100644 --- a/source/shared/core_results.cpp +++ b/source/shared/core_results.cpp @@ -911,6 +911,7 @@ SQLLEN sqlsrv_buffered_result_set::row_count( TSRMLS_D ) return zend_hash_num_elements( cache ); } else { + // returning -1 to represent getting the rowcount of an empty result set return -1; } }