mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00

The php_stream_read() and php_stream_write() functions now return an ssize_t value, with negative results indicating failure. Functions like fread() and fwrite() will return false in that case. As a special case, EWOULDBLOCK and EAGAIN on non-blocking streams should not be regarded as error conditions, and be reported as successful zero-length reads/writes instead. The handling of EINTR remains unclear and is internally inconsistent (e.g. some code-paths will automatically retry on EINTR, while some won't). I'm landing this now to make sure the stream wrapper ops API changes make it into 7.4 -- however, if the user-facing changes turn out to be problematic we have the option of clamping negative returns to zero in php_stream_read() and php_stream_write() to restore the old behavior in a relatively non-intrusive manner.
80 lines
2 KiB
PHP
80 lines
2 KiB
PHP
--TEST--
|
|
SQLite3::blobOpen stream test
|
|
--SKIPIF--
|
|
<?php require_once(__DIR__ . '/skipif.inc'); ?>
|
|
--FILE--
|
|
<?php
|
|
|
|
require_once(__DIR__ . '/new_db.inc');
|
|
require_once(__DIR__ . '/stream_test.inc');
|
|
define('TIMENOW', time());
|
|
|
|
echo "Creating Table\n";
|
|
var_dump($db->exec('CREATE TABLE test (id STRING, data BLOB)'));
|
|
|
|
echo "PREPARING insert\n";
|
|
$insert_stmt = $db->prepare("INSERT INTO test (id, data) VALUES (?, ?)");
|
|
|
|
echo "BINDING Parameter\n";
|
|
var_dump($insert_stmt->bindValue(1, 'a', SQLITE3_TEXT));
|
|
var_dump($insert_stmt->bindValue(2, 'TEST TEST', SQLITE3_BLOB));
|
|
$insert_stmt->execute();
|
|
echo "Closing statement\n";
|
|
var_dump($insert_stmt->close());
|
|
$stream = $db->openBlob('test', 'data', 1);
|
|
var_dump($stream);
|
|
echo "Stream Contents\n";
|
|
var_dump(stream_get_contents($stream));
|
|
echo "Writing to read-only stream\n";
|
|
var_dump(fwrite($stream, 'ABCD'));
|
|
echo "Closing Stream\n";
|
|
var_dump(fclose($stream));
|
|
echo "Opening stream in write mode\n";
|
|
$stream = $db->openBlob('test', 'data', 1, 'main', SQLITE3_OPEN_READWRITE);
|
|
var_dump($stream);
|
|
echo "Writing to blob\n";
|
|
var_dump(fwrite($stream, 'ABCD'));
|
|
echo "Stream Contents\n";
|
|
fseek($stream, 0);
|
|
var_dump(stream_get_contents($stream));
|
|
echo "Expanding blob size\n";
|
|
var_dump(fwrite($stream, 'ABCD ABCD ABCD'));
|
|
echo "Closing Stream\n";
|
|
var_dump(fclose($stream));
|
|
echo "Closing database\n";
|
|
var_dump($db->close());
|
|
echo "Done\n";
|
|
?>
|
|
--EXPECTF--
|
|
Creating Table
|
|
bool(true)
|
|
PREPARING insert
|
|
BINDING Parameter
|
|
bool(true)
|
|
bool(true)
|
|
Closing statement
|
|
bool(true)
|
|
resource(%d) of type (stream)
|
|
Stream Contents
|
|
string(9) "TEST TEST"
|
|
Writing to read-only stream
|
|
|
|
Warning: fwrite(): Can't write to blob stream: is open as read only in %s on line %d
|
|
bool(false)
|
|
Closing Stream
|
|
bool(true)
|
|
Opening stream in write mode
|
|
resource(%d) of type (stream)
|
|
Writing to blob
|
|
int(4)
|
|
Stream Contents
|
|
string(9) "ABCD TEST"
|
|
Expanding blob size
|
|
|
|
Warning: fwrite(): It is not possible to increase the size of a BLOB in %s on line %d
|
|
bool(false)
|
|
Closing Stream
|
|
bool(true)
|
|
Closing database
|
|
bool(true)
|
|
Done
|