Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use VALUES() in INSERT+UPDATE export

  • Loading branch information...
commit 3a381564e5c9066e6bbd1e2d1118158ee8afe8a5 1 parent f9cbf50
@vrana authored
View
33 adminer/include/adminer.inc.php
@@ -672,12 +672,17 @@ function dumpData($table, $style, $query) {
$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 @@ function dumpData($table, $style, $query) {
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
1  changes.txt
@@ -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
4 editor/include/adminer.inc.php
@@ -468,7 +468,9 @@ function processInput($field, $value, $function = "") {
$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)";
Please sign in to comment.
Something went wrong with that request. Please try again.