1--TEST--
2MySQL PDOStatement->nextRowSet()
3--XFAIL--
4nextRowset() problem with stored proc & emulation mode & mysqlnd
5--SKIPIF--
6<?php
7require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
8require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
9MySQLPDOTest::skip();
10$db = MySQLPDOTest::factory();
11$row = $db->query('SELECT VERSION() as _version')->fetch(PDO::FETCH_ASSOC);
12$matches = array();
13if (!preg_match('/^(\d+)\.(\d+)\.(\d+)/ismU', $row['_version'], $matches))
14	die(sprintf("skip Cannot determine MySQL Server version\n"));
15
16$version = $matches[0] * 10000 + $matches[1] * 100 + $matches[2];
17if ($version < 50000)
18	die(sprintf("skip Need MySQL Server 5.0.0+, found %d.%02d.%02d (%d)\n",
19		$matches[0], $matches[1], $matches[2], $version));
20
21if (!MySQLPDOTest::isPDOMySQLnd())
22	die("skip This will not work with libmysql");
23?>
24--FILE--
25<?php
26	require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
27	$db = MySQLPDOTest::factory();
28	$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
29
30	MySQLPDOTest::createTestTable($db);
31
32	$stmt = $db->query('SELECT id FROM test');
33	if (false !== ($tmp = $stmt->nextRowSet()))
34		printf("[002] Expecting false got %s\n", var_export($tmp, true));
35
36	// TODO: should give a warning, but its PDO, let's ignore the missing warning for now
37	if (false !== ($tmp = $stmt->nextRowSet(1)))
38		printf("[003] Expecting false got %s\n", var_export($tmp, true));
39
40	function test_proc1($db) {
41
42		$stmt = $db->query('SELECT @VERSION as _version');
43		$tmp = $stmt->fetch(PDO::FETCH_ASSOC);
44		assert($tmp['_version'] === NULL);
45		while ($stmt->fetch()) ;
46
47		$db->exec('DROP PROCEDURE IF EXISTS p');
48		$db->exec('CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) BEGIN SELECT VERSION() INTO ver_param; END;');
49		$db->exec('CALL p(@VERSION)');
50		$stmt = $db->query('SELECT @VERSION as _version');
51		var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
52		var_dump($stmt->nextRowSet());
53
54	}
55
56	function test_proc2($db) {
57
58		$db->exec('DROP PROCEDURE IF EXISTS p');
59		$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;');
60		$stmt = $db->query('CALL p()');
61		do {
62			var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
63		} while ($stmt->nextRowSet());
64		var_dump($stmt->nextRowSet());
65
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 dirname(__FILE__) . '/mysql_pdo_test.inc';
114MySQLPDOTest::dropTestTable();
115?>
116--EXPECTF--
117Emulated PS...
118array(1) {
119  [0]=>
120  array(1) {
121    [%u|b%"_version"]=>
122    %unicode|string%(%d) "%s"
123  }
124}
125bool(false)
126array(3) {
127  [0]=>
128  array(1) {
129    [%u|b%"id"]=>
130    %unicode|string%(1) "1"
131  }
132  [1]=>
133  array(1) {
134    [%u|b%"id"]=>
135    %unicode|string%(1) "2"
136  }
137  [2]=>
138  array(1) {
139    [%u|b%"id"]=>
140    %unicode|string%(1) "3"
141  }
142}
143array(3) {
144  [0]=>
145  array(2) {
146    [%u|b%"id"]=>
147    %unicode|string%(1) "3"
148    [%u|b%"label"]=>
149    %unicode|string%(1) "c"
150  }
151  [1]=>
152  array(2) {
153    [%u|b%"id"]=>
154    %unicode|string%(1) "2"
155    [%u|b%"label"]=>
156    %unicode|string%(1) "b"
157  }
158  [2]=>
159  array(2) {
160    [%u|b%"id"]=>
161    %unicode|string%(1) "1"
162    [%u|b%"label"]=>
163    %unicode|string%(1) "a"
164  }
165}
166bool(false)
167array(1) {
168  [0]=>
169  array(1) {
170    [%u|b%"_version"]=>
171    %unicode|string%(%d) "%s"
172  }
173}
174bool(false)
175array(3) {
176  [0]=>
177  array(1) {
178    [%u|b%"id"]=>
179    %unicode|string%(1) "1"
180  }
181  [1]=>
182  array(1) {
183    [%u|b%"id"]=>
184    %unicode|string%(1) "2"
185  }
186  [2]=>
187  array(1) {
188    [%u|b%"id"]=>
189    %unicode|string%(1) "3"
190  }
191}
192array(3) {
193  [0]=>
194  array(2) {
195    [%u|b%"id"]=>
196    %unicode|string%(1) "3"
197    [%u|b%"label"]=>
198    %unicode|string%(1) "c"
199  }
200  [1]=>
201  array(2) {
202    [%u|b%"id"]=>
203    %unicode|string%(1) "2"
204    [%u|b%"label"]=>
205    %unicode|string%(1) "b"
206  }
207  [2]=>
208  array(2) {
209    [%u|b%"id"]=>
210    %unicode|string%(1) "1"
211    [%u|b%"label"]=>
212    %unicode|string%(1) "a"
213  }
214}
215bool(false)
216Native PS...
217array(1) {
218  [0]=>
219  array(1) {
220    [%u|b%"_version"]=>
221    %unicode|string%(%d) "%s"
222  }
223}
224bool(false)
225array(3) {
226  [0]=>
227  array(1) {
228    [%u|b%"id"]=>
229    %unicode|string%(1) "1"
230  }
231  [1]=>
232  array(1) {
233    [%u|b%"id"]=>
234    %unicode|string%(1) "2"
235  }
236  [2]=>
237  array(1) {
238    [%u|b%"id"]=>
239    %unicode|string%(1) "3"
240  }
241}
242array(3) {
243  [0]=>
244  array(2) {
245    [%u|b%"id"]=>
246    %unicode|string%(1) "3"
247    [%u|b%"label"]=>
248    %unicode|string%(1) "c"
249  }
250  [1]=>
251  array(2) {
252    [%u|b%"id"]=>
253    %unicode|string%(1) "2"
254    [%u|b%"label"]=>
255    %unicode|string%(1) "b"
256  }
257  [2]=>
258  array(2) {
259    [%u|b%"id"]=>
260    %unicode|string%(1) "1"
261    [%u|b%"label"]=>
262    %unicode|string%(1) "a"
263  }
264}
265bool(false)
266array(1) {
267  [0]=>
268  array(1) {
269    [%u|b%"_version"]=>
270    %unicode|string%(%d) "%s"
271  }
272}
273bool(false)
274array(3) {
275  [0]=>
276  array(1) {
277    [%u|b%"id"]=>
278    %unicode|string%(1) "1"
279  }
280  [1]=>
281  array(1) {
282    [%u|b%"id"]=>
283    %unicode|string%(1) "2"
284  }
285  [2]=>
286  array(1) {
287    [%u|b%"id"]=>
288    %unicode|string%(1) "3"
289  }
290}
291array(3) {
292  [0]=>
293  array(2) {
294    [%u|b%"id"]=>
295    %unicode|string%(1) "3"
296    [%u|b%"label"]=>
297    %unicode|string%(1) "c"
298  }
299  [1]=>
300  array(2) {
301    [%u|b%"id"]=>
302    %unicode|string%(1) "2"
303    [%u|b%"label"]=>
304    %unicode|string%(1) "b"
305  }
306  [2]=>
307  array(2) {
308    [%u|b%"id"]=>
309    %unicode|string%(1) "1"
310    [%u|b%"label"]=>
311    %unicode|string%(1) "a"
312  }
313}
314bool(false)
315done!
316