a5e131674cd0ca2e072b795a732f8c0ef60ac4f1
[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 ?>
56 ===DONE===
57 --EXPECTF--
58 ===TEST===
59 string(%d) "3.%d.%s"
60 0: id = 1
61 0: data = one
62
63 1: id = 2
64 1: data = two
65
66 0: id = 1
67 0: data = one
68
69 1: id = 2
70 1: data = two
71
72 2: id = 3
73 2: data = three
74
75 SQL logic error or missing database: 'no tables specified'
76 ===DONE===
77 --CLEAN--
78 <?php
79 @unlink(__DIR__."/sqlite001.tmp");
80 ?>