Skip to content

[Tests] Optimized pdo_mysql tests #12751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Additional fixes
  • Loading branch information
SakiTakamachi committed Nov 24, 2023
commit db5b7daeaaddd42c048b49236ee98804a8ff85fd
1 change: 0 additions & 1 deletion ext/pdo_mysql/tests/bug53551.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ $createSql = "CREATE TABLE `bug53551` (
`count` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0'
)";

$db->exec('DROP TABLE IF EXISTS bug53551');
$db->exec($createSql);
$db->exec("INSERT INTO bug53551 SET `count` = 1 ");
$db->exec("SET sql_mode = 'Traditional'");
Expand Down
1 change: 0 additions & 1 deletion ext/pdo_mysql/tests/bug63185.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$procedure = 'test_procedure_error_at_second_63185';

$pdo->exec("DROP PROCEDURE IF EXISTS {$procedure}");
$pdo->exec("CREATE PROCEDURE {$procedure} ()
BEGIN
SELECT 'x' AS foo;
Expand Down
2 changes: 0 additions & 2 deletions ext/pdo_mysql/tests/bug76815.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$func = 'bug76815_pdo_mysql_f';
$procedure = 'bug76815_pdo_mysql_p';

$pdo->query("DROP FUNCTION IF EXISTS {$func}");
$pdo->query("DROP PROCEDURE IF EXISTS {$procedure}");
$pdo->query("CREATE FUNCTION {$func}() RETURNS VARCHAR(5) DETERMINISTIC BEGIN RETURN 'x12345'; END");
$pdo->query("CREATE PROCEDURE {$procedure}() BEGIN SELECT {$func}(); END");

Expand Down
1 change: 0 additions & 1 deletion ext/pdo_mysql/tests/bug_39858.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pdo_mysql
<?php
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
MySQLPDOTest::skip();
MySQLPDOTest::skipVersionThanLess(50000);
?>
--FILE--
<?php
Expand Down
1 change: 0 additions & 1 deletion ext/pdo_mysql/tests/bug_41125.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pdo_mysql
<?php
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
MySQLPDOTest::skip();
MySQLPDOTest::skipVersionThanLess(40100);
?>
--FILE--
<?php
Expand Down
2 changes: 0 additions & 2 deletions ext/pdo_mysql/tests/bug_41997.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pdo_mysql
<?php
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
MySQLPDOTest::skip();
MySQLPDOTest::skipVersionThanLess(50000);
?>
--FILE--
<?php
Expand All @@ -16,7 +15,6 @@ $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);

$procedure = 'bug_41997_pdo_mysql_p';

$db->exec("DROP PROCEDURE IF EXISTS {$procedure}");
$db->exec("CREATE PROCEDURE {$procedure}() BEGIN SELECT 1 AS 'one'; END");

$stmt = $db->query("CALL {$procedure}()");
Expand Down
1 change: 0 additions & 1 deletion ext/pdo_mysql/tests/bug_42499.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pdo_mysql
<?php
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
MySQLPDOTest::skip();
MySQLPDOTest::skipVersionThanLess(40100);
?>
--FILE--
<?php
Expand Down
1 change: 0 additions & 1 deletion ext/pdo_mysql/tests/bug_44707.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pdo_mysql
<?php
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
MySQLPDOTest::skip();
MySQLPDOTest::skipVersionThanLess(40100);
?>
--FILE--
<?php
Expand Down
2 changes: 1 addition & 1 deletion ext/pdo_mysql/tests/bug_50323.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ MySQLPDOTest::skip();
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
$db = MySQLPDOTest::factory();

