2017-04-04 20:32:18 +02:00
|
|
|
|
--TEST--
|
2017-10-04 22:16:25 +02:00
|
|
|
|
Test with cursor scroll and select different rows in some random order
|
2017-05-02 21:00:53 +02:00
|
|
|
|
--SKIPIF--
|
2017-10-04 22:16:25 +02:00
|
|
|
|
<?php require('skipif_mid-refactor.inc'); ?>
|
2017-04-04 20:32:18 +02:00
|
|
|
|
--FILE--
|
|
|
|
|
<?php
|
2017-10-04 22:16:25 +02:00
|
|
|
|
require_once("MsCommon_mid-refactor.inc");
|
2017-04-04 20:32:18 +02:00
|
|
|
|
|
2017-10-04 22:16:25 +02:00
|
|
|
|
function cursorForwardOnly($conn, $tableName)
|
2017-04-04 20:32:18 +02:00
|
|
|
|
{
|
2017-10-04 22:16:25 +02:00
|
|
|
|
createTable($conn, $tableName, array("c1_int" => "int", "c2_tinyint" => "tinyint", "c3_smallint" => "smallint", "c4_bigint" => "bigint", "c5_bit" => "bit"));
|
2017-04-04 20:32:18 +02:00
|
|
|
|
|
|
|
|
|
// insert data
|
2017-10-04 22:16:25 +02:00
|
|
|
|
$numRows = insertData($conn, $tableName);
|
|
|
|
|
|
|
|
|
|
// select table
|
|
|
|
|
if (!isColEncrypted()) {
|
|
|
|
|
$stmt = $conn->prepare("SELECT * FROM $tableName ORDER BY c1_int", array( constant('PDO::ATTR_CURSOR') => PDO::CURSOR_FWDONLY ));
|
|
|
|
|
} else {
|
2017-09-28 18:48:08 +02:00
|
|
|
|
// ORDER BY is not supported for encrypted columns
|
2017-10-04 22:16:25 +02:00
|
|
|
|
$stmt = $conn->prepare("SELECT * FROM $tableName", array( constant('PDO::ATTR_CURSOR') => PDO::CURSOR_FWDONLY ));
|
|
|
|
|
}
|
2017-04-04 20:32:18 +02:00
|
|
|
|
$stmt->execute();
|
|
|
|
|
|
|
|
|
|
$numRowsFetched = 0;
|
2017-10-04 22:16:25 +02:00
|
|
|
|
while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
|
2017-04-04 20:32:18 +02:00
|
|
|
|
echo "$row[0]\n";
|
|
|
|
|
$numRowsFetched++;
|
|
|
|
|
}
|
2017-10-04 22:16:25 +02:00
|
|
|
|
|
|
|
|
|
if ($numRowsFetched != $numRows) {
|
2017-04-04 20:32:18 +02:00
|
|
|
|
echo "Number of rows fetched $numRowsFetched is wrong! Expected $numRows\n";
|
2017-10-04 22:16:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unset($stmt);
|
2017-04-04 20:32:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-04 22:16:25 +02:00
|
|
|
|
function cursorScrollFetchRows($conn, $tableName)
|
2017-04-04 20:32:18 +02:00
|
|
|
|
{
|
2017-10-04 22:16:25 +02:00
|
|
|
|
if (!isColEncrypted()) {
|
|
|
|
|
$stmt = $conn->prepare("SELECT * FROM $tableName ORDER BY c1_int", array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
|
|
|
|
|
} else {
|
2017-09-28 18:48:08 +02:00
|
|
|
|
// ORDER BY is not supported for encrypted columns
|
2018-01-19 00:35:13 +01:00
|
|
|
|
$stmt = $conn->prepare("SELECT * FROM $tableName", array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
|
2017-10-04 22:16:25 +02:00
|
|
|
|
}
|
2017-04-04 20:32:18 +02:00
|
|
|
|
$stmt->execute();
|
2017-10-04 22:16:25 +02:00
|
|
|
|
|
|
|
|
|
getFirstRow($stmt);
|
|
|
|
|
getNextRow($stmt);
|
|
|
|
|
getLastRow($stmt);
|
|
|
|
|
getPriorRow($stmt);
|
|
|
|
|
getAbsoluteRow($stmt, 7);
|
|
|
|
|
getAbsoluteRow($stmt, 2);
|
|
|
|
|
getRelativeRow($stmt, 3);
|
|
|
|
|
getPriorRow($stmt);
|
|
|
|
|
getRelativeRow($stmt, -4);
|
|
|
|
|
getAbsoluteRow($stmt, 0);
|
|
|
|
|
getNextRow($stmt);
|
|
|
|
|
getRelativeRow($stmt, 5);
|
|
|
|
|
getAbsoluteRow($stmt, -1);
|
|
|
|
|
getNextRow($stmt);
|
|
|
|
|
getLastRow($stmt);
|
|
|
|
|
getRelativeRow($stmt, 1);
|
|
|
|
|
|
|
|
|
|
unset($stmt);
|
2017-04-04 20:32:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-04 22:16:25 +02:00
|
|
|
|
function insertData($conn, $tableName)
|
2017-04-04 20:32:18 +02:00
|
|
|
|
{
|
|
|
|
|
$numRows = 0;
|
2017-10-04 22:16:25 +02:00
|
|
|
|
|
|
|
|
|
insertRow($conn, $tableName, array("c1_int" => 1, "c2_tinyint" => 0, "c3_smallint" => null, "c4_bigint" => 922337203685477, "c5_bit" => 0));
|
2017-09-28 18:48:08 +02:00
|
|
|
|
$numRows++;
|
2017-10-04 22:16:25 +02:00
|
|
|
|
|
|
|
|
|
insertRow($conn, $tableName, array("c1_int" => 2, "c2_tinyint" => null, "c3_smallint" => -32768, "c4_bigint" => 922337203685477, "c5_bit" => 0));
|
2017-09-28 18:48:08 +02:00
|
|
|
|
$numRows++;
|
2017-10-04 22:16:25 +02:00
|
|
|
|
|
|
|
|
|
insertRow($conn, $tableName, array("c1_int" => 3, "c2_tinyint" => 255, "c3_smallint" => -32768, "c4_bigint" => 1035941737, "c5_bit" => 0));
|
2017-09-28 18:48:08 +02:00
|
|
|
|
$numRows++;
|
2017-10-04 22:16:25 +02:00
|
|
|
|
|
|
|
|
|
insertRow($conn, $tableName, array("c1_int" => 4, "c2_tinyint" => null, "c3_smallint" => 4762, "c4_bigint" => 804325764, "c5_bit" => 0));
|
2017-09-28 18:48:08 +02:00
|
|
|
|
$numRows++;
|
2017-10-04 22:16:25 +02:00
|
|
|
|
|
|
|
|
|
insertRow($conn, $tableName, array("c1_int" => 5, "c2_tinyint" => 57, "c3_smallint" => 32767, "c4_bigint" => -922337203685477, "c5_bit" => 0));
|
2017-09-28 18:48:08 +02:00
|
|
|
|
$numRows++;
|
2017-10-04 22:16:25 +02:00
|
|
|
|
|
|
|
|
|
insertRow($conn, $tableName, array("c1_int" => 6, "c2_tinyint" => 201, "c3_smallint" => -32768, "c4_bigint" => 450619355, "c5_bit" => 0));
|
2017-09-28 18:48:08 +02:00
|
|
|
|
$numRows++;
|
2017-10-04 22:16:25 +02:00
|
|
|
|
|
|
|
|
|
insertRow($conn, $tableName, array("c1_int" => 7, "c2_tinyint" => 244, "c3_smallint" => -21244, "c4_bigint" => 981345728, "c5_bit" => 0));
|
2017-09-28 18:48:08 +02:00
|
|
|
|
$numRows++;
|
2017-10-04 22:16:25 +02:00
|
|
|
|
|
|
|
|
|
insertRow($conn, $tableName, array("c1_int" => 8, "c2_tinyint" => 143, "c3_smallint" => 0, "c4_bigint" => -1330405117, "c5_bit" => 0));
|
2017-09-28 18:48:08 +02:00
|
|
|
|
$numRows++;
|
2017-10-04 22:16:25 +02:00
|
|
|
|
|
|
|
|
|
insertRow($conn, $tableName, array("c1_int" => 9, "c2_tinyint" => null, "c3_smallint" => null, "c4_bigint" => 209123628, "c5_bit" => 0));
|
2017-09-28 18:48:08 +02:00
|
|
|
|
$numRows++;
|
2017-10-04 22:16:25 +02:00
|
|
|
|
|
|
|
|
|
insertRow($conn, $tableName, array("c1_int" => 10, "c2_tinyint" => 147, "c3_smallint" => 21133, "c4_bigint" => -1, "c5_bit" => 0));
|
2017-09-28 18:48:08 +02:00
|
|
|
|
$numRows++;
|
2017-10-04 22:16:25 +02:00
|
|
|
|
|
2017-04-04 20:32:18 +02:00
|
|
|
|
return $numRows;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-04 22:16:25 +02:00
|
|
|
|
function getFirstRow($stmt)
|
2017-04-04 20:32:18 +02:00
|
|
|
|
{
|
2017-10-04 22:16:25 +02:00
|
|
|
|
echo "first row: ";
|
|
|
|
|
$row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_FIRST, 0);
|
2017-04-04 20:32:18 +02:00
|
|
|
|
if ($row)
|
2017-10-04 22:16:25 +02:00
|
|
|
|
echo "$row[0]";
|
|
|
|
|
echo "\n";
|
2017-04-04 20:32:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-04 22:16:25 +02:00
|
|
|
|
function getNextRow($stmt)
|
2017-04-04 20:32:18 +02:00
|
|
|
|
{
|
2017-10-04 22:16:25 +02:00
|
|
|
|
echo "next row: ";
|
|
|
|
|
$row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT, 0);
|
2017-04-04 20:32:18 +02:00
|
|
|
|
if ($row)
|
2017-10-04 22:16:25 +02:00
|
|
|
|
echo "$row[0]";
|
|
|
|
|
echo "\n";
|
2017-04-04 20:32:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-04 22:16:25 +02:00
|
|
|
|
function getPriorRow($stmt)
|
2017-04-04 20:32:18 +02:00
|
|
|
|
{
|
2017-10-04 22:16:25 +02:00
|
|
|
|
echo "prior row: ";
|
|
|
|
|
$row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_PRIOR, 0);
|
2017-04-04 20:32:18 +02:00
|
|
|
|
if ($row)
|
2017-10-04 22:16:25 +02:00
|
|
|
|
echo "$row[0]";
|
|
|
|
|
echo "\n";
|
2017-04-04 20:32:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-04 22:16:25 +02:00
|
|
|
|
function getLastRow($stmt)
|
2017-04-04 20:32:18 +02:00
|
|
|
|
{
|
2017-10-04 22:16:25 +02:00
|
|
|
|
echo "last row: ";
|
|
|
|
|
$row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_LAST, 0);
|
2017-04-04 20:32:18 +02:00
|
|
|
|
if ($row)
|
2017-10-04 22:16:25 +02:00
|
|
|
|
echo "$row[0]";
|
|
|
|
|
echo "\n";
|
2017-04-04 20:32:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-04 22:16:25 +02:00
|
|
|
|
function getRelativeRow($stmt, $offset)
|
2017-04-04 20:32:18 +02:00
|
|
|
|
{
|
2017-10-04 22:16:25 +02:00
|
|
|
|
echo "row $offset from the current row: ";
|
|
|
|
|
$row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_REL, $offset);
|
2017-04-04 20:32:18 +02:00
|
|
|
|
if ($row)
|
2017-10-04 22:16:25 +02:00
|
|
|
|
echo "$row[0]";
|
|
|
|
|
echo "\n";
|
2017-04-04 20:32:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-04 22:16:25 +02:00
|
|
|
|
function getAbsoluteRow($stmt, $offset)
|
2017-04-04 20:32:18 +02:00
|
|
|
|
{
|
2017-10-04 22:16:25 +02:00
|
|
|
|
echo "absolute row with offset $offset: ";
|
|
|
|
|
$row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_ABS, $offset);
|
2017-04-04 20:32:18 +02:00
|
|
|
|
if ($row)
|
2017-10-04 22:16:25 +02:00
|
|
|
|
echo "$row[0]";
|
|
|
|
|
echo "\n";
|
2017-04-04 20:32:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
|
// RunTest
|
|
|
|
|
//
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
|
|
2017-09-28 18:48:08 +02:00
|
|
|
|
echo "Test begins...\n";
|
2017-10-04 22:16:25 +02:00
|
|
|
|
try {
|
|
|
|
|
// Connect
|
2017-09-28 18:48:08 +02:00
|
|
|
|
$conn = connect();
|
2017-10-04 22:16:25 +02:00
|
|
|
|
$tableName = getTableName();
|
2017-04-04 20:32:18 +02:00
|
|
|
|
|
2017-10-04 22:16:25 +02:00
|
|
|
|
cursorForwardOnly($conn, $tableName);
|
|
|
|
|
cursorScrollFetchRows($conn, $tableName);
|
|
|
|
|
|
|
|
|
|
dropTable($conn, $tableName);
|
|
|
|
|
unset($conn);
|
|
|
|
|
} catch (Exception $e) {
|
2017-09-28 18:48:08 +02:00
|
|
|
|
echo $e->getMessage();
|
|
|
|
|
}
|
|
|
|
|
echo "Done\n";
|
2017-04-04 20:32:18 +02:00
|
|
|
|
?>
|
|
|
|
|
--EXPECT--
|
2017-10-04 22:16:25 +02:00
|
|
|
|
Test begins...
|
2017-04-04 20:32:18 +02:00
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
|
|
first row: 1
|
|
|
|
|
next row: 2
|
|
|
|
|
last row: 10
|
|
|
|
|
prior row: 9
|
|
|
|
|
absolute row with offset 7: 8
|
|
|
|
|
absolute row with offset 2: 3
|
|
|
|
|
row 3 from the current row: 6
|
|
|
|
|
prior row: 5
|
|
|
|
|
row -4 from the current row: 1
|
|
|
|
|
absolute row with offset 0: 1
|
|
|
|
|
next row: 2
|
|
|
|
|
row 5 from the current row: 7
|
|
|
|
|
absolute row with offset -1:
|
|
|
|
|
next row: 1
|
|
|
|
|
last row: 10
|
|
|
|
|
row 1 from the current row:
|
2017-10-04 22:16:25 +02:00
|
|
|
|
Done
|