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', '<')) { 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"; 34bug($db, array(PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT => 0)); 35bug($db, array(PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT => 1)); 36 37echo "Test 4\n"; 38$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1); 39bug($db); 40$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0); 41bug($db); 42 43echo "Test 5\n"; 44$db->setAttribute(PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT, 1); 45bug($db); 46$db->setAttribute(PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT, 0); 47bug($db); 48 49 50putenv('PDOTEST_ATTR='.serialize(array( 51 PDO::ATTR_EMULATE_PREPARES => 1, 52))); 53$db = PDOTest::factory('PDO', false); 54$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 55 56echo "Test 6\n"; 57bug($db); 58bug($db, array(PDO::ATTR_EMULATE_PREPARES => 0)); 59bug($db, array(PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT => 0)); 60 61 62putenv('PDOTEST_ATTR='.serialize(array( 63 PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT => 1, 64))); 65 66$db = PDOTest::factory('PDO', false); 67$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 68 69echo "Test 7\n"; 70bug($db); 71bug($db, array(PDO::ATTR_EMULATE_PREPARES => 0)); 72bug($db, array(PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT => 0)); 73 74 75putenv('PDOTEST_ATTR='.serialize(array( 76 PDO::ATTR_EMULATE_PREPARES => 1, 77 PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT => 1, 78))); 79 80$db = PDOTest::factory('PDO', false); 81$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 82 83echo "Test 8\n"; 84bug($db); 85bug($db, array(PDO::ATTR_EMULATE_PREPARES => 0)); 86bug($db, array(PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT => 0)); 87bug($db, array( 88 PDO::ATTR_EMULATE_PREPARES => 0, 89 PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT => 0, 90)); 91 92 93putenv('PDOTEST_ATTR'); 94 95 96function bug($db, $options = array()) { 97 try { 98 $stmt = $db->prepare("SELECT ?", $options); 99 $stmt->execute(array(1)); 100 echo "OK\n"; 101 } catch (PDOException $e) { 102 // Indetermined data type when using native prepared statements 103 echo $e->getCode()."\n"; 104 } 105} 106 107--EXPECTF-- 108Test 1 10942P18 110Test 2 11142P18 112OK 113Test 3 11442P18 115 116Deprecated: PDO::prepare(): PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT is deprecated, use PDO::ATTR_EMULATE_PREPARES instead in %s on line %d 117OK 118Test 4 119OK 12042P18 121Test 5 122 123Deprecated: PDO::setAttribute(): PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT is deprecated, use PDO::ATTR_EMULATE_PREPARES instead in %s on line %d 124 125Deprecated: PDO::prepare(): PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT is deprecated, use PDO::ATTR_EMULATE_PREPARES instead in %s on line %d 126OK 127 128Deprecated: PDO::setAttribute(): PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT is deprecated, use PDO::ATTR_EMULATE_PREPARES instead in %s on line %d 12942P18 130Test 6 131OK 13242P18 133OK 134 135Deprecated: PDO::__construct(): PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT is deprecated, use PDO::ATTR_EMULATE_PREPARES instead in %s on line %d 136Test 7 137 138Deprecated: PDO::prepare(): PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT is deprecated, use PDO::ATTR_EMULATE_PREPARES instead in %s on line %d 139OK 140 141Deprecated: PDO::prepare(): PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT is deprecated, use PDO::ATTR_EMULATE_PREPARES instead in %s on line %d 142OK 14342P18 144 145Deprecated: PDO::__construct(): PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT is deprecated, use PDO::ATTR_EMULATE_PREPARES instead in %s on line %d 146Test 8 147 148Deprecated: PDO::prepare(): PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT is deprecated, use PDO::ATTR_EMULATE_PREPARES instead in %s on line %d 149OK 150 151Deprecated: PDO::prepare(): PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT is deprecated, use PDO::ATTR_EMULATE_PREPARES instead in %s on line %d 152OK 153OK 15442P18 155