fix tests that uses scrollable cursor with AE

This commit is contained in:
v-kaywon 2018-01-18 15:35:13 -08:00
parent ef2a3e5717
commit 007e15c318
7 changed files with 322 additions and 393 deletions

View file

@ -41,8 +41,7 @@ function cursorScrollFetchRows($conn, $tableName)
$stmt = $conn->prepare("SELECT * FROM $tableName ORDER BY c1_int", array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL)); $stmt = $conn->prepare("SELECT * FROM $tableName ORDER BY c1_int", array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
} else { } else {
// ORDER BY is not supported for encrypted columns // ORDER BY is not supported for encrypted columns
// scrollable cursor is not supported for encrypted tablee; use client side buffered cursor $stmt = $conn->prepare("SELECT * FROM $tableName", array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$stmt = $conn->prepare("SELECT * FROM $tableName", array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
} }
$stmt->execute(); $stmt->execute();

View file

@ -3,28 +3,20 @@ Test the fetch() method for different fetch orientations with PDO::ATTR_CURSOR s
--ENV-- --ENV--
PHPT_EXEC=true PHPT_EXEC=true
--SKIPIF-- --SKIPIF--
<?php require('skipif.inc'); ?> <?php require('skipif_mid-refactor.inc'); ?>
--FILE-- --FILE--
<?php <?php
require_once("MsCommon_mid-refactor.inc");
require_once 'MsCommon.inc'; try {
function FetchAll($execMode, $fetchMode)
{
require_once 'MsCommon.inc';
require 'MsSetup.inc';
$testName = "PDO Statement - Fetch Scrollable";
StartTest($testName);
$conn1 = connect(); $conn1 = connect();
// Prepare test table // Prepare test table
$dataCols = "id, val"; $tableName = "pdo_test_table";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10)", null); createTable($conn1, $tableName, array(new ColumnMeta("int", "id", "NOT NULL PRIMARY KEY"), "val" => "varchar(10)"));
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A'", null); insertRow($conn1, $tableName, array("id" => 1, "val" => "A"));
InsertRowEx($conn1, $tableName, $dataCols, "2, 'B'", null); insertRow($conn1, $tableName, array("id" => 2, "val" => "B"));
InsertRowEx($conn1, $tableName, $dataCols, "3, 'C'", null); insertRow($conn1, $tableName, array("id" => 3, "val" => "C"));
// Query table and retrieve data // Query table and retrieve data
$stmt1 = $conn1->prepare( "SELECT val FROM $tableName", array( PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL )); $stmt1 = $conn1->prepare( "SELECT val FROM $tableName", array( PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL ));
@ -158,33 +150,15 @@ function FetchAll($execMode, $fetchMode)
} }
// Cleanup // Cleanup
DropTable($conn1, $tableName); dropTable($conn1, $tableName);
$stmt1 = null; unset($stmt1);
$conn1 = null; unset($conn1);
EndTest($testName); echo "Test 'PDO Statement - Fetch Scrollable' completed successfully.\n";
} catch (Exception $e) {
echo $e->getMessage();
} }
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
FetchAll(false, PDO::FETCH_BOTH);
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?> ?>
--EXPECT-- --EXPECT--
Test "PDO Statement - Fetch Scrollable" completed successfully. Test 'PDO Statement - Fetch Scrollable' completed successfully.

View file

