1--TEST--
2MySQL PDO->__construct(), PDO::MYSQL_ATTR_MAX_BUFFER_SIZE
3--SKIPIF--
4<?php
5require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
6require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7MySQLPDOTest::skip();
8if (MySQLPDOTest::isPDOMySQLnd())
9	die("skip PDO::MYSQL_ATTR_MAX_BUFFER_SIZE not supported with mysqlnd");
10?>
11--FILE--
12<?php
13	require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
14
15	function try_buffer_size($offset, $buffer_size) {
16
17		try {
18
19			$dsn = MySQLPDOTest::getDSN();
20			$user = PDO_MYSQL_TEST_USER;
21			$pass = PDO_MYSQL_TEST_PASS;
22
23			/* unsigned overflow possible ? */
24			$db = new PDO($dsn, $user, $pass,
25			array(
26				PDO::MYSQL_ATTR_MAX_BUFFER_SIZE => $buffer_size,
27				/* buffer is only relevant with native PS */
28				PDO::MYSQL_ATTR_DIRECT_QUERY => 0,
29				PDO::ATTR_EMULATE_PREPARES => 0,
30			));
31
32			$db->exec('DROP TABLE IF EXISTS test');
33			$db->exec(sprintf('CREATE TABLE test(id INT, val LONGBLOB) ENGINE = %s', PDO_MYSQL_TEST_ENGINE));
34
35			// 10 * (10 * 1024) = 10 * (10 * 1k) = 100k
36			$db->exec('INSERT INTO test(id, val) VALUES (1, REPEAT("01234567890", 10240))');
37
38			$stmt = $db->prepare('SELECT id, val FROM test');
39			$stmt->execute();
40
41			$id = $val = NULL;
42			$stmt->bindColumn(1, $id);
43			$stmt->bindColumn(2, $val);
44			while ($row = $stmt->fetch(PDO::FETCH_BOUND)) {
45				printf("[%03d] id = %d, val = %s... (length: %d)\n",
46					$offset, $id, substr($val, 0, 10), strlen($val));
47			}
48			$db->exec('DROP TABLE IF EXISTS test');
49
50		} catch (PDOException $e) {
51			printf("[%03d] %s, [%s] %s\n",
52				$offset,
53				$e->getMessage(),
54				(is_object($db)) ? $db->errorCode() : 'n/a',
55				(is_object($db)) ? implode(' ', $db->errorInfo()) : 'n/a');
56		}
57	}
58
59	try_buffer_size(1, -1);
60	try_buffer_size(2, 1000);
61	try_buffer_size(3, NULL);
62	try_buffer_size(4, 2000);
63
64	print "done!";
65?>
66--CLEAN--
67<?php
68require dirname(__FILE__) . '/mysql_pdo_test.inc';
69$db = MySQLPDOTest::factory();
70$db->exec('DROP TABLE IF EXISTS test');
71?>
72--EXPECTF--
73[001] id = 1, val = 0123456789... (length: %d)
74[002] id = 1, val = 0123456789... (length: 1000)
75[003] id = 1, val = 0123456789... (length: %d)
76[004] id = 1, val = 0123456789... (length: 2000)
77done!
78