php-sqlsrv/test/functional/sqlsrv/TC39_Cursors.phpt

101 lines
2.6 KiB
Plaintext
Raw Normal View History

2017-05-04 01:00:31 +02:00
--TEST--
Cursor Mode Test
--DESCRIPTION--
Verifies the functionality associated with scrollable resultsets.
--ENV--
PHPT_EXEC=true
--SKIPIF--
2017-10-27 18:32:57 +02:00
<?php require('skipif_versions_old.inc'); ?>
2017-05-04 01:00:31 +02:00
--FILE--
<?php
require_once('MsCommon.inc');
2017-05-04 01:00:31 +02:00
function cursorTest($noRows1, $noRows2)
2017-05-04 01:00:31 +02:00
{
$testName = "Statement - Cursor Mode";
startTest($testName);
2017-05-04 01:00:31 +02:00
setup();
$conn1 = AE\connect();
2017-05-04 01:00:31 +02:00
$tableName = 'TC39test';
2017-05-04 01:00:31 +02:00
$cursor = "";
for ($k = 0; $k < 4; $k++) {
switch ($k) {
2017-05-04 01:00:31 +02:00
case 0: $cursor = SQLSRV_CURSOR_FORWARD; break;
case 1: $cursor = SQLSRV_CURSOR_STATIC; break;
case 2: $cursor = SQLSRV_CURSOR_DYNAMIC; break;
case 3: $cursor = SQLSRV_CURSOR_KEYSET; break;
default: break;
2017-05-04 01:00:31 +02:00
}
scrollableFetch($conn1, $tableName, $noRows1, $noRows2, $cursor);
2017-05-04 01:00:31 +02:00
}
sqlsrv_close($conn1);
endTest($testName);
2017-05-04 01:00:31 +02:00
}
function scrollableFetch($conn, $tableName, $noRows1, $noRows2, $cursor)
2017-05-04 01:00:31 +02:00
{
$colIndex = "c27_timestamp";
$tableIndex = "TC39index";
2017-05-04 01:00:31 +02:00
AE\createTestTable($conn, $tableName);
createUniqueIndexEx($conn, $tableName, $tableIndex, $colIndex);
2017-05-04 01:00:31 +02:00
$stmt1 = AE\selectFromTable($conn, $tableName);
if (sqlsrv_has_rows($stmt1)) {
2017-05-04 01:00:31 +02:00
die("Table $tableName is expected to be empty...");
}
sqlsrv_free_stmt($stmt1);
$noRows = AE\insertTestRows($conn, $tableName, $noRows1);
2017-05-04 01:00:31 +02:00
$query = "SELECT * FROM [$tableName] ORDER BY $colIndex";
$options = array('Scrollable' => $cursor);
$stmt2 = sqlsrv_query($conn, $query, null, $options);
if (!sqlsrv_has_rows($stmt2)) {
2017-05-04 01:00:31 +02:00
die("Table $tableName is not expected to be empty...");
}
if (($cursor == SQLSRV_CURSOR_STATIC) ||
($cursor == SQLSRV_CURSOR_KEYSET)) {
2017-05-04 01:00:31 +02:00
$numRows = sqlsrv_num_rows($stmt2);
if ($numRows != $noRows) {
die("Unexpected row count for $cursor: $numRows instead of $noRows\n");
2017-05-04 01:00:31 +02:00
}
}
while (($noRows > 0) && sqlsrv_fetch($stmt2)) {
2017-05-04 01:00:31 +02:00
// consume the result set
$noRows--;
}
if ($noRows2 > 0) {
$extraRows = AE\insertTestRows($conn, $tableName, $noRows2);
if ($cursor == SQLSRV_CURSOR_DYNAMIC) {
2017-05-04 01:00:31 +02:00
$noRows += $extraRows;
}
}
while (sqlsrv_fetch($stmt2)) {
2017-05-04 01:00:31 +02:00
// consume the result set
$noRows--;
}
sqlsrv_free_stmt($stmt2);
if ($noRows != 0) {
die("Unexpected row count for $cursor: $noRows\n");
2017-05-04 01:00:31 +02:00
}
dropTable($conn, $tableName);
2017-05-04 01:00:31 +02:00
}
try {
cursorTest(10, 5);
} catch (Exception $e) {
echo $e->getMessage();
2017-05-04 01:00:31 +02:00
}
?>
--EXPECT--
Test "Statement - Cursor Mode" completed successfully.