@ -61,9 +61,7 @@ try {
echo "Now selecting....\n"; echo "Now selecting....\n";
$tsql = "SELECT * FROM [$tableName]"; $tsql = "SELECT * FROM [$tableName]";
$stmtOptions[PDO::ATTR_CURSOR] = PDO::CURSOR_SCROLL; $stmtOptions[PDO::ATTR_CURSOR] = PDO::CURSOR_SCROLL;
if (isColEncrypted()) {
$stmtOptions[PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE] = PDO::SQLSRV_CURSOR_BUFFERED;
}
$stmt1 = $conn1->prepare($tsql, $stmtOptions); $stmt1 = $conn1->prepare($tsql, $stmtOptions);
$stmt1->execute(); $stmt1->execute();
// The row order in the resultset when the column is encrypted (which is dependent on the encrytion key used) // The row order in the resultset when the column is encrypted (which is dependent on the encrytion key used)
@ -114,7 +112,6 @@ try {
} else { } else {
// more and less than operators do not work for encrypted columns // more and less than operators do not work for encrypted columns
$tsql = "SELECT * FROM [$tableName] WHERE NOT ID = :id"; $tsql = "SELECT * FROM [$tableName] WHERE NOT ID = :id";
unset($stmtOptions[PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE]);
$stmt2 = $conn1->prepare($tsql, $stmtOptions); $stmt2 = $conn1->prepare($tsql, $stmtOptions);
$id = 3; $id = 3;
$stmt2->bindParam(':id', $id); $stmt2->bindParam(':id', $id);

View file

@ -1,69 +1,63 @@
--TEST-- --TEST--
scrollable results with no rows. scrollable results with no rows.
--DESCRIPTION-- --DESCRIPTION--
this test is very similar to test_scrollable.phpt... might consider removing this test as a duplicate this test is very similar to test_scrollable.phpt... might consider removing this test as a duplicate
--SKIPIF-- --SKIPIF--
<?php require('skipif_versions_old.inc'); ?> <?php require('skipif_versions_old.inc'); ?>
--FILE-- --FILE--
<?php <?php
sqlsrv_configure('WarningsReturnAsErrors', 0); sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL); sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require_once('MsCommon.inc'); require_once('MsCommon.inc');
$conn = AE\connect(); $conn = AE\connect();
$tableName = 'ScrollTest'; $tableName = 'ScrollTest';
$columns = array(new AE\ColumnMeta('int', 'id'), $columns = array(new AE\ColumnMeta('int', 'id'),
new AE\ColumnMeta('char(10)', 'value')); new AE\ColumnMeta('char(10)', 'value'));
$stmt = AE\createTable($conn, $tableName, $columns); $stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) { if (!$stmt) {
fatalError("Failed to create table for the test]n"); fatalError("Failed to create table for the test]n");
} }
sqlsrv_free_stmt($stmt); sqlsrv_free_stmt($stmt);
// Always Encrypted feature only supports SQLSRV_CURSOR_FORWARD or $query = "SELECT * FROM $tableName";
// SQLSRV_CURSOR_CLIENT_BUFFERED $options = array('Scrollable' => 'static');
$query = "SELECT * FROM $tableName";
if (AE\isColEncrypted()) { $stmt = sqlsrv_query($conn, $query, array(), $options);
$options = array('Scrollable' => SQLSRV_CURSOR_FORWARD); $rows = sqlsrv_has_rows($stmt);
} else { if ($rows != false) {
$options = array('Scrollable' => 'static'); fatalError("Should be no rows present");
} };
$stmt = sqlsrv_query($conn, $query, array(), $options); if ($stmt === false) {
$rows = sqlsrv_has_rows($stmt); die(print_r(sqlsrv_errors(), true));
if ($rows != false) { }
fatalError("Should be no rows present"); $row = sqlsrv_fetch_array($stmt);
}; print_r($row);
if ($row === false) {
if ($stmt === false) { print_r(sqlsrv_errors(), true);
die(print_r(sqlsrv_errors(), true)); }
}
$row = sqlsrv_fetch_array($stmt); $stmt = sqlsrv_query($conn, $query);
print_r($row); $rows = sqlsrv_has_rows($stmt);
if ($row === false) { if ($rows != false) {
print_r(sqlsrv_errors(), true); fatalError("Should be no rows present");
} };
$stmt = sqlsrv_query($conn, $query); if ($stmt === false) {
$rows = sqlsrv_has_rows($stmt); die(print_r(sqlsrv_errors(), true));
if ($rows != false) { }
fatalError("Should be no rows present"); $row = sqlsrv_fetch_array($stmt);
}; print_r($row);
if ($row === false) {
if ($stmt === false) { print_r(sqlsrv_errors(), true);
die(print_r(sqlsrv_errors(), true)); }
}
$row = sqlsrv_fetch_array($stmt); dropTable($conn, $tableName);
print_r($row); echo "Test succeeded.\n";
if ($row === false) {
print_r(sqlsrv_errors(), true); ?>
} --EXPECT--
Test succeeded.
dropTable($conn, $tableName);
echo "Test succeeded.\n";
?>
--EXPECT--
Test succeeded.

