Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlsrv_fetch() with an out of range offset for SQLSRV_SCROLL_ABSOLUTE #223

Closed
yitam opened this issue Jan 12, 2017 · 1 comment
Closed

Comments

@yitam
Copy link
Contributor

yitam commented Jan 12, 2017

When client buffer is used, calling sqlsrv_fetch() with an out of bound offset will result in a fatal error. Should have caught the error gracefully. This is the repro scenario (happens in both Windows/Linux whether it's thread safe or not):

// the table has seven rows
$sql = "select upc, title, artist from cd_info order by rel_date";
$stmt = sqlsrv_query( $conn, $sql, array(), array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
if (! $stmt) {
	echo "Query failed\n";
	die (print_r(sqlsrv_errors(), true));
}

$row_count = sqlsrv_num_rows( $stmt );  
echo "\nRow count for first result set = $row_count\n";  

$row = sqlsrv_fetch($stmt, SQLSRV_SCROLL_LAST);  
$title = sqlsrv_get_field($stmt, 1);
var_dump($title);

$row = sqlsrv_fetch($stmt, SQLSRV_SCROLL_ABSOLUTE, 3);  
$title = sqlsrv_get_field($stmt, 1);
var_dump($title);

// this results in a fatal error (should have returned an error message gracefully)
$row = sqlsrv_fetch($stmt, SQLSRV_SCROLL_ABSOLUTE, 7);  
$title = sqlsrv_get_field($stmt, 1);
var_dump($title);

Actual output:

Row count for first result set = 7
string(17) "Casual Viewin USA"
string(12) "Mothers Milk"
PHP Fatal error:  Failed to find row 8 in the cache in ...filename.php on line 34

Fatal error: Failed to find row 8 in the cache in ...filename.php on line 34

Expected output:

Should have returned NULL / false

@v-kigos
Copy link
Contributor

v-kigos commented Jan 12, 2017

sqlsrv_fetch_array() will work as expected

$row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC,SQLSRV_SCROLL_ABSOLUTE,7);
returns: NULL

$row = sqlsrv_fetch_array($stmt,SQLSRV_SCROLL_ABSOLUTE,7);
returns: bool(false)

@yitam yitam self-assigned this Feb 9, 2017
@yitam yitam mentioned this issue Feb 9, 2017
@yitam yitam added the resolved label Feb 10, 2017
@yitam yitam closed this as completed Feb 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants