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 = ""; $insert = "";
$buffer = ""; $buffer = "";
$keys = array(); $keys = array();
$suffix = "";
while ($row = $result->fetch_row()) { while ($row = $result->fetch_row()) {
if (!$keys) { if (!$keys) {
$values = array();
foreach ($row as $val) { foreach ($row as $val) {
$field = $result->fetch_field(); $field = $result->fetch_field();
$keys[] = $field->name; $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 ($_POST["format"] != "sql") {
if ($style == "table") { if ($style == "table") {
@ -692,29 +697,19 @@ DROP PROCEDURE adminer_alter;
foreach ($row as $key => $val) { 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 $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); $s = ($max_packet ? "\n" : " ") . "(" . implode(",\t", $row) . ")";
if ($style == "INSERT+UPDATE") { if (!$buffer) {
$set = array(); $buffer = $insert . $s;
foreach ($row as $key => $val) { } elseif (strlen($buffer) + 4 + strlen($s) + strlen($suffix) < $max_packet) { // 4 - length specification
$set[] = idf_escape($keys[$key]) . " = $val"; $buffer .= ",$s";
}
echo "$insert ($s) ON DUPLICATE KEY UPDATE " . implode(", ", $set) . ";\n";
} else { } else {
$s = ($max_packet ? "\n" : " ") . "($s)"; echo $buffer . $suffix;
if (!$buffer) { $buffer = $insert . $s;
$buffer = $insert . $s;
} elseif (strlen($buffer) + 4 + strlen($s) < $max_packet) { // 4 - length specification
$buffer .= ",$s";
} else {
echo "$buffer;\n";
$buffer = $insert . $s;
}
} }
} }
} }
if ($_POST["format"] == "sql" && $style != "INSERT+UPDATE" && $buffer) { if ($buffer) {
$buffer .= ";\n"; echo $buffer . $suffix;
echo $buffer;
} }
} elseif ($_POST["format"] == "sql") { } elseif ($_POST["format"] == "sql") {
echo "-- " . str_replace("\n", " ", $connection->error) . "\n"; echo "-- " . str_replace("\n", " ", $connection->error) . "\n";

View file

@ -1,5 +1,6 @@
Adminer 3.5.2-dev: Adminer 3.5.2-dev:
Edit strings with \n in textarea Edit strings with \n in textarea
Use VALUES() in INSERT+UPDATE export
Style logout button as link Style logout button as link
Adminer 3.5.1 (released 2012-08-10): 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 = ($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)); $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"; $return = "NULL";
} elseif (ereg('^(md5|sha1)$', $function)) { } elseif (ereg('^(md5|sha1)$', $function)) {
$return = "$function($return)"; $return = "$function($return)";