View file

@ -45,30 +45,26 @@ function fetchRow($noRows)
sqlsrv_free_stmt($stmt2); sqlsrv_free_stmt($stmt2);
checkData($noRowsInserted, $numFields, $actual, $expected); checkData($noRowsInserted, $numFields, $actual, $expected);
// Always Encrypted feature does not support the following options // fetch object - STATIC cursor
// https://github.com/Microsoft/msphpsql/wiki/Features#aelimitation $options = array('Scrollable' => SQLSRV_CURSOR_STATIC);
if (!AE\isColEncrypted()) { $stmt2 = AE\executeQueryEx($conn1, $query, $options);
// fetch object - STATIC cursor $actual = fetchObject($stmt2, $noRowsInserted, $numFields, SQLSRV_SCROLL_RELATIVE);
$options = array('Scrollable' => SQLSRV_CURSOR_STATIC); sqlsrv_free_stmt($stmt2);
$stmt2 = AE\executeQueryEx($conn1, $query, $options); checkData($noRowsInserted, $numFields, $actual, $expected);
$actual = fetchObject($stmt2, $noRowsInserted, $numFields, SQLSRV_SCROLL_RELATIVE);
sqlsrv_free_stmt($stmt2);
checkData($noRowsInserted, $numFields, $actual, $expected);
// fetch object - DYNAMIC cursor // fetch object - DYNAMIC cursor
$options = array('Scrollable' => SQLSRV_CURSOR_DYNAMIC); $options = array('Scrollable' => SQLSRV_CURSOR_DYNAMIC);
$stmt2 = AE\executeQueryEx($conn1, $query, $options); $stmt2 = AE\executeQueryEx($conn1, $query, $options);
$actual = fetchObject($stmt2, $noRowsInserted, $numFields, SQLSRV_SCROLL_ABSOLUTE); $actual = fetchObject($stmt2, $noRowsInserted, $numFields, SQLSRV_SCROLL_ABSOLUTE);
sqlsrv_free_stmt($stmt2); sqlsrv_free_stmt($stmt2);
checkData($noRowsInserted, $numFields, $actual, $expected); checkData($noRowsInserted, $numFields, $actual, $expected);
// fetch object - KEYSET cursor // fetch object - KEYSET cursor
$options = array('Scrollable' => SQLSRV_CURSOR_KEYSET); $options = array('Scrollable' => SQLSRV_CURSOR_KEYSET);
$stmt2 = AE\executeQueryEx($conn1, $query, $options); $stmt2 = AE\executeQueryEx($conn1, $query, $options);
$actual = fetchObject($stmt2, $noRowsInserted, $numFields, SQLSRV_SCROLL_PRIOR, 0); $actual = fetchObject($stmt2, $noRowsInserted, $numFields, SQLSRV_SCROLL_PRIOR, 0);
sqlsrv_free_stmt($stmt2); sqlsrv_free_stmt($stmt2);
checkData($noRowsInserted, $numFields, $actual, $expected); checkData($noRowsInserted, $numFields, $actual, $expected);
}
dropTable($conn1, $tableName); dropTable($conn1, $tableName);

View file

