Skip to content

Commit

Permalink
fix crash from getting the numrow of a null buffered result set; add …
Browse files Browse the repository at this point in the history
…test
  • Loading branch information
yukiwongky committed Mar 20, 2017
1 parent 7434d06 commit c1a1a06
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
7 changes: 6 additions & 1 deletion source/shared/core_results.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions test/sqlsrv/srv_330_numrow_null_buffered_result_set.phpt
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit c1a1a06

Please sign in to comment.