1--TEST--
2Pdo\Sqlite::blobOpen stream test
3--EXTENSIONS--
4pdo_sqlite
5--FILE--
6<?php
7
8$db = new Pdo\Sqlite('sqlite::memory:');
9
10require_once(__DIR__ . '/stream_test.inc');
11
12define('TIMENOW', time());
13
14echo "Creating Table\n";
15$db->exec('CREATE TABLE test (id STRING, data BLOB)');
16
17echo "PREPARING insert\n";
18$insert_stmt = $db->prepare("INSERT INTO test (id, data) VALUES (?, ?)");
19
20echo "BINDING Parameter\n";
21var_dump($insert_stmt->bindValue(1, 'a', PDO::PARAM_STR));
22var_dump($insert_stmt->bindValue(2, 'TEST TEST', PDO::PARAM_LOB));
23$insert_stmt->execute();
24echo "\n";
25
26$stream = $db->openBlob('test', 'data', 1);
27var_dump($stream);
28echo "Stream Contents\n";
29var_dump(stream_get_contents($stream));
30echo "Writing to read-only stream\n";
31var_dump(fwrite($stream, 'ABCD'));
32echo "Closing Stream\n";
33var_dump(fclose($stream));
34echo "Opening stream in write mode\n";
35$stream = $db->openBlob('test', 'data', 1, 'main', Pdo\Sqlite::OPEN_READWRITE);
36var_dump($stream);
37echo "Writing to blob\n";
38var_dump(fwrite($stream, 'ABCD'));
39echo "Stream Contents\n";
40fseek($stream, 0);
41var_dump(stream_get_contents($stream));
42echo "Expanding blob size\n";
43var_dump(fwrite($stream, 'ABCD ABCD ABCD'));
44echo "Closing Stream\n";
45var_dump(fclose($stream));
46
47echo "Done\n";
48?>
49--EXPECTF--
50Creating Table
51PREPARING insert
52BINDING Parameter
53bool(true)
54bool(true)
55
56resource(%d) of type (stream)
57Stream Contents
58string(9) "TEST TEST"
59Writing to read-only stream
60
61Warning: fwrite(): Can't write to blob stream: is open as read only in %s on line %d
62bool(false)
63Closing Stream
64bool(true)
65Opening stream in write mode
66resource(%d) of type (stream)
67Writing to blob
68int(4)
69Stream Contents
70string(9) "ABCD TEST"
71Expanding blob size
72
73Warning: fwrite(): It is not possible to increase the size of a BLOB in %s on line %d
74bool(false)
75Closing Stream
76bool(true)
77Done
78