Skip to content

Fix PDO test cases #6505

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

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion ext/pdo_mysql/tests/pdo_mysql_attr_oracle_nulls.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ MySQLPDOTest::skip();
$db->setAttribute(PDO::ATTR_ORACLE_NULLS, 1);
$stmt = $db->query('SELECT VERSION() as _version');
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ((int)substr($row['_version'], 0, 1) >= 5)
if ((int)strtok($row['_version'], '.') >= 5)
$have_procedures = true;
else
$have_procedures = false;
Expand Down
65 changes: 29 additions & 36 deletions ext/pdo_mysql/tests/pdo_mysql_exec_load_data.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -64,50 +64,43 @@ if (($row = $stmt->fetch(PDO::FETCH_ASSOC)) && ($row['value'] != '')) {
MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db));

/* affected rows related */
try {

exec_and_count(2, $db, 'DROP TABLE IF EXISTS test', 0);
exec_and_count(3, $db, sprintf('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, col1 CHAR(10)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE), 0);
exec_and_count(2, $db, 'DROP TABLE IF EXISTS test', 0);
exec_and_count(3, $db, sprintf('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, col1 CHAR(10)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE), 0);

$stmt = $db->query("SHOW VARIABLES LIKE 'secure_file_priv'");
if (($row = $stmt->fetch(PDO::FETCH_ASSOC)) && ($row['value'] != '')) {
$filename = $row['value'] . DIRECTORY_SEPARATOR . "pdo_mysql_exec_load_data.csv";
} else {
$filename = MySQLPDOTest::getTempDir() . DIRECTORY_SEPARATOR . "pdo_mysql_exec_load_data.csv";
}
$stmt = $db->query("SHOW VARIABLES LIKE 'secure_file_priv'");
if (($row = $stmt->fetch(PDO::FETCH_ASSOC)) && ($row['value'] != '')) {
$filename = $row['value'] . DIRECTORY_SEPARATOR . "pdo_mysql_exec_load_data.csv";
} else {
$filename = MySQLPDOTest::getTempDir() . DIRECTORY_SEPARATOR . "pdo_mysql_exec_load_data.csv";
}

$fp = fopen($filename, "w");
fwrite($fp, "1;foo\n");
fwrite($fp, "2;bar");
fclose($fp);

$sql = sprintf("LOAD DATA LOCAL INFILE %s INTO TABLE test FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n'", $db->quote($filename));

if (exec_and_count(4, $db, $sql, 2)) {

$stmt = $db->query('SELECT id, col1 FROM test ORDER BY id ASC');
$expected = array(array("id" => 1, "col1" => "foo"), array("id" => 2, "col1" => "bar"));
$ret = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($expected as $offset => $exp) {
foreach ($exp as $key => $value) {
if ($ret[$offset][$key] != $value) {
printf("Results seem wrong, check manually\n");
var_dump($ret);
var_dump($expected);
break 2;
}
$fp = fopen($filename, "w");
fwrite($fp, "1;foo\n");
fwrite($fp, "2;bar");
fclose($fp);

$sql = sprintf("LOAD DATA LOCAL INFILE %s INTO TABLE test FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n'", $db->quote($filename));

if (exec_and_count(4, $db, $sql, 2)) {

$stmt = $db->query('SELECT id, col1 FROM test ORDER BY id ASC');
$expected = array(array("id" => 1, "col1" => "foo"), array("id" => 2, "col1" => "bar"));
$ret = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($expected as $offset => $exp) {
foreach ($exp as $key => $value) {
if ($ret[$offset][$key] != $value) {
printf("Results seem wrong, check manually\n");
var_dump($ret);
var_dump($expected);
break 2;
}
}
}

unlink($filename);

} catch (PDOException $e) {
printf("[001] %s, [%s] %s\n",
$e->getMessage(),
$db->errorCode(), implode(' ', $db->errorInfo()));
}

unlink($filename);

print "done!";
?>
--CLEAN--
Expand Down
75 changes: 27 additions & 48 deletions ext/pdo_mysql/tests/pdo_mysql_prepare_load_data.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -65,53 +65,38 @@ if (($row = $stmt->fetch(PDO::FETCH_ASSOC)) && ($row['value'] != '')) {
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db));

/* affected rows related */
try {

exec_and_count(2, $db, 'DROP TABLE IF EXISTS test', 0);
exec_and_count(3, $db, sprintf('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, col1 CHAR(10)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE), 0);

$stmt = $db->query("SHOW VARIABLES LIKE 'secure_file_priv'");
if (($row = $stmt->fetch(PDO::FETCH_ASSOC)) && ($row['value'] != '')) {
$filename = $row['value'] . DIRECTORY_SEPARATOR . "pdo_mysql_exec_load_data.csv";
} else {
$filename = MySQLPDOTest::getTempDir() . DIRECTORY_SEPARATOR . "pdo_mysql_exec_load_data.csv";
}

$fp = fopen($filename, "w");
fwrite($fp, "1;foo\n");
fwrite($fp, "2;bar");
fclose($fp);

// This should fail, the PS protocol should not support it.
// mysqlnd will give 2014 as a follow-up of the fallback logic
// libmysql will give a little more precise 2030 error code
// However, you get an error and the big question is what happens to the line
$stmt = $db->prepare(sprintf("LOAD DATA INFILE %s INTO TABLE test FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n'", $db->quote($filename)));
if (!$stmt->execute()) {
printf("[004] [%d] %s\n", $stmt->errorCode(), var_export($stmt->errorInfo(), true));
}
exec_and_count(2, $db, 'DROP TABLE IF EXISTS test', 0);
exec_and_count(3, $db, sprintf('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, col1 CHAR(10)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE), 0);

$stmt = $db->query("SHOW VARIABLES LIKE 'secure_file_priv'");
if (($row = $stmt->fetch(PDO::FETCH_ASSOC)) && ($row['value'] != '')) {
$filename = $row['value'] . DIRECTORY_SEPARATOR . "pdo_mysql_exec_load_data.csv";
} else {
$filename = MySQLPDOTest::getTempDir() . DIRECTORY_SEPARATOR . "pdo_mysql_exec_load_data.csv";
}

// Check the line
$stmt = $db->query("SELECT 1 as 'one'");
if ($stmt->errorCode() != '0000') {
printf("[005] [%d] %s\n", $stmt->errorCode(), var_export($stmt->errorInfo(), true));
} else {
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (!isset($rows[0]['one']) || $rows[0]['one'] != 1)
printf("[006] [%d] %s\n", $stmt->errorCode(), var_export($stmt->errorInfo(), true));
}
$fp = fopen($filename, "w");
fwrite($fp, "1;foo\n");
fwrite($fp, "2;bar");
fclose($fp);

unlink($filename);
$stmt = $db->prepare(sprintf("LOAD DATA INFILE %s INTO TABLE test FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n'", $db->quote($filename)));
if (!$stmt->execute()) {
printf("[004] [%d] %s\n", $stmt->errorCode(), var_export($stmt->errorInfo(), true));
}

} catch (PDOException $e) {
printf("[001] %s, [%s] %s (%s)\n",
$e->getMessage(),
$db->errorCode(),
implode(' ', $db->errorInfo()),
(isset($stmt)) ? implode(' ', $stmt->errorInfo()) : 'N/A');
// Check the line
$stmt = $db->query("SELECT 1 as 'one'");
if ($stmt->errorCode() != '0000') {
printf("[005] [%d] %s\n", $stmt->errorCode(), var_export($stmt->errorInfo(), true));
} else {
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (!isset($rows[0]['one']) || $rows[0]['one'] != 1)
printf("[006] [%d] %s\n", $stmt->errorCode(), var_export($stmt->errorInfo(), true));
}

unlink($filename);

print "done!";
?>
--CLEAN--
Expand All @@ -120,10 +105,4 @@ require __DIR__ . '/mysql_pdo_test.inc';
MySQLPDOTest::dropTestTable();
?>
--EXPECTF--
Warning: PDOStatement::execute(): SQLSTATE[HY000]: General error: %s in %s on line %d
[004] [0] array (
0 => 'HY000',
1 => %d,
2 => %s,
)
done!