xref: /PHP-8.1/ext/pdo_pgsql/tests/bug48764.phpt (revision 39131219)
1--TEST--
2Bug #48764 (PDO_pgsql::query always uses implicit prepared statements if v3 proto available)
3--EXTENSIONS--
4pdo
5pdo_pgsql
6--SKIPIF--
7<?php
8require __DIR__ . '/config.inc';
9require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
10PDOTest::skip();
11
12$db = PDOTest::factory();
13
14$client_version = $db->getAttribute(PDO::ATTR_CLIENT_VERSION);
15$server_version = $db->getAttribute(PDO::ATTR_SERVER_VERSION);
16
17if (version_compare($server_version, '7.4', '<') || version_compare($client_version, '7.4', '<') || version_compare($server_version, '10', '>=')) {
18        die('skip');
19}
20
21?>
22--FILE--
23<?php
24require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
25$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
26$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
27
28echo "Test 1\n";
29bug($db);
30
31echo "Test 2\n";
32bug($db, array(PDO::ATTR_EMULATE_PREPARES => 0));
33bug($db, array(PDO::ATTR_EMULATE_PREPARES => 1));
34
35echo "Test 3\n";
36$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
37bug($db);
38$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
39bug($db);
40
41putenv('PDOTEST_ATTR='.serialize(array(
42    PDO::ATTR_EMULATE_PREPARES => 1,
43)));
44$db = PDOTest::factory('PDO', false);
45$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
46
47echo "Test 4\n";
48bug($db);
49bug($db, array(PDO::ATTR_EMULATE_PREPARES => 0));
50
51putenv('PDOTEST_ATTR');
52
53
54function bug($db, $options = array()) {
55    try {
56        $stmt = $db->prepare("SELECT ?", $options);
57        $stmt->execute(array(1));
58        echo "OK\n";
59    } catch (PDOException $e) {
60        // Indetermined data type when using native prepared statements
61        echo $e->getCode()."\n";
62    }
63}
64?>
65--EXPECT--
66Test 1
6742P18
68Test 2
6942P18
70OK
71Test 3
72OK
7342P18
74Test 4
75OK
7642P18
77