1--TEST--
2SQLite3::blobOpen test, testing stream with wrong parameter count
3--CREDITS--
4Michelangelo van Dam
5# Belgian PHP Testfest 2009
6--SKIPIF--
7<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
8--FILE--
9<?php
10class SQLite3_Test_Stream
11{
12	private $position;
13	public static $string_length = 10;
14	public static $string = "abcdefg\0hi";
15
16	public function stream_open($path, $mode, $options, &$opened_path)
17	{
18		$this->position = 0;
19		return true;
20	}
21
22	public function stream_read($count)
23	{
24		$ret = substr(self::$string, $this->position, $count);
25		$this->position += strlen($ret);
26		return $ret;
27	}
28
29	public function stream_write($data)
30	{
31		return 0;
32	}
33
34	public function stream_stat()
35	{
36		return array('size' => self::$string_length);
37	}
38
39	public function stream_tell()
40	{
41		return $this->position;
42	}
43
44	public function stream_eof()
45	{
46		return ($this->position >= self::$string_length);
47	}
48}
49
50$db = new SQLite3(':memory:');
51stream_wrapper_register('sqliteBlobTest', "SQLite3_Test_Stream") or die("Unable to register sqliteBlobTest stream");
52echo "Creating table: " . var_export($db->exec('CREATE TABLE test (id STRING, data BLOB)'),true) . "\n";
53
54echo "PREPARING insert\n";
55$insert_stmt = $db->prepare("INSERT INTO test (id, data) VALUES (?, ?)");
56
57echo "BINDING Parameters:\n";
58var_dump($insert_stmt->bindValue(1, 'a', SQLITE3_TEXT));
59var_dump($insert_stmt->bindValue(2, 'TEST TEST', SQLITE3_BLOB));
60$insert_stmt->execute();
61echo "Closing statement: " . var_export($insert_stmt->close(), true) . "\n";
62
63echo "Open BLOB with wrong parameter count\n";
64$stream = $db->openBlob();
65var_dump($stream);
66echo "Done\n";
67?>
68--EXPECTF--
69Creating table: true
70PREPARING insert
71BINDING Parameters:
72bool(true)
73bool(true)
74Closing statement: true
75Open BLOB with wrong parameter count
76
77Warning: SQLite3::openBlob() expects at least 3 parameters, 0 given in %s on line %d
78NULL
79Done
80