1--TEST--
2MySQL PDO->__construct(), PDO::MYSQL_ATTR_MAX_BUFFER_SIZE
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once __DIR__ . '/inc/mysql_pdo_test.inc';
8MySQLPDOTest::skip();
9if (MySQLPDOTest::isPDOMySQLnd())
10    die("skip PDO::MYSQL_ATTR_MAX_BUFFER_SIZE not supported with mysqlnd");
11?>
12--FILE--
13<?php
14require_once __DIR__ . '/inc/mysql_pdo_test.inc';
15
16function try_buffer_size($offset, $buffer_size)
17{
18    /* unsigned overflow possible ? */
19    $db = new PDO(MySQLPDOTest::getDSN(), PDO_MYSQL_TEST_USER, PDO_MYSQL_TEST_PASS, [
20        PDO::MYSQL_ATTR_MAX_BUFFER_SIZE => $buffer_size,
21        /* buffer is only relevant with native PS */
22        PDO::MYSQL_ATTR_DIRECT_QUERY => 0,
23        PDO::ATTR_EMULATE_PREPARES => 0,
24    ]);
25
26    $db->exec(sprintf('CREATE TABLE test_attr_max_buffer_size(id INT, val LONGBLOB) ENGINE = %s', PDO_MYSQL_TEST_ENGINE));
27
28    // 10 * (10 * 1024) = 10 * (10 * 1k) = 100k
29    $db->exec('INSERT INTO test_attr_max_buffer_size(id, val) VALUES (1, REPEAT("01234567890", 10240))');
30
31    $stmt = $db->prepare('SELECT id, val FROM test_attr_max_buffer_size');
32    $stmt->execute();
33
34    $stmt->bindColumn(1, $id);
35    $stmt->bindColumn(2, $val);
36    while ($stmt->fetch(PDO::FETCH_BOUND)) {
37        printf(
38            "[%03d] id = %d, val = %s... (length: %d)\n",
39            $offset,
40            $id,
41            substr($val, 0, 10),
42            strlen($val)
43        );
44    }
45
46    // This is necessary because we will be creating tables several times.
47    $db->query('DROP TABLE test_attr_max_buffer_size');
48}
49
50try_buffer_size(1, -1);
51try_buffer_size(2, 1000);
52try_buffer_size(4, 2000);
53try {
54    try_buffer_size(3, null);
55} catch (TypeError $e) {
56    echo $e->getMessage(), "\n";
57}
58
59print "done!";
60?>
61--CLEAN--
62<?php
63require_once __DIR__ . '/inc/mysql_pdo_test.inc';
64$db = MySQLPDOTest::factory();
65$db->query('DROP TABLE IF EXISTS test_attr_max_buffer_size');
66?>
67--EXPECTF--
68[001] id = 1, val = 0123456789... (length: %d)
69[002] id = 1, val = 0123456789... (length: 1000)
70[004] id = 1, val = 0123456789... (length: 2000)
71Attribute value must be of type int for selected attribute, null given
72done!
73