@$db->exec('DROP DATABASE IF EXISTS `crazy;dbname`');
$db->exec('DROP DATABASE IF EXISTS `crazy;dbname`');
?>
--EXPECT--
done!
1 change: 0 additions & 1 deletion ext/pdo_mysql/tests/bug_61411.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pdo_mysql
<?php
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
MySQLPDOTest::skip();
MySQLPDOTest::skipVersionThanLess(40106);
?>
--FILE--
<?php
Expand Down
1 change: 0 additions & 1 deletion ext/pdo_mysql/tests/bug_pecl_7976.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pdo_mysql
<?php
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
MySQLPDOTest::skip();
MySQLPDOTest::skipVersionThanLess(50000);
?>
--FILE--
<?php
Expand Down
2 changes: 1 addition & 1 deletion ext/pdo_mysql/tests/inc/mysql_pdo_test.inc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
require_once __DIR__ . '/config.inc';
require_once __DIR__ . '/../../../../ext/pdo/tests/pdo_test.inc';
require_once dirname(__DIR__, 4) . '/ext/pdo/tests/pdo_test.inc';

foreach ($env as $k => $v) {
define($k, $v);
Expand Down
2 changes: 0 additions & 2 deletions ext/pdo_mysql/tests/pdo_mysql_attr_init_command.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ error_reporting=E_ALL

$table = 'pdo_mysql_attr_init_command';
$db = new PDO($dsn, $user, $pass);
$db->exec(sprintf('DROP TABLE IF EXISTS %s', $table));

$create = sprintf('CREATE TABLE %s(id INT)', $table);
var_dump($create);
Expand All @@ -33,7 +32,6 @@ error_reporting=E_ALL
$stmt = $db->query(sprintf('SELECT id FROM %s', $table));
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));