@ -29,57 +29,31 @@ function streamScroll($noRows, $startRow)
AE\insertTestRowsByRange($conn1, $tableName, $startRow, $startRow + $noRows - 1); AE\insertTestRowsByRange($conn1, $tableName, $startRow, $startRow + $noRows - 1);
$query = "SELECT * FROM [$tableName] ORDER BY c27_timestamp"; $query = "SELECT * FROM [$tableName] ORDER BY c27_timestamp";
// Always Encrypted feature does not support SQLSRV_CURSOR_STATIC $options = array('Scrollable' => SQLSRV_CURSOR_STATIC);
// https://github.com/Microsoft/msphpsql/wiki/Features#aelimitation
if (AE\isColEncrypted()) {
$options = array('Scrollable' => SQLSRV_CURSOR_FORWARD);
} else {
$options = array('Scrollable' => SQLSRV_CURSOR_STATIC);
}
$stmt1 = AE\executeQueryEx($conn1, $query, $options); $stmt1 = AE\executeQueryEx($conn1, $query, $options);
$numFields = sqlsrv_num_fields($stmt1); $numFields = sqlsrv_num_fields($stmt1);
if (AE\isColEncrypted()) { $row = $noRows;
$row = $startRow; while ($row >= 1) {
while ($row <= $noRows) { if ($row == $noRows) {
if (!sqlsrv_fetch($stmt1, SQLSRV_SCROLL_NEXT)) { if (!sqlsrv_fetch($stmt1, SQLSRV_SCROLL_LAST)) {
fatalError("Failed to fetch row ".$row); fatalError("Failed to fetch row ".$row);
} }
trace("\nStreaming row $row:\n"); } else {
for ($j = 0; $j < $numFields; $j++) { if (!sqlsrv_fetch($stmt1, SQLSRV_SCROLL_PRIOR)) {
$col = $j + 1; fatalError("Failed to fetch row ".$row);
if (!isUpdatable($col)) {
continue;
}
if (isStreamable($col)) {
verifyStream($stmt1, $startRow + $row - 1, $j);
}
} }
$row++;
} }
} else { trace("\nStreaming row $row:\n");
$row = $noRows; for ($j = 0; $j < $numFields; $j++) {
while ($row >= 1) { $col = $j + 1;
if ($row == $noRows) { if (!isUpdatable($col)) {
if (!sqlsrv_fetch($stmt1, SQLSRV_SCROLL_LAST)) { continue;
fatalError("Failed to fetch row ".$row);
}
} else {
if (!sqlsrv_fetch($stmt1, SQLSRV_SCROLL_PRIOR)) {
fatalError("Failed to fetch row ".$row);
}
} }
trace("\nStreaming row $row:\n"); if (isStreamable($col)) {
for ($j = 0; $j < $numFields; $j++) { verifyStream($stmt1, $startRow + $row - 1, $j);
$col = $j + 1;
if (!isUpdatable($col)) {
continue;
}
if (isStreamable($col)) {
verifyStream($stmt1, $startRow + $row - 1, $j);
}
} }
$row--;
} }
$row--;
} }
sqlsrv_free_stmt($stmt1); sqlsrv_free_stmt($stmt1);

View file

