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 all commits
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
4 changes: 2 additions & 2 deletions ext/pdo/tests/pdo_017.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ try {
}

if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') {
require_once(__DIR__ . DIRECTORY_SEPARATOR . '../../pdo_mysql/tests/mysql_pdo_test.inc');
require_once(__DIR__ . DIRECTORY_SEPARATOR . '../../pdo_mysql/tests/inc/mysql_pdo_test.inc');
if (false === MySQLPDOTest::detect_transactional_mysql_engine($db)) {
die('skip your mysql configuration does not support working transactions');
}
Expand All @@ -32,7 +32,7 @@ require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
$db = PDOTest::factory();

if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') {
require_once(__DIR__ . DIRECTORY_SEPARATOR . '../../pdo_mysql/tests/mysql_pdo_test.inc');
require_once(__DIR__ . DIRECTORY_SEPARATOR . '../../pdo_mysql/tests/inc/mysql_pdo_test.inc');
$suf = ' ENGINE=' . MySQLPDOTest::detect_transactional_mysql_engine($db);
} else {
$suf = '';
Expand Down
9 changes: 3 additions & 6 deletions ext/pdo_mysql/tests/bug41125.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ Bug #41125 (PDO mysql + quote() + prepare() can result in seg fault)
pdo_mysql
--SKIPIF--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
MySQLPDOTest::skip();

?>
--FILE--
<?php

require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');

$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
$db = MySQLPDOTest::factory();

$search = "o'";
$sql = "SELECT 1 FROM DUAL WHERE 'o''riley' LIKE " . $db->quote('%' . $search . '%');
Expand Down
8 changes: 3 additions & 5 deletions ext/pdo_mysql/tests/bug44327.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ Bug #44327 (PDORow::queryString property & numeric offsets / Crash)
pdo_mysql
--SKIPIF--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
MySQLPDOTest::skip();
$db = MySQLPDOTest::factory();
?>
--FILE--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
$db = MySQLPDOTest::factory();
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);

Expand Down Expand Up @@ -38,11 +37,10 @@ $db = MySQLPDOTest::factory();
@$stmt->execute();
$row = $stmt->fetch();
var_dump($row->queryString);

?>
--CLEAN--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
$db = MySQLPDOTest::factory();
$db->exec("DROP TABLE test_44327");
?>
Expand Down
8 changes: 3 additions & 5 deletions ext/pdo_mysql/tests/bug46292.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ Bug #46292 (PDO::setFetchMode() shouldn't requires the 2nd arg when using FETCH_
pdo_mysql
--SKIPIF--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
MySQLPDOTest::skip();
?>
--FILE--
<?php

require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
$pdoDb = MySQLPDOTest::factory();


class myclass {
public $value;

Expand Down Expand Up @@ -42,7 +40,7 @@ MySQLPDOTest::skip();
?>
--CLEAN--
<?php
require __DIR__ . '/mysql_pdo_test.inc';
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
$db = MySQLPDOTest::factory();
$db->exec('DROP TABLE IF EXISTS test_46292');
?>
Expand Down
19 changes: 8 additions & 11 deletions ext/pdo_mysql/tests/bug53551.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,29 @@ Bug #44327 (PDORow::queryString property & numeric offsets / Crash)
pdo_mysql
--SKIPIF--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
MySQLPDOTest::skip();
$db = MySQLPDOTest::factory();
?>
--FILE--
<?php
include __DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc';
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
$db = MySQLPDOTest::factory();

$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);

