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