1--TEST--
2PgSQL PDO Parser custom syntax
3--EXTENSIONS--
4pdo
5pdo_pgsql
6--SKIPIF--
7<?php
8require __DIR__ . '/config.inc';
9require dirname(__DIR__, 2) . '/pdo/tests/pdo_test.inc';
10PDOTest::skip();
11?>
12--FILE--
13<?php
14require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
15$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
16$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
17
18$query = <<<'EOF'
19SELECT e'He''ll\'o? ' || ? AS b -- '
20UNION ALL
21SELECT 'He''ll''o?\' || ? AS b -- '
22UNION ALL
23SELECT U&'d\0061t\+000061? ' || ? AS b /* :name */
24UNION ALL
25SELECT $__$Is this a $$dollar$$ 'escaping'? $__$ || ? AS b -- ?
26UNION ALL
27SELECT $$Escaped question mark here?? $$ || ? AS b -- ?
28EOF;
29
30$stmt = $db->prepare($query);
31$stmt->execute(['World', 'World', 'base', 'Yes', 'Yes']);
32
33while ($row = $stmt->fetchColumn()) {
34    var_dump($row);
35}
36
37// Nested comments are incompatible: PDO parses the "?" inside the comment, Postgres doesn't
38$query = <<<'EOF'
39SELECT 'Hello' || ? /* is this a /* nested */ 'comment' ? */
40EOF;
41
42$stmt = $db->prepare($query);
43
44try {
45    $stmt->execute(['X', 'Y', 'Z']);
46} catch (PDOException $e) {
47    // PDO error: 3 parameters vs 2 expected
48    var_dump('HY093' === $e->getCode());
49}
50
51try {
52    $stmt->execute(['X', 'Y']);
53} catch (PDOException $e) {
54    // PgSQL error: Indeterminate datatype (1 extra parameter)
55    var_dump('42P18' === $e->getCode());
56}
57
58?>
59--EXPECTF--
60Deprecated: PDO::prepare(): Escaping question marks inside dollar quoted strings is not required anymore and is deprecated in %s on line %d
61string(14) "He'll'o? World"
62string(14) "He'll'o?\World"
63string(10) "data? base"
64string(36) "Is this a $$dollar$$ 'escaping'? Yes"
65string(31) "Escaped question mark here? Yes"
66bool(true)
67bool(true)
68