Skip to content

Commit 50598a7

Browse files
committed
Tidy up pdo_mysql_attr_max_buffer_size.phpt
1 parent d433035 commit 50598a7

File tree

1 file changed

+38
-47
lines changed

1 file changed

+38
-47
lines changed

ext/pdo_mysql/tests/pdo_mysql_attr_max_buffer_size.phpt

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,61 +11,52 @@ if (MySQLPDOTest::isPDOMySQLnd())
1111
?>
1212
--FILE--
1313
<?php
14-
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
15-
16-
function try_buffer_size($offset, $buffer_size) {
17-
try {
18-
$dsn = MySQLPDOTest::getDSN();
19-
$user = PDO_MYSQL_TEST_USER;
20-
$pass = PDO_MYSQL_TEST_PASS;
21-
22-
/* unsigned overflow possible ? */
23-
$db = new PDO($dsn, $user, $pass,
24-
array(
25-
PDO::MYSQL_ATTR_MAX_BUFFER_SIZE => $buffer_size,
26-
/* buffer is only relevant with native PS */
27-
PDO::MYSQL_ATTR_DIRECT_QUERY => 0,
28-
PDO::ATTR_EMULATE_PREPARES => 0,
29-
));
30-
31-
$db->exec(sprintf('CREATE TABLE test_attr_max_buffer_size(id INT, val LONGBLOB) ENGINE = %s', PDO_MYSQL_TEST_ENGINE));
14+
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
3215

33-
// 10 * (10 * 1024) = 10 * (10 * 1k) = 100k
34-
$db->exec('INSERT INTO test_attr_max_buffer_size(id, val) VALUES (1, REPEAT("01234567890", 10240))');
16+
function 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+
]);
3525

36-
$stmt = $db->prepare('SELECT id, val FROM test_attr_max_buffer_size');
37-
$stmt->execute();
26+
$db->exec(sprintf('CREATE TABLE test_attr_max_buffer_size(id INT, val LONGBLOB) ENGINE = %s', PDO_MYSQL_TEST_ENGINE));
3827

39-
$id = $val = NULL;
40-
$stmt->bindColumn(1, $id);
41-
$stmt->bindColumn(2, $val);
42-
while ($row = $stmt->fetch(PDO::FETCH_BOUND)) {
43-
printf("[%03d] id = %d, val = %s... (length: %d)\n",
44-
$offset, $id, substr($val, 0, 10), strlen($val));
45-
}
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))');
4630

47-
// This is necessary because we will be creating tables several times.
48-
$db->query('DROP TABLE test_attr_max_buffer_size');
31+
$stmt = $db->prepare('SELECT id, val FROM test_attr_max_buffer_size');
32+
$stmt->execute();
4933

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-
}
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+
);
5744
}
5845

59-
try_buffer_size(1, -1);
60-
try_buffer_size(2, 1000);
61-
try_buffer_size(4, 2000);
62-
try {
63-
try_buffer_size(3, NULL);
64-
} catch (TypeError $e) {
65-
echo $e->getMessage(), "\n";
66-
}
46+
// This is necessary because we will be creating tables several times.
47+
$db->query('DROP TABLE test_attr_max_buffer_size');
48+
}
49+
50+
try_buffer_size(1, -1);
51+
try_buffer_size(2, 1000);
52+
try_buffer_size(4, 2000);
53+
try {
54+
try_buffer_size(3, null);
55+
} catch (TypeError $e) {
56+
echo $e->getMessage(), "\n";
57+
}
6758

68-
print "done!";
59+
print "done!";
6960
?>
7061
--CLEAN--
7162
<?php

0 commit comments

Comments
 (0)