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

107 lines
2.8 KiB
Plaintext
Raw Normal View History

2017-05-04 01:00:31 +02:00
--TEST--
Stream Cancel Test
--DESCRIPTION--
Verifies that a stream is invalidated by:
- fetching next row
- cancelling or closing the statement
--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 CancelStream()
{
$testName = "Stream - Cancel";
startTest($testName);
2017-05-04 01:00:31 +02:00
setup();
$tableName = "TC53test";
$conn1 = AE\connect();
2017-05-04 01:00:31 +02:00
$noRows = 5;
AE\createTestTable($conn1, $tableName);
AE\insertTestRows($conn1, $tableName, $noRows);
2017-05-04 01:00:31 +02:00
$stmt1 = AE\selectFromTable($conn1, $tableName);
2017-05-04 01:00:31 +02:00
// Expired stream
$stream1 = getStream($stmt1);
2017-05-04 01:00:31 +02:00
sqlsrv_fetch($stmt1);
checkStream($stream1);
2017-05-04 01:00:31 +02:00
// Cancelled statement
$stream2 = getStream($stmt1);
2017-05-04 01:00:31 +02:00
sqlsrv_cancel($stmt1);
checkStream($stream2);
2017-05-04 01:00:31 +02:00
// Closed statement
$stmt2 = AE\selectFromTable($conn1, $tableName);
$stream3 = getStream($stmt2);
2017-05-04 01:00:31 +02:00
sqlsrv_free_stmt($stmt2);
checkStream($stream3);
dropTable($conn1, $tableName);
2017-05-04 01:00:31 +02:00
sqlsrv_close($conn1);
endTest($testName);
2017-05-04 01:00:31 +02:00
}
function getStream($stmt)
2017-05-04 01:00:31 +02:00
{
$stream = null;
if (!sqlsrv_fetch($stmt)) {
fatalError("Failed to fetch row ".$row);
2017-05-04 01:00:31 +02:00
}
while ($stream == null) {
2017-05-04 01:00:31 +02:00
$col = rand(11, 22); // select a streamable field
if (!isStreamable($col + 1)) {
2017-05-04 01:00:31 +02:00
die("Failed to select a streamable field.");
}
$type = getSqlType($col + 1);
trace("Selected streamable type: $type ...\n");
2017-05-04 01:00:31 +02:00
$stream = sqlsrv_get_field($stmt, $col, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY));
if ($stream === false) {
fatalError("Failed to read field $col: $type");
2017-05-04 01:00:31 +02:00
}
}
return ($stream);
}
function checkStream($stream)
2017-05-04 01:00:31 +02:00
{
$bytesRead = 0;
try {
2017-05-04 01:00:31 +02:00
$value = fread($stream, 8192);
$bytesRread = strlen($value);
} catch (Exception $e) {
2017-05-04 01:00:31 +02:00
$bytesRead = 0;
trace($e->getMessage());
2017-05-04 01:00:31 +02:00
}
if ($bytesRead > 0) {
2017-05-04 01:00:31 +02:00
die("Invalid stream should not return any data.");
}
}
try {
CancelStream();
} catch (Exception $e) {
echo $e->getMessage();
2017-05-04 01:00:31 +02:00
}
?>
--EXPECTREGEX--
|Warning: fread\(\): supplied argument is not a valid stream resource in .+\\TC53_StreamCancel.php on line 86|Warning: fread\(\): expects parameter 1 to be resource, null given in .+\\TC53_StreamCancel.php on line 84
2017-05-04 01:00:31 +02:00
|Warning: fread\(\): supplied argument is not a valid stream resource in .+\\TC53_StreamCancel.php on line 86|Warning: fread\(\): expects parameter 1 to be resource, null given in .+\\TC53_StreamCancel.php on line 84
2017-05-04 01:00:31 +02:00
|Warning: fread\(\): supplied argument is not a valid stream resource in .+\\TC53_StreamCancel.php on line 86|Warning: fread\(\): expects parameter 1 to be resource, null given in .+\\TC53_StreamCancel.php on line 84
2017-05-04 01:00:31 +02:00
Test "Stream - Cancel" completed successfully.