1--TEST--
2SQLite3 enable Extended Error Result Codes
3--EXTENSIONS--
4sqlite3
5--FILE--
6<?php
7
8require_once(__DIR__ . '/new_db.inc');
9
10$db->query("CREATE TABLE dog ( id INTEGER PRIMARY KEY, name TEXT, annoying INTEGER )");
11
12echo "Inserting first time which should succeed" . PHP_EOL;
13$result = $db->query("INSERT INTO dog VALUES (1, 'Annoying Dog', 1)");
14echo "First Error Code: " . $db->lastErrorCode() . PHP_EOL;
15
16echo "Inserting second time which should fail" . PHP_EOL;
17$result = $db->query("INSERT INTO dog VALUES (1, 'Annoying Dog', 1)");
18echo "Second Error Code: " . $db->lastErrorCode() . PHP_EOL;
19
20echo "Toggling extended error codes and re-inserting a third time" . PHP_EOL;
21$db->enableExtendedResultCodes(true);
22$result = $db->query("INSERT INTO DOG VALUES (1, 'Annoying Dog', 1)");
23echo "Third (Extended) Error Code: " . $db->lastErrorCode() . PHP_EOL;
24
25echo "Closing database\n";
26var_dump($db->close());
27echo "Done" . PHP_EOL;
28?>
29--EXPECTF--
30Inserting first time which should succeed
31First Error Code: 0
32Inserting second time which should fail
33
34Warning: SQLite3::query(): Unable to execute statement: UNIQUE constraint failed: dog.id in %s on line %d
35Second Error Code: 19
36Toggling extended error codes and re-inserting a third time
37
38Warning: SQLite3::query(): Unable to execute statement: UNIQUE constraint failed: dog.id in %s on line %d
39Third (Extended) Error Code: 1555
40Closing database
41bool(true)
42Done
43
44