$db->exec(sprintf('DROP TABLE IF EXISTS %s', $table));
print "done!";
?>
--CLEAN--
Expand Down
2 changes: 1 addition & 1 deletion ext/pdo_mysql/tests/pdo_mysql_attr_multi_statements.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ error_reporting=E_ALL
$db = new PDO($dsn, $user, $pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
$db->exec(sprintf('DROP TABLE IF EXISTS %s', $table));

$create = sprintf('CREATE TABLE %s(id INT)', $table);
$db->exec($create);
$db->exec(sprintf('INSERT INTO %s(id) VALUES (1)', $table));
Expand Down
17 changes: 11 additions & 6 deletions ext/pdo_mysql/tests/pdo_mysql_attr_oracle_nulls.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ MySQLPDOTest::skip();
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
$db = MySQLPDOTest::factory();

$procedure = 'pdo_mysql_attr_oracle_nulls_p';

try {
$db->setAttribute(PDO::ATTR_ORACLE_NULLS, []);
} catch (\TypeError $e) {
Expand Down Expand Up @@ -47,10 +49,10 @@ MySQLPDOTest::skip();
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);

if ($have_procedures && (false !== $db->exec('DROP PROCEDURE IF EXISTS p')) &&
(false !== $db->exec("CREATE PROCEDURE p() BEGIN SELECT NULL as z, '' AS a, ' ' AS b, TRIM(' ') as c, ' d' AS d, ' e' AS e; END;"))) {
if ($have_procedures && (false !== $db->exec("DROP PROCEDURE IF EXISTS {$procedure}")) &&
(false !== $db->exec("CREATE PROCEDURE {$procedure}() BEGIN SELECT NULL as z, '' AS a, ' ' AS b, TRIM(' ') as c, ' d' AS d, ' e' AS e; END;"))) {
// requires MySQL 5+
$stmt = $db->prepare('CALL p()');
$stmt = $db->prepare("CALL {$procedure}()");
$stmt->execute();
do {
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
Expand All @@ -63,11 +65,14 @@ MySQLPDOTest::skip();

}

if ($have_procedures)
@$db->exec('DROP PROCEDURE IF EXISTS p');

print "done!";
?>
--CLEAN--
<?php
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
$db = MySQLPDOTest::factory();
$db->exec("DROP PROCEDURE IF EXISTS pdo_mysql_attr_oracle_nulls_p");
?>
--EXPECTF--
Attribute value must be of type int for selected attribute, array given
Attribute value must be of type int for selected attribute, stdClass given
Expand Down
1 change: 0 additions & 1 deletion ext/pdo_mysql/tests/pdo_mysql_commit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ MySQLPDOTest::skipNotTransactionalEngine();
}

// DDL will issue an implicit commit
$db->exec(sprintf('DROP TABLE IF EXISTS %s', $table2));
$db->exec(sprintf('CREATE TABLE %s (id INT) ENGINE=%s', $table2, MySQLPDOTest::detect_transactional_mysql_engine($db)));
try {
$db->commit();
Expand Down
21 changes: 13 additions & 8 deletions ext/pdo_mysql/tests/pdo_mysql_exec.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ MySQLPDOTest::skip();
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
$db = MySQLPDOTest::factory();

$procedure = 'pdo_mysql_exec_p';

/* affected rows related */
try {
exec_and_count(2, $db, 'DROP TABLE IF EXISTS test_mysql_exec', 0);
Expand Down Expand Up @@ -66,11 +68,11 @@ MySQLPDOTest::skip();
// let's try to play with stored procedures
try {
$ignore_exception = true;
exec_and_count(18, $db, 'DROP PROCEDURE IF EXISTS p', 0);
exec_and_count(19, $db, 'CREATE PROCEDURE p(OUT ver_param VARCHAR(255)) BEGIN SELECT VERSION() INTO ver_param; END;', 0);
exec_and_count(18, $db, "DROP PROCEDURE IF EXISTS {$procedure}", 0);
exec_and_count(19, $db, "CREATE PROCEDURE {$procedure}(OUT ver_param VARCHAR(255)) BEGIN SELECT VERSION() INTO ver_param; END;", 0);
// we got this far without problems. If there's an issue from now on, its a failure
$ignore_exception = false;
exec_and_count(20, $db, 'CALL p(@version)', 1);
exec_and_count(20, $db, "CALL {$procedure}(@version)", 1);
$stmt = $db->query('SELECT @version AS p_version');
$tmp = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (count($tmp) > 1 || !isset($tmp[0]['p_version'])) {
Expand All @@ -92,7 +94,7 @@ MySQLPDOTest::skip();
$tmp[0]['_version'], gettype($tmp[0]['_version']));
}
}
exec_and_count(25, $db, 'DROP PROCEDURE IF EXISTS p', 0);
exec_and_count(25, $db, "DROP PROCEDURE IF EXISTS {$procedure}", 0);

} catch (PDOException $e) {
// ignore it, we might not have sufficient permissions
Expand All @@ -103,13 +105,14 @@ MySQLPDOTest::skip();
}

// stored function
$func = 'pdo_mysql_exec_f';
try {
$ignore_exception = true;
exec_and_count(27, $db, 'DROP FUNCTION IF EXISTS f', 0);
exec_and_count(28, $db, 'CREATE FUNCTION f( ver_param VARCHAR(255)) RETURNS VARCHAR(255) DETERMINISTIC RETURN ver_param;', 0);
exec_and_count(27, $db, "DROP FUNCTION IF EXISTS {$func}", 0);
exec_and_count(28, $db, "CREATE FUNCTION {$func}( ver_param VARCHAR(255)) RETURNS VARCHAR(255) DETERMINISTIC RETURN ver_param;", 0);
// we got this far without problems. If there's an issue from now on, its a failure
$ignore_exception = false;
$stmt = $db->query('SELECT f(VERSION()) AS f_version');
$stmt = $db->query("SELECT {$func}(VERSION()) AS f_version");
$tmp = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (count($tmp) > 1 || !isset($tmp[0]['f_version'])) {
printf("[029] Data seems wrong, dumping\n");
Expand All @@ -129,7 +132,7 @@ MySQLPDOTest::skip();
$tmp[0]['_version'], gettype($tmp[0]['_version']));
}
}
exec_and_count(32, $db, 'DROP FUNCTION IF EXISTS f', 0);
exec_and_count(32, $db, "DROP FUNCTION IF EXISTS {$func}", 0);

} catch (PDOException $e) {
// ignore it, we might not have sufficient permissions
Expand Down Expand Up @@ -169,6 +172,8 @@ MySQLPDOTest::skip();
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
$db = MySQLPDOTest::factory();
$db->query('DROP TABLE IF EXISTS test_mysql_exec');
$db->query('DROP PROCEDURE IF EXISTS pdo_mysql_exec_p');
$db->query('DROP FUNCTION IF EXISTS pdo_mysql_exec_f');
?>
--EXPECTF--
Warning: PDO::exec(): SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near 'THIS IS NOT VALID SQL, I HOPE' at line 1 in %s on line %d
Expand Down
4 changes: 0 additions & 4 deletions ext/pdo_mysql/tests/pdo_mysql_exec_ddl.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,11 @@ MySQLPDOTest::skip();
$table2 = 'pdo_mysql_exec_ddl_2';
/* affected rows related */
try {
@$db->exec("DROP DATABASE IF EXISTS {$db_name}");
@$db->exec("DROP DATABASE IF EXISTS {$db_name_2}");
if (1 === @$db->exec("CREATE DATABASE {$db_name}")) {
// yippie - we can create databases etc.
exec_and_count(3, $db, "ALTER DATABASE {$db_name} CHARACTER SET latin1", 1);
}

exec_and_count(4, $db, "DROP TABLE IF EXISTS {$table}", 0);
exec_and_count(5, $db, "DROP TABLE IF EXISTS {$table2}", 0);
if (0 === $db->exec("CREATE TABLE {$table} (id INT, col1 CHAR(2))")) {
exec_and_count(5, $db, "CREATE INDEX idx1 ON {$table} (id)", 0);
exec_and_count(6, $db, "DROP INDEX idx1 ON {$table}", 0);
Expand Down
1 change: 0 additions & 1 deletion ext/pdo_mysql/tests/pdo_mysql_multi_stmt_nextrowset.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pdo_mysql
<?php
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
MySQLPDOTest::skip();
MySQLPDOTest::skipVersionThanLess(50000);
?>
--FILE--
<?php
Expand Down
1 change: 0 additions & 1 deletion ext/pdo_mysql/tests/pdo_mysql_rollback.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ MySQLPDOTest::skipNotTransactionalEngine();

$db->beginTransaction();
$db->query("INSERT INTO {$table}(id, label) VALUES (100, 'z')");
$db->query("DROP TABLE IF EXISTS {$table2}");
$db->query("CREATE TABLE {$table2}(id INT)");
$num++;
try {
Expand Down
1 change: 0 additions & 1 deletion ext/pdo_mysql/tests/pdo_mysql_stmt_getcolumnmeta.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pdo_mysql
<?php
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
MySQLPDOTest::skip();
MySQLPDOTest::skipVersionThanLess(50100);
?>
--FILE--
<?php
Expand Down
1 change: 0 additions & 1 deletion ext/pdo_mysql/tests/pdo_mysql_stmt_nextrowset.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pdo_mysql
<?php
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
MySQLPDOTest::skip();
MySQLPDOTest::skipVersionThanLess(50000);
MySQLPDOTest::skipNotMySQLnd();
?>
--FILE--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pdo_mysql
<?php
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
MySQLPDOTest::skip();
MySQLPDOTest::skipVersionThanLess(50000);
?>
--FILE--
<?php
Expand Down Expand Up @@ -39,7 +38,6 @@ MySQLPDOTest::skipVersionThanLess(50000);
try {
// What will happen if a PS returns a different number of result set column upon each execution?
// Lets try with a SP accepting parameters...
$db->exec("DROP PROCEDURE IF EXISTS {$procedure}");
$db->exec("CREATE PROCEDURE {$procedure}(IN cols INT) BEGIN IF cols < 2 THEN SELECT cols AS 'one'; ELSE SELECT 1 AS 'one', cols AS 'two'; END IF; END;");

// Emulates PS first
Expand Down
1 change: 0 additions & 1 deletion ext/pdo_mysql/tests/unsigned_bigint.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ require_once __DIR__ . '/inc/mysql_pdo_test.inc';
$pdo = MySQLPDOTest::factory();

$tbl = "unsigned_bigint_pdo_mysql";
$pdo->query("DROP TABLE IF EXISTS $tbl");
$pdo->query("CREATE TABLE $tbl (`ubigint` bigint unsigned NOT NULL) ENGINE=InnoDB");
$pdo->query("INSERT INTO $tbl (`ubigint`) VALUES (18446744073709551615)");
$pdo->query("INSERT INTO $tbl (`ubigint`) VALUES (9223372036854775808)");
Expand Down