@ -1,213 +1,208 @@
--TEST-- --TEST--
scrollable result sets. scrollable result sets.
--SKIPIF-- --SKIPIF--
<?php require('skipif_versions_old.inc'); ?> <?php require('skipif_versions_old.inc'); ?>
--FILE-- --FILE--
<?php <?php
sqlsrv_configure('WarningsReturnAsErrors', false); sqlsrv_configure('WarningsReturnAsErrors', false);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL); sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require_once('MsCommon.inc'); require_once('MsCommon.inc');
function hasRows($stmt, $expectedFail) function hasRows($stmt, $expectedFail)
{ {
$rows = sqlsrv_has_rows($stmt); $rows = sqlsrv_has_rows($stmt);
if ($expectedFail) { if ($expectedFail) {
if ($rows == true) { if ($rows == true) {
die("Shouldn't have rows"); die("Shouldn't have rows");
} }
} else { } else {
if ($rows != true) { if ($rows != true) {
die("Should have rows"); die("Should have rows");
} }
} }
} }
function countRows($stmt, $numRows, $cursorType, $initialCount = 0) function countRows($stmt, $numRows, $cursorType, $initialCount = 0)
{ {
$row_count = $initialCount; $row_count = $initialCount;
while ($row = sqlsrv_fetch($stmt)) { while ($row = sqlsrv_fetch($stmt)) {
++$row_count; ++$row_count;
} }
if($row === false) { if($row === false) {
die(print_r(sqlsrv_errors(), true)); die(print_r(sqlsrv_errors(), true));
} }
if ($row_count != $numRows) { if ($row_count != $numRows) {
echo "ERROR: $row_count rows retrieved on the $cursorType cursor\n"; echo "ERROR: $row_count rows retrieved on the $cursorType cursor\n";
} }
} }
function insertOneRow($conn, $tableName, $idx, $expectedFail) function insertOneRow($conn, $tableName, $idx, $expectedFail)
{ {
$res = null; $res = null;
$stmt = AE\insertRow($conn, $tableName, array('id' => $idx, 'value' => 'Row ' . $idx), $res, AE\INSERT_QUERY_PARAMS); $stmt = AE\insertRow($conn, $tableName, array('id' => $idx, 'value' => 'Row ' . $idx), $res, AE\INSERT_QUERY_PARAMS);
if (!$stmt || $res === false) { if (!$stmt || $res === false) {
fatalError("failed to insert row $idx!\n"); fatalError("failed to insert row $idx!\n");
} }
hasRows($stmt, $expectedFail); hasRows($stmt, $expectedFail);
sqlsrv_free_stmt($stmt); sqlsrv_free_stmt($stmt);
} }
$conn = AE\connect(); $conn = AE\connect();
$tableName = 'ScrollTest'; $tableName = 'ScrollTest';
$numRows = 4; $numRows = 4;
$columns = array(new AE\ColumnMeta('int', 'id'), $columns = array(new AE\ColumnMeta('int', 'id'),
new AE\ColumnMeta('char(10)', 'value')); new AE\ColumnMeta('char(10)', 'value'));
$stmt = AE\createTable($conn, $tableName, $columns); $stmt = AE\createTable($conn, $tableName, $columns);
$rows = sqlsrv_has_rows($stmt); $rows = sqlsrv_has_rows($stmt);
if($rows == true) { if($rows == true) {
die("Shouldn't have rows"); die("Shouldn't have rows");
} }
sqlsrv_free_stmt($stmt); sqlsrv_free_stmt($stmt);
for ($i = 1; $i <= $numRows; $i++) { for ($i = 1; $i <= $numRows; $i++) {
insertOneRow($conn, $tableName, $i, true); insertOneRow($conn, $tableName, $i, true);
} }
// Always Encrypted feature only supports SQLSRV_CURSOR_FORWARD, so skip the rest of the test $query = "SELECT * FROM $tableName";
// when AE is enabled $options = array('Scrollable' => SQLSRV_CURSOR_FORWARD);
// https://github.com/Microsoft/msphpsql/wiki/Features#aelimitation $stmt = sqlsrv_query($conn, $query, array(), $options);
$query = "SELECT * FROM $tableName";
$options = array('Scrollable' => SQLSRV_CURSOR_FORWARD); hasRows($stmt, false);
$stmt = sqlsrv_query($conn, $query, array(), $options); countRows($stmt, $numRows, 'forward only');
sqlsrv_free_stmt($stmt);
hasRows($stmt, false);
countRows($stmt, $numRows, 'forward only'); $options = array('Scrollable' => 'static');
sqlsrv_free_stmt($stmt); $stmt = sqlsrv_query($conn, $query, array(), $options);
if (! AE\isColEncrypted()) { $result = sqlsrv_fetch($stmt, SQLSRV_SCROLL_ABSOLUTE, 4);
$options = array('Scrollable' => 'static'); if($result !== null) {
$stmt = sqlsrv_query($conn, $query, array(), $options); die("Should have failed with an invalid row number");
}
$result = sqlsrv_fetch($stmt, SQLSRV_SCROLL_ABSOLUTE, 4); hasRows($stmt, false);
if($result !== null) { // this is empty
die("Should have failed with an invalid row number"); print_r(sqlsrv_errors());
} $result = sqlsrv_fetch($stmt, SQLSRV_SCROLL_ABSOLUTE, -1);
hasRows($stmt, false); if($result !== null) {
// this is empty die("Should have failed with an invalid row number");
print_r(sqlsrv_errors()); }
$result = sqlsrv_fetch($stmt, SQLSRV_SCROLL_ABSOLUTE, -1); // this is empty
if($result !== null) { print_r(sqlsrv_errors());
die("Should have failed with an invalid row number");
} // expected an error here
// this is empty $rows = sqlsrv_rows_affected($stmt);
print_r(sqlsrv_errors()); $message = !empty(sqlsrv_errors()) ? sqlsrv_errors()[0]['message'] : '';
$expected = 'This function only works with statements that are not scrollable.';
// expected an error here if (strcmp($message, $expected)) {
$rows = sqlsrv_rows_affected($stmt); echo "Expected this error message: \'$expected\'\nbut it is: \'$message\'\n";
$message = !empty(sqlsrv_errors()) ? sqlsrv_errors()[0]['message'] : ''; }
$expected = 'This function only works with statements that are not scrollable.';
if (strcmp($message, $expected)) { $rows = sqlsrv_num_rows($stmt);
echo "Expected this error message: \'$expected\'\nbut it is: \'$message\'\n"; if ($rows != $numRows) {
} echo "Error: Query returned $rows rows\n";
}
$rows = sqlsrv_num_rows($stmt);
if ($rows != $numRows) { $row = 3;
echo "Error: Query returned $rows rows\n"; $result = sqlsrv_fetch($stmt, SQLSRV_SCROLL_ABSOLUTE, $row);
} do {
$result = sqlsrv_fetch($stmt, SQLSRV_SCROLL_ABSOLUTE, $row);
$row = 3; if($result === false) {
$result = sqlsrv_fetch($stmt, SQLSRV_SCROLL_ABSOLUTE, $row); die(print_r(sqlsrv_errors(), true));
do { }
$result = sqlsrv_fetch($stmt, SQLSRV_SCROLL_ABSOLUTE, $row); $field1 = sqlsrv_get_field($stmt, 0);
if($result === false) { $field2 = sqlsrv_get_field($stmt, 1);
die(print_r(sqlsrv_errors(), true)); $idx = $row + 1;
}
$field1 = sqlsrv_get_field($stmt, 0); if ($field1 != $idx || trim($field2) != "Row $idx")
$field2 = sqlsrv_get_field($stmt, 1); echo "Field values unexpected $field1 $field2!\n";
$idx = $row + 1;
$row = $row - 1;
if ($field1 != $idx || trim($field2) != "Row $idx") } while($row >= 0);
echo "Field values unexpected $field1 $field2!\n"; sqlsrv_free_stmt($stmt);
$row = $row - 1; $options = array('Scrollable' => 'static');
} while($row >= 0); $stmt = sqlsrv_query($conn, $query, array(), $options);
sqlsrv_free_stmt($stmt);
hasRows($stmt, false);
$options = array('Scrollable' => 'static'); countRows($stmt, $numRows, 'static');
$stmt = sqlsrv_query($conn, $query, array(), $options); sqlsrv_free_stmt($stmt);
hasRows($stmt, false); $options = array('Scrollable' => 'dynamic');
countRows($stmt, $numRows, 'static'); $stmt = sqlsrv_query($conn, $query, array(), $options);
sqlsrv_free_stmt($stmt);
sqlsrv_fetch($stmt);
$options = array('Scrollable' => 'dynamic'); sqlsrv_fetch($stmt);
$stmt = sqlsrv_query($conn, $query, array(), $options);
insertOneRow($conn, $tableName, 5, true);
sqlsrv_fetch($stmt); insertOneRow($conn, $tableName, 6, true);
sqlsrv_fetch($stmt); $numRows = 6;
insertOneRow($conn, $tableName, 5, true); // to account for the two fetches above
insertOneRow($conn, $tableName, 6, true); countRows($stmt, $numRows, 'dynamic', 2);
$numRows = 6; sqlsrv_free_stmt($stmt);
// to account for the two fetches above $options = array('Scrollable' => SQLSRV_CURSOR_STATIC);
countRows($stmt, $numRows, 'dynamic', 2); $stmt = sqlsrv_query($conn, $query, array(), $options);
sqlsrv_free_stmt($stmt);
$row_count = sqlsrv_num_rows($stmt);
$options = array('Scrollable' => SQLSRV_CURSOR_STATIC); if($row_count != $numRows) {
$stmt = sqlsrv_query($conn, $query, array(), $options); die("sqlsrv_num_rows should have returned 6 rows in the static cursor\n");
}
$row_count = sqlsrv_num_rows($stmt); $row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC, SQLSRV_SCROLL_ABSOLUTE, -1);
if($row_count != $numRows) { if($row !== null) {
die("sqlsrv_num_rows should have returned 6 rows in the static cursor\n"); die("sqlsrv_fetch_array should have returned null\n");
} }
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC, SQLSRV_SCROLL_ABSOLUTE, -1);
if($row !== null) { $row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC, SQLSRV_SCROLL_ABSOLUTE, 6);
die("sqlsrv_fetch_array should have returned null\n"); if($row !== null) {
} die("sqlsrv_fetch_array should have returned null\n");
}
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC, SQLSRV_SCROLL_ABSOLUTE, 6);
if($row !== null) { $options = array('Scrollable' => SQLSRV_CURSOR_DYNAMIC);
die("sqlsrv_fetch_array should have returned null\n"); $stmt = sqlsrv_query($conn, $query, array(), $options);
}
$result = sqlsrv_num_rows($stmt);
$options = array('Scrollable' => SQLSRV_CURSOR_DYNAMIC); if($result !== false) {
$stmt = sqlsrv_query($conn, $query, array(), $options); die("sqlsrv_num_rows should have failed for a dynamic cursor.");
}
$result = sqlsrv_num_rows($stmt); sqlsrv_fetch($stmt);
if($result !== false) { sqlsrv_fetch($stmt);
die("sqlsrv_num_rows should have failed for a dynamic cursor.");
} $stmt2 = AE\executeQuery($conn, "DELETE FROM $tableName", "id = ?", array(2));
sqlsrv_fetch($stmt); if($stmt2 === false) {
sqlsrv_fetch($stmt); die(print_r(sqlsrv_errors(), true));
}
$stmt2 = sqlsrv_query($conn, "DELETE FROM ScrollTest WHERE id = 2");
if($stmt2 === false) { $row = sqlsrv_get_field($stmt, 0);
die(print_r(sqlsrv_errors(), true)); if($row !== false) {
} die("sqlsrv_get_field should have returned false retrieving a field deleted by another query");
}
$row = sqlsrv_get_field($stmt, 0); $error = sqlsrv_errors()[0];
if($row !== false) { $message = $error['message'];
die("sqlsrv_get_field should have returned false retrieving a field deleted by another query"); $sqlstate = $error['SQLSTATE'];
} if (strcmp($sqlstate, 'HY109') || strpos($message, 'Invalid cursor position') === false) {
$error = sqlsrv_errors()[0]; die("Unexpected SQL state $sqlstate or error \'$message\'");
$message = $error['message']; }
$sqlstate = $error['SQLSTATE'];
if (strcmp($sqlstate, 'HY109') || strpos($message, 'Invalid cursor position') === false) { // verify the sqlsrv_fetch_object is working
die("Unexpected SQL state $sqlstate or error \'$message\'"); $obj = sqlsrv_fetch_object($stmt, null, array(null), SQLSRV_SCROLL_LAST, 1);
} if($obj === false) {
print_r(sqlsrv_errors());
// verify the sqlsrv_fetch_object is working } else {
$obj = sqlsrv_fetch_object($stmt, null, array(null), SQLSRV_SCROLL_LAST, 1); if ($obj->id != $numRows || trim($obj->value) != "Row $numRows")
if($obj === false) { echo "Field values unexpected $obj->id $obj->value!\n";
print_r(sqlsrv_errors()); }
} else { sqlsrv_free_stmt($stmt);
if ($obj->id != $numRows || trim($obj->value) != "Row $numRows")
echo "Field values unexpected $obj->id $obj->value!\n"; dropTable($conn, $tableName);
} sqlsrv_close($conn);
sqlsrv_free_stmt($stmt);
} echo "Test succeeded.\n";
dropTable($conn, $tableName); ?>
sqlsrv_close($conn); --EXPECT--
Test succeeded.
echo "Test succeeded.\n";
?>
--EXPECT--
Test succeeded.