Skip to content

Commit 54a63d9

Browse files
kamil-tekielanikic
authored andcommitted
Fix test cases for MariaDB
And remove unnecessary try-catch. Closes GH-6505.
1 parent 9e3ba77 commit 54a63d9

File tree

3 files changed

+57
-85
lines changed

3 files changed

+57
-85
lines changed

ext/pdo_mysql/tests/pdo_mysql_attr_oracle_nulls.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ MySQLPDOTest::skip();
4040
$db->setAttribute(PDO::ATTR_ORACLE_NULLS, 1);
4141
$stmt = $db->query('SELECT VERSION() as _version');
4242
$row = $stmt->fetch(PDO::FETCH_ASSOC);
43-
if ((int)substr($row['_version'], 0, 1) >= 5)
43+
if ((int)strtok($row['_version'], '.') >= 5)
4444
$have_procedures = true;
4545
else
4646
$have_procedures = false;

ext/pdo_mysql/tests/pdo_mysql_exec_load_data.phpt

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -64,50 +64,43 @@ if (($row = $stmt->fetch(PDO::FETCH_ASSOC)) && ($row['value'] != '')) {
6464
MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db));
6565

6666
/* affected rows related */
67-
try {
6867

69-
exec_and_count(2, $db, 'DROP TABLE IF EXISTS test', 0);
70-
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);
68+
exec_and_count(2, $db, 'DROP TABLE IF EXISTS test', 0);
69+
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);
7170

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

