Skip to content

Commit

Permalink
Merge pull request #283 from yitam/GH223
Browse files Browse the repository at this point in the history
Fix for issue 223
  • Loading branch information
v-dareck authored Feb 9, 2017
2 parents 451f84c + f90be11 commit 78bb2f2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions source/shared/core_stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ bool core_sqlsrv_fetch( sqlsrv_stmt* stmt, SQLSMALLINT fetch_orientation, SQLULE
if( stmt->cursor_type == SQL_CURSOR_FORWARD_ONLY ) {
stmt->past_fetch_end = true;
}
stmt->fetch_called = false; // reset this flag
return false;
}

Expand Down
59 changes: 59 additions & 0 deletions test/sqlsrv/srv_223_sqlsrv_fetch_absolute.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
--TEST--
sqlsrv_fetch() with SQLSRV_SCROLL_ABSOLUTE using out of range offset
--SKIPIF--
--FILE--
<?php

function print_errors($message = "")
{
if (strlen($message) > 0)
{
echo $message . "\n";
}
die( print_r( sqlsrv_errors(), true));
}

function test()
{
require_once("autonomous_setup.php");

// Connect
$conn = sqlsrv_connect($serverName, $connectionInfo);
if( !$conn ) { print_errors(); }

// Prepare the statement
$sql = "select name from sys.databases";
$stmt = sqlsrv_prepare( $conn, $sql, array(), array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED) );
if( $stmt === false ) { print_errors(); }
sqlsrv_execute($stmt);

// Get row count
$row_count = sqlsrv_num_rows( $stmt );
if ($row_count == 0) { print_errors("There should be at least one row!\n"); }

sqlsrv_execute($stmt);
$row = sqlsrv_fetch($stmt, SQLSRV_SCROLL_FIRST);
$field = sqlsrv_get_field($stmt, 0);
if (! $field) { print_errors(); }

$row = sqlsrv_fetch($stmt, SQLSRV_SCROLL_ABSOLUTE, 3);
$field = sqlsrv_get_field($stmt, 0);
if (! $field) { print_errors(); }

// this should return false
$row = sqlsrv_fetch($stmt, SQLSRV_SCROLL_ABSOLUTE, $row_count);
if ($row) { print_errors("This should return false!"); }
$field = sqlsrv_get_field($stmt, 0);
if ($field !== false) { print_errors("This should have resulted in error!"); }

sqlsrv_free_stmt( $stmt);
sqlsrv_close($conn);
}

test();

print "Done";
?>

--EXPECT--
Done

0 comments on commit 78bb2f2

Please sign in to comment.