xref: /php-src/ext/pdo_pgsql/tests/bug68371.phpt (revision 6fb81d23)
1--TEST--
2PDO PgSQL Bug #38671 (PDO#getAttribute() cannot be called with platform-specific attribute names)
3--EXTENSIONS--
4pdo_pgsql
5--SKIPIF--
6<?php
7require __DIR__ . '/config.inc';
8require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
9PDOTest::skip();
10?>
11--FILE--
12<?php
13
14require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
15$pdo = PDOTest::test_factory(__DIR__ . '/common.phpt');
16$pdo->setAttribute (\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
17
18$attrs = array(
19    // Extensive test: default value and set+get values
20    PDO::ATTR_EMULATE_PREPARES			=> array(null, true, false),
21    PDO::PGSQL_ATTR_DISABLE_PREPARES	=> array(null, true, false),
22
23    // Just test the default
24    PDO::ATTR_AUTOCOMMIT			=> array(null),
25    PDO::ATTR_PREFETCH				=> array(null),
26    PDO::ATTR_TIMEOUT				=> array(null),
27    PDO::ATTR_ERRMODE				=> array(null),
28    PDO::ATTR_SERVER_VERSION		=> array(null),
29    PDO::ATTR_CLIENT_VERSION		=> array(null),
30    PDO::ATTR_SERVER_INFO			=> array(null),
31    PDO::ATTR_CONNECTION_STATUS		=> array(null),
32    PDO::ATTR_CASE					=> array(null),
33    PDO::ATTR_CURSOR_NAME			=> array(null),
34    PDO::ATTR_CURSOR				=> array(null),
35    PDO::ATTR_ORACLE_NULLS			=> array(null),
36    PDO::ATTR_PERSISTENT			=> array(null),
37    PDO::ATTR_STATEMENT_CLASS		=> array(null),
38    PDO::ATTR_FETCH_TABLE_NAMES		=> array(null),
39    PDO::ATTR_FETCH_CATALOG_NAMES	=> array(null),
40    PDO::ATTR_DRIVER_NAME			=> array(null),
41    PDO::ATTR_STRINGIFY_FETCHES		=> array(null),
42    PDO::ATTR_MAX_COLUMN_LEN		=> array(null),
43    PDO::ATTR_DEFAULT_FETCH_MODE	=> array(null),
44);
45
46foreach ($attrs as $a => $vals) {
47    foreach ($vals as $v) {
48        try {
49            if (!isset($v)) {
50                var_dump($pdo->getAttribute($a));
51            } else {
52                $pdo->setAttribute($a, $v);
53                if ($pdo->getAttribute($a) === $v) {
54                    echo "OK\n";
55                } else {
56                    throw new \Exception('KO');
57                }
58            }
59        } catch (\Exception $e) {
60            if ($e->getCode() == 'IM001') {
61                echo "ERR\n";
62            } else {
63                echo "ERR {$e->getMessage()}\n";
64            }
65        }
66    }
67}
68
69?>
70--EXPECTF--
71bool(false)
72OK
73OK
74bool(false)
75OK
76OK
77ERR
78ERR
79ERR
80int(2)
81string(%d) "%s"
82string(%d) "%s"
83string(%d) "%s"
84string(31) "%s"
85int(2)
86ERR
87ERR
88int(0)
89bool(false)
90array(1) {
91  [0]=>
92  string(12) "PDOStatement"
93}
94ERR
95ERR
96string(5) "pgsql"
97bool(true)
98ERR
99int(4)
100