1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Tidy up pdo_mysql_attr_max_buffer_size.phpt

This commit is contained in:
Kamil Tekiela
2024-02-18 13:09:19 +01:00
parent d433035319
commit 50598a7097

View File

@@ -11,61 +11,52 @@ if (MySQLPDOTest::isPDOMySQLnd())
?>
--FILE--
<?php
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
function try_buffer_size($offset, $buffer_size) {
try {
$dsn = MySQLPDOTest::getDSN();
$user = PDO_MYSQL_TEST_USER;
$pass = PDO_MYSQL_TEST_PASS;
function try_buffer_size($offset, $buffer_size)
{
/* unsigned overflow possible ? */
$db = new PDO(MySQLPDOTest::getDSN(), PDO_MYSQL_TEST_USER, PDO_MYSQL_TEST_PASS, [
PDO::MYSQL_ATTR_MAX_BUFFER_SIZE => $buffer_size,
/* buffer is only relevant with native PS */
PDO::MYSQL_ATTR_DIRECT_QUERY => 0,
PDO::ATTR_EMULATE_PREPARES => 0,
]);
/* unsigned overflow possible ? */
$db = new PDO($dsn, $user, $pass,
array(
PDO::MYSQL_ATTR_MAX_BUFFER_SIZE => $buffer_size,
/* buffer is only relevant with native PS */
PDO::MYSQL_ATTR_DIRECT_QUERY => 0,
PDO::ATTR_EMULATE_PREPARES => 0,
));
$db->exec(sprintf('CREATE TABLE test_attr_max_buffer_size(id INT, val LONGBLOB) ENGINE = %s', PDO_MYSQL_TEST_ENGINE));
$db->exec(sprintf('CREATE TABLE test_attr_max_buffer_size(id INT, val LONGBLOB) ENGINE = %s', PDO_MYSQL_TEST_ENGINE));
// 10 * (10 * 1024) = 10 * (10 * 1k) = 100k
$db->exec('INSERT INTO test_attr_max_buffer_size(id, val) VALUES (1, REPEAT("01234567890", 10240))');
// 10 * (10 * 1024) = 10 * (10 * 1k) = 100k
$db->exec('INSERT INTO test_attr_max_buffer_size(id, val) VALUES (1, REPEAT("01234567890", 10240))');
$stmt = $db->prepare('SELECT id, val FROM test_attr_max_buffer_size');
$stmt->execute();
$stmt = $db->prepare('SELECT id, val FROM test_attr_max_buffer_size');
$stmt->execute();
$id = $val = NULL;
$stmt->bindColumn(1, $id);
$stmt->bindColumn(2, $val);
while ($row = $stmt->fetch(PDO::FETCH_BOUND)) {
printf("[%03d] id = %d, val = %s... (length: %d)\n",
$offset, $id, substr($val, 0, 10), strlen($val));
}
// This is necessary because we will be creating tables several times.
$db->query('DROP TABLE test_attr_max_buffer_size');
} catch (PDOException $e) {
printf("[%03d] %s, [%s] %s\n",
$offset,
$e->getMessage(),
(is_object($db)) ? $db->errorCode() : 'n/a',
(is_object($db)) ? implode(' ', $db->errorInfo()) : 'n/a');
}
$stmt->bindColumn(1, $id);
$stmt->bindColumn(2, $val);
while ($stmt->fetch(PDO::FETCH_BOUND)) {
printf(
"[%03d] id = %d, val = %s... (length: %d)\n",
$offset,
$id,
substr($val, 0, 10),
strlen($val)
);
}
try_buffer_size(1, -1);
try_buffer_size(2, 1000);
try_buffer_size(4, 2000);
try {
try_buffer_size(3, NULL);
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
// This is necessary because we will be creating tables several times.
$db->query('DROP TABLE test_attr_max_buffer_size');
}
print "done!";
try_buffer_size(1, -1);
try_buffer_size(2, 1000);
try_buffer_size(4, 2000);
try {
try_buffer_size(3, null);
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
print "done!";
?>
--CLEAN--
<?php