cleanup test
[m6w6/ext-psi] / tests / sqlite / sqlite001.phpt
1 --TEST--
2 sqlite3
3 --INI--
4 psi.directory={PWD}:{PWD}/../../psi.d
5 --SKIPIF--
6 <?php
7 extension_loaded("psi") or printf("%s\n", "skip - need ext/psi");
8 function_exists("sqlite3\\open") or printf("%s\n", "skip - need libsqlite3");
9 ?>
10 --FILE--
11 ===TEST===
12 <?php
13
14 var_dump(sqlite3\version());
15
16 copy(__DIR__."/sqlite001.db", __DIR__."/sqlite001.tmp");
17
18 $rc = sqlite3\open(__DIR__."/sqlite001.tmp", $db);
19 if ($rc) {
20 printf("%s\n", sqlite3\errstr($rc));
21 }
22
23 function callback($context, int $argc, array $argv, array $cols) {
24 $context->row = $context->row ?? 0;
25
26 for ($i = 0; $i < $argc; ++$i) {
27 printf("%d: %s = %s\n", $context->row, $cols[$i], $argv[$i] ?? "<NULL>");
28 }
29 printf("\n");
30 ++$context->row;
31 }
32
33 $rc = sqlite3\exec($db, "SELECT * FROM test", "callback", new stdClass, $error);
34 if ($rc) {
35 printf("%s: '%s'\n", sqlite3\errstr($rc), $error);
36 }
37
38 $rc = sqlite3\exec($db, "INSERT INTO test VALUES (3,'three')", "callback", new stdClass, $error);
39 if ($rc) {
40 printf("%s: '%s'\n", sqlite3\errstr($rc), $error);
41 }
42
43 $rc = sqlite3\exec($db, "SELECT * FROM test", "callback", new stdClass, $error);
44 if ($rc) {
45 printf("%s: '%s'\n", sqlite3\errstr($rc), $error);
46 }
47
48 $rc = sqlite3\exec($db, "SELECT *", "callback", new stdClass, $error);
49 if ($rc) {
50 printf("%s: '%s'\n", sqlite3\errstr($rc), $error);
51 }
52
53 sqlite3\close($db);
54
55 $rc = sqlite3\exec($db, "SELECT *", "callback", new stdClass, $error);
56 if ($rc) {
57 printf("%s: '%s'\n", sqlite3\errstr($rc), $error);
58 }
59
60 ?>
61 ===DONE===
62 --EXPECTF--
63 ===TEST===
64 string(%d) "3.%d.%s"
65 0: id = 1
66 0: data = one
67
68 1: id = 2
69 1: data = two
70
71 0: id = 1
72 0: data = one
73
74 1: id = 2
75 1: data = two
76
77 2: id = 3
78 2: data = three
79
80 SQL logic error or missing database: 'no tables specified'
81 ===DONE===
82 --CLEAN--
83 <?php
84 @unlink(__DIR__."/sqlite001.tmp");
85 ?>