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