xref: /php-src/ext/pdo/tests/bug_44861.phpt (revision c1fec9bb)
1--TEST--
2PDO Common: Bug #44861 (scrollable cursor don't work with pgsql)
3--EXTENSIONS--
4pdo
5--SKIPIF--
6<?php
7$dir = getenv('REDIR_TEST_DIR');
8if (false == $dir) die('skip no driver');
9$allowed = array('oci', 'pgsql');
10$ok = false;
11foreach ($allowed as $driver) {
12    if (!strncasecmp(getenv('PDOTEST_DSN'), $driver, strlen($driver))) {
13        $ok = true;
14    }
15}
16if (!$ok) {
17    die("skip Scrollable cursors not supported");
18}
19require_once $dir . 'pdo_test.inc';
20PDOTest::skip();
21?>
22--FILE--
23<?php
24if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
25require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
26$db = PDOTest::factory();
27
28$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
29
30switch ($db->getAttribute(PDO::ATTR_DRIVER_NAME)) {
31    case 'oci':
32        $from = 'FROM DUAL';
33        $ob = '1';
34        break;
35    case 'firebird':
36        $from = 'FROM RDB$DATABASE';
37        $ob = 'r';
38        break;
39    default:
40        $from = '';
41        $ob = 'r';
42        break;
43}
44
45$query = "SELECT 'row1' AS r $from UNION SELECT 'row2' $from UNION SELECT 'row3' $from UNION SELECT 'row4' $from ORDER BY $ob";
46$aParams = array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL);
47
48$res = $db->prepare($query, $aParams);
49$res->execute();
50var_dump($res->fetchColumn());
51var_dump($res->fetchColumn());
52var_dump($res->fetchColumn());
53var_dump($res->fetchColumn());
54var_dump($res->fetchColumn());
55
56var_dump($res->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_ABS, 3));
57var_dump($res->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_PRIOR));
58var_dump($res->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_FIRST));
59var_dump($res->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_LAST));
60var_dump($res->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_REL, -1));
61
62var_dump($res->fetchAll(PDO::FETCH_ASSOC));
63
64// Test binding params via emulated prepared query
65$res = $db->prepare("SELECT ? $from", $aParams);
66$res->execute(array("it's working"));
67var_dump($res->fetch(PDO::FETCH_NUM));
68
69
70// Test bug #48188, trying to execute again
71$res->execute(array("try again"));
72var_dump($res->fetchColumn());
73var_dump($res->fetchColumn());
74
75?>
76--EXPECT--
77string(4) "row1"
78string(4) "row2"
79string(4) "row3"
80string(4) "row4"
81bool(false)
82array(1) {
83  [0]=>
84  string(4) "row3"
85}
86array(1) {
87  [0]=>
88  string(4) "row2"
89}
90array(1) {
91  [0]=>
92  string(4) "row1"
93}
94array(1) {
95  [0]=>
96  string(4) "row4"
97}
98array(1) {
99  [0]=>
100  string(4) "row3"
101}
102array(1) {
103  [0]=>
104  array(1) {
105    ["r"]=>
106    string(4) "row4"
107  }
108}
109array(1) {
110  [0]=>
111  string(12) "it's working"
112}
113string(9) "try again"
114bool(false)
115