Use VALUES() in INSERT+UPDATE export

This commit is contained in:
Jakub Vrana 2012-08-11 22:59:20 -07:00
parent f9cbf50bd7
commit 3a381564e5
3 changed files with 18 additions and 20 deletions

View file

@ -672,12 +672,17 @@ DROP PROCEDURE adminer_alter;
$insert = "";
$buffer = "";
$keys = array();
$suffix = "";
while ($row = $result->fetch_row()) {
if (!$keys) {
$values = array();
foreach ($row as $val) {
$field = $result->fetch_field();
$keys[] = $field->name;
$key = idf_escape($field->name);
$values[] = "$key = VALUES($key)";
}
$suffix = ($style == "INSERT+UPDATE" ? "\nON DUPLICATE KEY UPDATE " . implode(", ", $values) : "") . ";\n";
}
if ($_POST["format"] != "sql") {
if ($style == "table") {
@ -692,29 +697,19 @@ DROP PROCEDURE adminer_alter;
foreach ($row as $key => $val) {
$row[$key] = ($val !== null ? (ereg('int|float|double|decimal|bit', $fields[$keys[$key]]["type"]) ? $val : q($val)) : "NULL"); //! columns looking like functions
}
$s = implode(",\t", $row);
if ($style == "INSERT+UPDATE") {
$set = array();
foreach ($row as $key => $val) {
$set[] = idf_escape($keys[$key]) . " = $val";
}
echo "$insert ($s) ON DUPLICATE KEY UPDATE " . implode(", ", $set) . ";\n";
$s = ($max_packet ? "\n" : " ") . "(" . implode(",\t", $row) . ")";
if (!$buffer) {
$buffer = $insert . $s;
} elseif (strlen($buffer) + 4 + strlen($s) + strlen($suffix) < $max_packet) { // 4 - length specification
$buffer .= ",$s";
} else {
$s = ($max_packet ? "\n" : " ") . "($s)";
if (!$buffer) {
$buffer = $insert . $s;
} elseif (strlen($buffer) + 4 + strlen($s) < $max_packet) { // 4 - length specification
$buffer .= ",$s";
} else {
echo "$buffer;\n";
$buffer = $insert . $s;
}
echo $buffer . $suffix;
$buffer = $insert . $s;
}
}
}
if ($_POST["format"] == "sql" && $style != "INSERT+UPDATE" && $buffer) {
$buffer .= ";\n";
echo $buffer;
if ($buffer) {
echo $buffer . $suffix;
}
} elseif ($_POST["format"] == "sql") {
echo "-- " . str_replace("\n", " ", $connection->error) . "\n";

View file

@ -1,5 +1,6 @@
Adminer 3.5.2-dev:
Edit strings with \n in textarea
Use VALUES() in INSERT+UPDATE export
Style logout button as link
Adminer 3.5.1 (released 2012-08-10):

View file

@ -468,7 +468,9 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
$return = ($match["p1"] != "" ? $match["p1"] : ($match["p2"] != "" ? ($match["p2"] < 70 ? 20 : 19) . $match["p2"] : gmdate("Y"))) . "-$match[p3]$match[p4]-$match[p5]$match[p6]" . end($match);
}
$return = ($field["type"] == "bit" && ereg('^[0-9]+$', $value) ? $return : q($return));
if ($value == "" && ($field["null"] || !ereg('char|text', $field["type"])) && !like_bool($field)) {
if ($value == "" && like_bool($field)) {
$return = "0";
} elseif ($value == "" && ($field["null"] || !ereg('char|text', $field["type"]))) {
$return = "NULL";
} elseif (ereg('^(md5|sha1)$', $function)) {
$return = "$function($return)";