PDO MySQL: Fix libmysql option test

The fact that getAttribute() fails for various libmysqlclient-only
options is a known issue, and the test was taking that into account.
However, the change of the default error mode broke the handling.
We need to handle the exceptions now.
This commit is contained in:
Nikita Popov 2020-12-11 12:04:44 +01:00
parent 43741a3f26
commit 4e51059d52

View File

@ -27,57 +27,52 @@ if (MySQLPDOTest::isPDOMySQLnd())
$tmp, gettype($tmp),
$option_desc);
} catch (PDOException $e) {
printf("[%03d] %s\n", $offset, $e->getMessage());
echo "Failed to getAttribute() for $option_desc\n";
}
}
try {
$dsn = MySQLPDOTest::getDSN();
$user = PDO_MYSQL_TEST_USER;
$pass = PDO_MYSQL_TEST_PASS;
$dsn = MySQLPDOTest::getDSN();
$user = PDO_MYSQL_TEST_USER;
$pass = PDO_MYSQL_TEST_PASS;
$valid_options = array();
$valid_options[PDO::MYSQL_ATTR_MAX_BUFFER_SIZE] = 'PDO::MYSQL_ATTR_MAX_BUFFER_SIZE';
$valid_options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'PDO::MYSQL_ATTR_INIT_COMMAND';
$valid_options[PDO::MYSQL_ATTR_READ_DEFAULT_FILE] = 'PDO::MYSQL_ATTR_READ_DEFAULT_FILE';
$valid_options[PDO::MYSQL_ATTR_READ_DEFAULT_GROUP] = 'PDO::MYSQL_ATTR_READ_DEFAULT_GROUP';
$valid_options = array();
$valid_options[PDO::MYSQL_ATTR_MAX_BUFFER_SIZE] = 'PDO::MYSQL_ATTR_MAX_BUFFER_SIZE';
$valid_options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'PDO::MYSQL_ATTR_INIT_COMMAND';
$valid_options[PDO::MYSQL_ATTR_READ_DEFAULT_FILE] = 'PDO::MYSQL_ATTR_READ_DEFAULT_FILE';
$valid_options[PDO::MYSQL_ATTR_READ_DEFAULT_GROUP] = 'PDO::MYSQL_ATTR_READ_DEFAULT_GROUP';
$defaults[PDO::MYSQL_ATTR_MAX_BUFFER_SIZE] = 1048576;
/* TODO getAttribute() does not handle it */
$defaults[PDO::MYSQL_ATTR_INIT_COMMAND] = '';
$defaults[PDO::MYSQL_ATTR_READ_DEFAULT_FILE] = false;
$defaults[PDO::MYSQL_ATTR_READ_DEFAULT_GROUP] = false;
$defaults[PDO::MYSQL_ATTR_MAX_BUFFER_SIZE] = 1048576;
/* TODO getAttribute() does not handle it */
$defaults[PDO::MYSQL_ATTR_INIT_COMMAND] = '';
$defaults[PDO::MYSQL_ATTR_READ_DEFAULT_FILE] = false;
$defaults[PDO::MYSQL_ATTR_READ_DEFAULT_GROUP] = false;
$db = new PDO($dsn, $user, $pass);
foreach ($valid_options as $option => $name) {
/* TODO getAttribute() is pretty poor in supporting the options, suppress errors */
$tmp = @$db->getAttribute($option);
$db = new PDO($dsn, $user, $pass);
foreach ($valid_options as $option => $name) {
try {
$tmp = $db->getAttribute($option);
if ($tmp !== $defaults[$option])
printf("[001] Expecting default value for '%s' of '%s'/%s, getAttribute() reports setting '%s'/%s\n",
$name, $defaults[$option], gettype($defaults[$option]),
$tmp, gettype($tmp));
} catch (PDOException $e) {
echo "Failed to getAttribute() for $name\n";
}
set_option_and_check(26, PDO::MYSQL_ATTR_READ_DEFAULT_FILE, true, 'PDO::MYSQL_ATTR_READ_DEFAULT_FILE');
set_option_and_check(27, PDO::MYSQL_ATTR_READ_DEFAULT_FILE, false, 'PDO::MYSQL_ATTR_READ_DEFAULT_FILE');
set_option_and_check(30, PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, -1, 'PDO::MYSQL_ATTR_MAX_BUFFER_SIZE', true);
set_option_and_check(31, PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, PHP_INT_MAX, 'PDO::MYSQL_ATTR_MAX_BUFFER_SIZE');
set_option_and_check(32, PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, 1, 'PDO::MYSQL_ATTR_MAX_BUFFER_SIZE');
} catch (PDOException $e) {
printf("[001] %s, [%s] %s\n",
$e->getMessage(),
(is_object($db)) ? $db->errorCode() : 'n/a',
(is_object($db)) ? implode(' ', $db->errorInfo()) : 'n/a');
}
print "done!";
set_option_and_check(26, PDO::MYSQL_ATTR_READ_DEFAULT_FILE, true, 'PDO::MYSQL_ATTR_READ_DEFAULT_FILE');
set_option_and_check(27, PDO::MYSQL_ATTR_READ_DEFAULT_FILE, false, 'PDO::MYSQL_ATTR_READ_DEFAULT_FILE');
set_option_and_check(30, PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, -1, 'PDO::MYSQL_ATTR_MAX_BUFFER_SIZE', true);
set_option_and_check(31, PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, PHP_INT_MAX, 'PDO::MYSQL_ATTR_MAX_BUFFER_SIZE');
set_option_and_check(32, PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, 1, 'PDO::MYSQL_ATTR_MAX_BUFFER_SIZE');
print "done!\n";
?>
--EXPECT--
[001] Expecting default value for 'PDO::MYSQL_ATTR_INIT_COMMAND' of ''/string, getAttribute() reports setting ''/boolean
[026] Expecting '1'/boolean got ''/boolean' for options 'PDO::MYSQL_ATTR_READ_DEFAULT_FILE'
Failed to getAttribute() for PDO::MYSQL_ATTR_INIT_COMMAND
Failed to getAttribute() for PDO::MYSQL_ATTR_READ_DEFAULT_FILE
Failed to getAttribute() for PDO::MYSQL_ATTR_READ_DEFAULT_GROUP
Failed to getAttribute() for PDO::MYSQL_ATTR_READ_DEFAULT_FILE
Failed to getAttribute() for PDO::MYSQL_ATTR_READ_DEFAULT_FILE
done!