79-
$fp = fopen($filename, "w");
80-
fwrite($fp, "1;foo\n");
81-
fwrite($fp, "2;bar");
82-
fclose($fp);
83-
84-
$sql = sprintf("LOAD DATA LOCAL INFILE %s INTO TABLE test FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n'", $db->quote($filename));
85-
86-
if (exec_and_count(4, $db, $sql, 2)) {
87-
88-
$stmt = $db->query('SELECT id, col1 FROM test ORDER BY id ASC');
89-
$expected = array(array("id" => 1, "col1" => "foo"), array("id" => 2, "col1" => "bar"));
90-
$ret = $stmt->fetchAll(PDO::FETCH_ASSOC);
91-
foreach ($expected as $offset => $exp) {
92-
foreach ($exp as $key => $value) {
93-
if ($ret[$offset][$key] != $value) {
94-
printf("Results seem wrong, check manually\n");
95-
var_dump($ret);
96-
var_dump($expected);
97-
break 2;
98-
}
78+
$fp = fopen($filename, "w");
79+
fwrite($fp, "1;foo\n");
80+
fwrite($fp, "2;bar");
81+
fclose($fp);
82+
83+
$sql = sprintf("LOAD DATA LOCAL INFILE %s INTO TABLE test FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n'", $db->quote($filename));
84+
85+
if (exec_and_count(4, $db, $sql, 2)) {
86+
87+
$stmt = $db->query('SELECT id, col1 FROM test ORDER BY id ASC');
88+
$expected = array(array("id" => 1, "col1" => "foo"), array("id" => 2, "col1" => "bar"));
89+
$ret = $stmt->fetchAll(PDO::FETCH_ASSOC);
90+
foreach ($expected as $offset => $exp) {
91+
foreach ($exp as $key => $value) {
92+
if ($ret[$offset][$key] != $value) {
93+
printf("Results seem wrong, check manually\n");
94+
var_dump($ret);
95+
var_dump($expected);
96+
break 2;
9997
}
10098
}
10199
}
102-
103-
unlink($filename);
104-
105-
} catch (PDOException $e) {
106-
printf("[001] %s, [%s] %s\n",
107-
$e->getMessage(),
108-
$db->errorCode(), implode(' ', $db->errorInfo()));
109100
}
110101

102+
unlink($filename);
103+
111104
print "done!";
112105
?>
113106
--CLEAN--

ext/pdo_mysql/tests/pdo_mysql_prepare_load_data.phpt

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -65,53 +65,38 @@ if (($row = $stmt->fetch(PDO::FETCH_ASSOC)) && ($row['value'] != '')) {
6565
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
6666
MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db));
6767

68-
/* affected rows related */
69-
try {
70-
71-
exec_and_count(2, $db, 'DROP TABLE IF EXISTS test', 0);
72-
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);
73-
74-
$stmt = $db->query("SHOW VARIABLES LIKE 'secure_file_priv'");
75-
if (($row = $stmt->fetch(PDO::FETCH_ASSOC)) && ($row['value'] != '')) {
76-
$filename = $row['value'] . DIRECTORY_SEPARATOR . "pdo_mysql_exec_load_data.csv";
77-
} else {
78-
$filename = MySQLPDOTest::getTempDir() . DIRECTORY_SEPARATOR . "pdo_mysql_exec_load_data.csv";
79-
}
80-
81-
$fp = fopen($filename, "w");
82-
fwrite($fp, "1;foo\n");
83-
fwrite($fp, "2;bar");
84-
fclose($fp);
85-
86-
// This should fail, the PS protocol should not support it.
87-
// mysqlnd will give 2014 as a follow-up of the fallback logic
88-
// libmysql will give a little more precise 2030 error code
89-
// However, you get an error and the big question is what happens to the line
90-
$stmt = $db->prepare(sprintf("LOAD DATA INFILE %s INTO TABLE test FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n'", $db->quote($filename)));
91-
if (!$stmt->execute()) {
92-
printf("[004] [%d] %s\n", $stmt->errorCode(), var_export($stmt->errorInfo(), true));
93-
}
68+
exec_and_count(2, $db, 'DROP TABLE IF EXISTS test', 0);
69+
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);
70+
71+
$stmt = $db->query("SHOW VARIABLES LIKE 'secure_file_priv'");
72+
if (($row = $stmt->fetch(PDO::FETCH_ASSOC)) && ($row['value'] != '')) {
73+
$filename = $row['value'] . DIRECTORY_SEPARATOR . "pdo_mysql_exec_load_data.csv";
74+
} else {
75+
$filename = MySQLPDOTest::getTempDir() . DIRECTORY_SEPARATOR . "pdo_mysql_exec_load_data.csv";
76+
}
9477

95-
// Check the line
96-
$stmt = $db->query("SELECT 1 as 'one'");
97-
if ($stmt->errorCode() != '0000') {
98-
printf("[005] [%d] %s\n", $stmt->errorCode(), var_export($stmt->errorInfo(), true));
99-
} else {
100-
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
101-
if (!isset($rows[0]['one']) || $rows[0]['one'] != 1)
102-
printf("[006] [%d] %s\n", $stmt->errorCode(), var_export($stmt->errorInfo(), true));
103-
}
78+
$fp = fopen($filename, "w");
79+
fwrite($fp, "1;foo\n");
80+
fwrite($fp, "2;bar");
81+
fclose($fp);
10482

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

107-
} catch (PDOException $e) {
108-
printf("[001] %s, [%s] %s (%s)\n",
109-
$e->getMessage(),
110-
$db->errorCode(),
111-
implode(' ', $db->errorInfo()),
112-
(isset($stmt)) ? implode(' ', $stmt->errorInfo()) : 'N/A');
88+
// Check the line
89+
$stmt = $db->query("SELECT 1 as 'one'");
90+
if ($stmt->errorCode() != '0000') {
91+
printf("[005] [%d] %s\n", $stmt->errorCode(), var_export($stmt->errorInfo(), true));
92+
} else {
93+
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
94+
if (!isset($rows[0]['one']) || $rows[0]['one'] != 1)
95+
printf("[006] [%d] %s\n", $stmt->errorCode(), var_export($stmt->errorInfo(), true));
11396
}
11497

98+
unlink($filename);
99+
115100
print "done!";
116101
?>
117102
--CLEAN--
@@ -120,10 +105,4 @@ require __DIR__ . '/mysql_pdo_test.inc';
120105
MySQLPDOTest::dropTestTable();
121106
?>
122107
--EXPECTF--
123-
Warning: PDOStatement::execute(): SQLSTATE[HY000]: General error: %s in %s on line %d
124-
[004] [0] array (
125-
0 => 'HY000',
126-
1 => %d,
127-
2 => %s,
128-
)
129108
done!

0 commit comments

Comments
 (0)