MySQL: Use utf8mb4 in export only if required

This commit is contained in:
Jakub Vrana 2015-03-06 09:36:20 -08:00
parent 6bbc8bc3ea
commit 8aa420d160
5 changed files with 29 additions and 10 deletions

View file

@ -16,7 +16,7 @@ if ($_POST && !$error) {
if ($is_sql) {
echo "-- Adminer $VERSION " . $drivers[DRIVER] . " dump\n\n";
if ($jush == "sql") {
echo "SET NAMES " . charset($connection) . ";
echo "SET NAMES utf8;
SET time_zone = '+00:00';
" . ($_POST["data_style"] ? "SET foreign_key_checks = 0;
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
@ -39,6 +39,7 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
$adminer->dumpDatabase($db);
if ($connection->select_db($db)) {
if ($is_sql && preg_match('~CREATE~', $style) && ($create = $connection->result("SHOW CREATE DATABASE " . idf_escape($db), 1))) {
set_utf8mb4($create);
if ($style == "DROP+CREATE") {
echo "DROP DATABASE IF EXISTS " . idf_escape($db) . ";\n";
}
@ -53,16 +54,18 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
if ($_POST["routines"]) {
foreach (array("FUNCTION", "PROCEDURE") as $routine) {
foreach (get_rows("SHOW $routine STATUS WHERE Db = " . q($db), null, "-- ") as $row) {
$out .= ($style != 'DROP+CREATE' ? "DROP $routine IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "")
. remove_definer($connection->result("SHOW CREATE $routine " . idf_escape($row["Name"]), 2)) . ";;\n\n";
$create = remove_definer($connection->result("SHOW CREATE $routine " . idf_escape($row["Name"]), 2));
set_utf8mb4($create);
$out .= ($style != 'DROP+CREATE' ? "DROP $routine IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "") . "$create;;\n\n";
}
}
}
if ($_POST["events"]) {
foreach (get_rows("SHOW EVENTS", null, "-- ") as $row) {
$out .= ($style != 'DROP+CREATE' ? "DROP EVENT IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "")
. remove_definer($connection->result("SHOW CREATE EVENT " . idf_escape($row["Name"]), 3)) . ";;\n\n";
$create = remove_definer($connection->result("SHOW CREATE EVENT " . idf_escape($row["Name"]), 3));
set_utf8mb4($create);
$out .= ($style != 'DROP+CREATE' ? "DROP EVENT IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "") . "$create;;\n\n";
}
}

View file

@ -637,7 +637,7 @@ username.form['auth[driver]'].onchange();
if ($style) {
dump_csv(array_keys(fields($table)));
}
} elseif ($style) {
} else {
if ($is_view == 2) {
$fields = array();
foreach (fields($table) as $name => $field) {
@ -647,7 +647,8 @@ username.form['auth[driver]'].onchange();
} else {
$create = create_sql($table, $_POST["auto_increment"]);
}
if ($create) {
set_utf8mb4($create);
if ($style && $create) {
if ($style == "DROP+CREATE" || $is_view == 1) {
echo "DROP " . ($is_view == 2 ? "VIEW" : "TABLE") . " IF EXISTS " . table($table) . ";\n";
}

View file

@ -523,3 +523,15 @@ function db_size($db) {
}
return format_number($return);
}
/** Print SET NAMES if utf8mb4 might be needed
* @param string
* @return null
*/
function set_utf8mb4($create) {
static $set = false;
if (!$set && preg_match('~\butf8mb4~i', $create)) { // possible false positive
$set = true;
echo "SET NAMES utf8mb4;\n\n";
}
}

View file

@ -1,2 +1,2 @@
<?php
$VERSION = "4.2.0";
$VERSION = "4.2.1-dev";

View file

@ -1,4 +1,7 @@
Adminer 4.2.0 (released 2015-02-07)
Adminer 4.2.1-dev:
MySQL: Use utf8mb4 in export only if required
Adminer 4.2.0 (released 2015-02-07):
Fix XSS in login form (bug #436)
Allow limiting number of displayed rows in SQL command
Fix reading routine column collations
@ -21,7 +24,7 @@ Elasticsearch: Use where in select
Firebird: Alpha version
Danish translation
Adminer 4.1.0 (released 2014-04-18)
Adminer 4.1.0 (released 2014-04-18):
Provide size of all databases in the overview
Prevent against brute force login attempts from the same IP address
Compute number of tables in the overview explicitly