1--TEST--
2PDO_sqlite: Testing PDO_SQLITE_ATTR_EXTENDED_RESULT_CODES
3--SKIPIF--
4<?php if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; ?>
5--FILE--
6<?php
7
8echo "Creating new PDO" . PHP_EOL;
9$db = new PDO('sqlite::memory:');
10
11$db->exec("CREATE TABLE dog ( id INTEGER PRIMARY KEY, name TEXT, annoying INTEGER )");
12
13echo "Inserting first time which should succeed" . PHP_EOL;
14$db->exec("INSERT INTO dog VALUES (1, 'Annoying Dog', 1)");
15$errorInfo = $db->errorInfo();
16echo sprintf("First Error Info: SQLSTATE Error Code: (%s), Driver Specific Error Code: (%s)", $errorInfo[0], $errorInfo[1]) . PHP_EOL;
17
18echo "Inserting second time which should fail" . PHP_EOL;
19$result = $db->exec("INSERT INTO dog VALUES (1, 'Annoying Dog', 1)");
20$errorInfo = $db->errorInfo();
21echo sprintf("Second Error Info: SQLSTATE Error Code: (%s), Driver Specific Error Code: (%s)", $errorInfo[0], $errorInfo[1]) . PHP_EOL;
22
23
24echo "Creating new PDO with Extended Result Codes turned on" . PHP_EOL;
25$db = new PDO('sqlite::memory:', '', '', [PDO::SQLITE_ATTR_EXTENDED_RESULT_CODES => TRUE]);
26
27$db->exec("CREATE TABLE dog ( id INTEGER PRIMARY KEY, name TEXT, annoying INTEGER )");
28
29echo "Inserting first time which should succeed" . PHP_EOL;
30$result = $db->exec("INSERT INTO dog VALUES (1, 'Annoying Dog', 1)");
31$errorInfo = $db->errorInfo();
32echo sprintf("First (Extended) Error Info: SQLSTATE Error Code: (%s), Driver Specific Error Code: (%s)", $errorInfo[0], $errorInfo[1]) . PHP_EOL;
33
34echo "Inserting second time which should fail" . PHP_EOL;
35$result = $db->exec("INSERT INTO dog VALUES (1, 'Annoying Dog', 1)");
36$errorInfo = $db->errorInfo();
37echo sprintf("Second (Extended) Error Info: SQLSTATE Error Code: (%s), Driver Specific Error Code: (%s)", $errorInfo[0], $errorInfo[1]) . PHP_EOL;
38
39?>
40--EXPECT--
41Creating new PDO
42Inserting first time which should succeed
43First Error Info: SQLSTATE Error Code: (00000), Driver Specific Error Code: ()
44Inserting second time which should fail
45Second Error Info: SQLSTATE Error Code: (23000), Driver Specific Error Code: (19)
46Creating new PDO with Extended Result Codes turned on
47Inserting first time which should succeed
48First (Extended) Error Info: SQLSTATE Error Code: (00000), Driver Specific Error Code: ()
49Inserting second time which should fail
50Second (Extended) Error Info: SQLSTATE Error Code: (HY000), Driver Specific Error Code: (1555)
51