Merge pull request #333 from v-kaywon/numrow_null_result

fix crash from getting the numrow of a null buffered result set
This commit is contained in:
v-kaywon 2017-03-23 11:46:57 -07:00 committed by GitHub
commit 566a2dafb0
2 changed files with 38 additions and 1 deletions

View file

@ -907,7 +907,13 @@ 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 {
// returning -1 to represent getting the rowcount of an empty result set
return -1;
}
}
// private functions

View file

@ -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--
<?php
require_once("tools.inc");
require_once("autonomous_setup.php");
// Connect
$conn = sqlsrv_connect($serverName, $connectionInfo) ?: FatalError("Failed to connect");
$stmt = sqlsrv_query($conn, "IF EXISTS (SELECT * FROM [sys].[objects] WHERE (name LIKE 'non_existent_table_name%') AND type in (N'U'))
BEGIN
select 0
END", [], ['Scrollable' => 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)