$createSql = "CREATE TABLE `bug53551` (
`count` bigint(20) unsigned NOT NULL DEFAULT '0'
`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("INSERT INTO bug53551 SET `count` = 1 ");
$db->exec("SET sql_mode = 'Traditional'");
$sql = 'UPDATE bug53551 SET `count` = :count';
$stmt = $db->prepare($sql);

$values = array (
'count' => NULL,
);
$values = [
'count' => null,
];

echo "1\n";
$stmt->execute($values);
Expand All @@ -39,11 +37,10 @@ $stmt->execute($values);
var_dump($stmt->errorInfo());

echo "\ndone\n";

?>
--CLEAN--
<?php
include __DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc';
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
$db = MySQLPDOTest::factory();
$db->exec('DROP TABLE IF EXISTS bug53551');
?>
Expand Down
16 changes: 4 additions & 12 deletions ext/pdo_mysql/tests/bug53782.phpt
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
--TEST--
PDO MySQL Bug #53782 (foreach throws irrelevant exception)
--EXTENSIONS--
pdo
pdo_mysql
--SKIPIF--
<?php
require __DIR__ . '/config.inc';
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
PDOTest::skip();
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
MySQLPDOTest::skip();
?>
--FILE--
<?php
require __DIR__ . '/config.inc';
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
$conn = PDOTest::test_factory(__DIR__ . '/common.phpt');
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
$conn = MySQLPDOTest::factory();

$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

Expand All @@ -31,11 +28,6 @@ foreach ($res as $k => $v) {

echo "DONE";
?>
--CLEAN--
<?php
require __DIR__ . '/mysql_pdo_test.inc';
MySQLPDOTest::dropTestTable();
?>
--EXPECTF--
Caught: SQLSTATE[42000]: %s
Value: 0
Expand Down
26 changes: 11 additions & 15 deletions ext/pdo_mysql/tests/bug54929.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,34 @@ Bug #54929 (Parse error with single quote in sql comment (pdo-mysql))
pdo_mysql
--SKIPIF--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
MySQLPDOTest::skip();

?>
--FILE--
<?php

require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');

$pdodb = PDOTest::test_factory(__DIR__ . '/common.phpt');

require_once __DIR__ . '/inc/mysql_pdo_test.inc';
$pdodb = MySQLPDOTest::factory();

function testQuery($query) {
global $pdodb;
$stmt = $pdodb->prepare($query);

if (!$stmt->execute(array("foo"))) {
if (!$stmt->execute(["foo"])) {
var_dump($stmt->errorInfo());
} else{
var_dump($stmt->fetch(PDO::FETCH_ASSOC));
}
}

testQuery("/* ' */ select ? as f1 /* ' */");
testQuery("/* '-- */ select ? as f1 /* *' */");
testQuery("/* ' */ select ? as f1 --';");
testQuery("/* ' */ select ? as f1 -- 'a;");
testQuery("/*'**/ select ? as f1 /* ' */");
testQuery("/*'***/ select ? as f1 /* ' */");
testQuery("/* ' */ SELECT ? AS f1 /* ' */");
testQuery("/* '-- */ SELECT ? AS f1 /* *' */");
testQuery("/* ' */ SELECT ? AS f1 --';");
testQuery("/* ' */ SELECT ? AS f1 -- 'a;");
testQuery("/*'**/ SELECT ? AS f1 /* ' */");
testQuery("/*'***/ SELECT ? AS f1 /* ' */");
testQuery("/*'**a ***b / ****
******
**/ select ? as f1 /* ' */");
**/ SELECT ? AS f1 /* ' */");

?>
--EXPECTF--
Expand Down
10 changes: 5 additions & 5 deletions ext/pdo_mysql/tests/bug63176.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ Bug #63176 (Segmentation fault when instantiate 2 persistent PDO to the same db
pdo_mysql
--SKIPIF--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
MySQLPDOTest::skip();
?>
--FILE--
<?php
require(__DIR__. DIRECTORY_SEPARATOR . 'config.inc');
require_once __DIR__ . '/inc/mysql_pdo_test.inc';

class PDO2 extends PDO {
protected $transLevel;
}
Expand All @@ -18,15 +19,14 @@ class PDO3 extends PDO {
protected $tomato;
}


class ModelA {
public $db;
public function __construct($h) {
var_dump($h);
if ($h) {
$this->db = new PDO2(PDO_MYSQL_TEST_DSN, PDO_MYSQL_TEST_USER, PDO_MYSQL_TEST_PASS, array(PDO::ATTR_PERSISTENT => true));
$this->db = new PDO2(PDO_MYSQL_TEST_DSN, PDO_MYSQL_TEST_USER, PDO_MYSQL_TEST_PASS, [PDO::ATTR_PERSISTENT => true]);
} else {
$this->db = new PDO3(PDO_MYSQL_TEST_DSN, PDO_MYSQL_TEST_USER, PDO_MYSQL_TEST_PASS, array(PDO::ATTR_PERSISTENT => true));
$this->db = new PDO3(PDO_MYSQL_TEST_DSN, PDO_MYSQL_TEST_USER, PDO_MYSQL_TEST_PASS, [PDO::ATTR_PERSISTENT => true]);
}
$this->db->query('SELECT 1')->fetchAll();
}
Expand Down
25 changes: 12 additions & 13 deletions ext/pdo_mysql/tests/bug63185.phpt
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
--TEST--
Bug #63185: nextRowset() ignores MySQL errors with native prepared statements
--EXTENSIONS--
pdo
pdo_mysql
--SKIPIF--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
MySQLPDOTest::skip();
?>
--FILE--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');

require_once __DIR__ . '/inc/mysql_pdo_test.inc';
$pdo = MySQLPDOTest::factory();

$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$pdo->exec('DROP PROCEDURE IF EXISTS test_procedure_error_at_second');
$pdo->exec('CREATE PROCEDURE test_procedure_error_at_second ()
$procedure = 'test_procedure_error_at_second_63185';

$pdo->exec("CREATE PROCEDURE {$procedure} ()
BEGIN
SELECT "x" as foo;
SELECT 'x' AS foo;
SELECT * FROM no_such_table;
END');
END");

$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
$st = $pdo->query('CALL test_procedure_error_at_second()');
$st = $pdo->query("CALL {$procedure}()");
var_dump($st->fetchAll());
try {
var_dump($st->nextRowset());
Expand All @@ -33,21 +33,20 @@ try {
unset($st);

$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$st = $pdo->query('CALL test_procedure_error_at_second()');
$st = $pdo->query("CALL {$procedure}()");
var_dump($st->fetchAll());
try {
var_dump($st->nextRowset());
} catch (PDOException $e) {
echo $e->getMessage(), "\n";
}
var_dump($st->fetchAll());

?>
--CLEAN--
<?php
require_once __DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc';
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
$pdo = MySQLPDOTest::factory();
$pdo->query('DROP PROCEDURE IF EXISTS test_procedure_error_at_second');
$pdo->query('DROP PROCEDURE IF EXISTS test_procedure_error_at_second_63185');
?>
--EXPECTF--
array(1) {
Expand Down
4 changes: 2 additions & 2 deletions ext/pdo_mysql/tests/bug66141.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ Bug #66141 (mysqlnd quote function is wrong with NO_BACKSLASH_ESCAPES after fail
pdo_mysql
--SKIPIF--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
MySQLPDOTest::skip();
?>
--FILE--
<?php
include __DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc';
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
$db = MySQLPDOTest::factory();

$input = 'Something\', 1 as one, 2 as two FROM dual; -- f';
Expand Down
14 changes: 7 additions & 7 deletions ext/pdo_mysql/tests/bug66528.phpt
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
--TEST--
Bug #66528: No PDOException or errorCode if database becomes unavailable before PDO::commit
--EXTENSIONS--
pdo
pdo_mysql
--SKIPIF--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
MySQLPDOTest::skip();
?>
--FILE--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');

require_once __DIR__ . '/inc/mysql_pdo_test.inc';
$dbh = MySQLPDOTest::factory();

$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);

$dbh->exec('CREATE TABLE test_66528 (a int) engine=innodb');
$dbh->exec('CREATE TABLE test_66528 (a INT) ENGINE=InnoDB');
$dbh->beginTransaction();
$dbh->exec('INSERT INTO test_66528 (a) VALUES (1), (2)');
$stmt = $dbh->query('SELECT * FROM test_66528');
Expand All @@ -42,8 +41,9 @@ try {
?>
--CLEAN--
<?php
require __DIR__ . '/mysql_pdo_test.inc';
MySQLPDOTest::dropTestTable(NULL, 'test_66528');
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
$db = MySQLPDOTest::factory();
$db->exec('DROP TABLE IF EXISTS test_66528');
?>
--EXPECT--
SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.
Expand Down
Loading