1--TEST--
2MySQL PDOStatement->nextRowSet()
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
8MySQLPDOTest::skip();
9$db = MySQLPDOTest::factory();
10$row = $db->query('SELECT VERSION() as _version')->fetch(PDO::FETCH_ASSOC);
11$matches = array();
12if (!preg_match('/^(\d+)\.(\d+)\.(\d+)/ismU', $row['_version'], $matches))
13    die(sprintf("skip Cannot determine MySQL Server version\n"));
14
15$version = $matches[1] * 10000 + $matches[2] * 100 + $matches[3];
16if ($version < 50000)
17    die(sprintf("skip Need MySQL Server 5.0.0+, found %d.%02d.%02d (%d)\n",
18        $matches[1], $matches[2], $matches[3], $version));
19
20if (!MySQLPDOTest::isPDOMySQLnd())
21    die("skip This will not work with libmysql");
22?>
23--FILE--
24<?php
25    require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
26    $db = MySQLPDOTest::factory();
27    $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
28
29    MySQLPDOTest::createTestTable($db);
30
31    $stmt = $db->query('SELECT id FROM test');
32    if (false !== ($tmp = $stmt->nextRowSet()))
33        printf("[002] Expecting false got %s\n", var_export($tmp, true));
34
35    function test_proc1($db) {
36
37        $stmt = $db->query('SELECT @VERSION as _version');
38        $tmp = $stmt->fetch(PDO::FETCH_ASSOC);
39        assert($tmp['_version'] === NULL);
40        while ($stmt->fetch()) ;
41
42        $db->exec('DROP PROCEDURE IF EXISTS p');
43        $db->exec('CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) BEGIN SELECT VERSION() INTO ver_param; END;');
44        $db->exec('CALL p(@VERSION)');
45        $stmt = $db->query('SELECT @VERSION as _version');
46        var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
47        var_dump($stmt->nextRowSet());
48
49    }
50
51    function test_proc2($db) {
52
53        $db->exec('DROP PROCEDURE IF EXISTS p');
54        $db->exec('CREATE PROCEDURE p() BEGIN SELECT id FROM test ORDER BY id ASC LIMIT 3; SELECT id, label FROM test WHERE id < 4 ORDER BY id DESC LIMIT 3; END;');
55        $stmt = $db->query('CALL p()');
56        do {
57            var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
58        } while ($stmt->nextRowSet());
59        var_dump($stmt->nextRowSet());
60
61        echo "Skip fetchAll(): ";
62        unset($stmt);
63        $stmt = $db->query('CALL p()');
64        var_dump($stmt->nextRowSet());
65        $stmt->closeCursor();
66    }
67
68    try {
69
70        // Emulated PS
71        printf("Emulated PS...\n");
72        $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
73
74        $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 1);
75        test_proc1($db);
76        test_proc2($db);
77
78        $db = MySQLPDOTest::factory();
79        $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
80        $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
81        $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 0);
82        test_proc1($db);
83        test_proc2($db);
84
85        // Native PS
86        printf("Native PS...\n");
87        $db = MySQLPDOTest::factory();
88        $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
89        $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 1);
90        $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
91        test_proc1($db);
92        test_proc2($db);
93
94        $db = MySQLPDOTest::factory();
95        $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
96        $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 0);
97        $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
98
99        test_proc1($db);
100        test_proc2($db);
101
102        @$db->exec('DROP PROCEDURE IF EXISTS p');
103
104    } catch (PDOException $e) {
105        printf("[001] %s [%s] %s\n",
106            $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
107    }
108
109    print "done!";
110?>
111--CLEAN--
112<?php
113require __DIR__ . '/mysql_pdo_test.inc';
114MySQLPDOTest::dropTestTable();
115?>
116--EXPECTF--
117Emulated PS...
118array(1) {
119  [0]=>
120  array(1) {
121    ["_version"]=>
122    string(%d) "%s"
123  }
124}
125bool(false)
126array(3) {
127  [0]=>
128  array(1) {
129    ["id"]=>
130    string(1) "1"
131  }
132  [1]=>
133  array(1) {
134    ["id"]=>
135    string(1) "2"
136  }
137  [2]=>
138  array(1) {
139    ["id"]=>
140    string(1) "3"
141  }
142}
143array(3) {
144  [0]=>
145  array(2) {
146    ["id"]=>
147    string(1) "3"
148    ["label"]=>
149    string(1) "c"
150  }
151  [1]=>
152  array(2) {
153    ["id"]=>
154    string(1) "2"
155    ["label"]=>
156    string(1) "b"
157  }
158  [2]=>
159  array(2) {
160    ["id"]=>
161    string(1) "1"
162    ["label"]=>
163    string(1) "a"
164  }
165}
166array(0) {
167}
168bool(false)
169Skip fetchAll(): bool(true)
170array(1) {
171  [0]=>
172  array(1) {
173    ["_version"]=>
174    string(%d) "%s"
175  }
176}
177bool(false)
178array(3) {
179  [0]=>
180  array(1) {
181    ["id"]=>
182    string(1) "1"
183  }
184  [1]=>
185  array(1) {
186    ["id"]=>
187    string(1) "2"
188  }
189  [2]=>
190  array(1) {
191    ["id"]=>
192    string(1) "3"
193  }
194}
195array(3) {
196  [0]=>
197  array(2) {
198    ["id"]=>
199    string(1) "3"
200    ["label"]=>
201    string(1) "c"
202  }
203  [1]=>
204  array(2) {
205    ["id"]=>
206    string(1) "2"
207    ["label"]=>
208    string(1) "b"
209  }
210  [2]=>
211  array(2) {
212    ["id"]=>
213    string(1) "1"
214    ["label"]=>
215    string(1) "a"
216  }
217}
218array(0) {
219}
220bool(false)
221Skip fetchAll(): bool(true)
222Native PS...
223array(1) {
224  [0]=>
225  array(1) {
226    ["_version"]=>
227    string(%d) "%s"
228  }
229}
230bool(false)
231array(3) {
232  [0]=>
233  array(1) {
234    ["id"]=>
235    string(1) "1"
236  }
237  [1]=>
238  array(1) {
239    ["id"]=>
240    string(1) "2"
241  }
242  [2]=>
243  array(1) {
244    ["id"]=>
245    string(1) "3"
246  }
247}
248array(3) {
249  [0]=>
250  array(2) {
251    ["id"]=>
252    string(1) "3"
253    ["label"]=>
254    string(1) "c"
255  }
256  [1]=>
257  array(2) {
258    ["id"]=>
259    string(1) "2"
260    ["label"]=>
261    string(1) "b"
262  }
263  [2]=>
264  array(2) {
265    ["id"]=>
266    string(1) "1"
267    ["label"]=>
268    string(1) "a"
269  }
270}
271array(0) {
272}
273bool(false)
274Skip fetchAll(): bool(true)
275array(1) {
276  [0]=>
277  array(1) {
278    ["_version"]=>
279    string(%d) "%s"
280  }
281}
282bool(false)
283array(3) {
284  [0]=>
285  array(1) {
286    ["id"]=>
287    string(1) "1"
288  }
289  [1]=>
290  array(1) {
291    ["id"]=>
292    string(1) "2"
293  }
294  [2]=>
295  array(1) {
296    ["id"]=>
297    string(1) "3"
298  }
299}
300array(3) {
301  [0]=>
302  array(2) {
303    ["id"]=>
304    string(1) "3"
305    ["label"]=>
306    string(1) "c"
307  }
308  [1]=>
309  array(2) {
310    ["id"]=>
311    string(1) "2"
312    ["label"]=>
313    string(1) "b"
314  }
315  [2]=>
316  array(2) {
317    ["id"]=>
318    string(1) "1"
319    ["label"]=>
320    string(1) "a"
321  }
322}
323array(0) {
324}
325bool(false)
326Skip fetchAll(): bool(true)
327done!
328