Permalink
Browse files

Use extended INSERT in select export

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@695 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent 8611716 commit fa5c952af00219ec277cb65ad4fc87976ac3f1d4 jakubvrana committed Jun 15, 2009
Showing with 7 additions and 6 deletions.
  1. +0 −1 adminer/dump.inc.php
  2. +4 −4 adminer/include/export.inc.php
  3. +3 −1 adminer/select.inc.php
View
@@ -12,7 +12,6 @@ function tar_file($filename, $contents) {
if ($_POST) {
$ext = dump_headers((strlen($_GET["dump"]) ? $_GET["dump"] : $_GET["db"]), (!strlen($_GET["db"]) || count((array) $_POST["tables"] + (array) $_POST["data"]) > 1));
if ($_POST["format"] != "csv") {
- $max_packet = 1048576; // default, minimum is 1024
echo "SET NAMES utf8;\n";
echo "SET foreign_key_checks = 0;\n";
echo "SET time_zone = '" . $dbh->escape_string($dbh->result($dbh->query("SELECT @@time_zone"))) . "';\n";
@@ -129,7 +129,7 @@ function dump_data($table, $style, $select = "") {
if ($_POST["format"] == "csv") {
dump_csv($row);
} else {
- $insert = "INSERT INTO " . idf_escape($table) . ($select ? " (" . implode(", ", array_map('idf_escape', array_keys($row))) . ")" : "") . " VALUES ";
+ $insert = "INSERT INTO " . idf_escape($table) . ($select ? " (" . implode(", ", array_map('idf_escape', array_keys($row))) . ")" : "") . " VALUES";
$row2 = array();
foreach ($row as $key => $val) {
$row2[$key] = (isset($val) ? "'" . $dbh->escape_string($val) . "'" : "NULL");
@@ -141,7 +141,7 @@ function dump_data($table, $style, $select = "") {
}
echo "$insert (" . implode(", ", $row2) . ") ON DUPLICATE KEY UPDATE " . implode(", ", $set) . ";\n";
} else {
- $s = "(" . implode(", ", $row2) . ")";
+ $s = "\n(" . implode(", ", $row2) . ")";
if (!$length) {
echo $insert, $s;
$length = strlen($insert) + strlen($s);
@@ -150,7 +150,7 @@ function dump_data($table, $style, $select = "") {
if ($length < $max_packet) {
echo ", ", $s;
} else {
- echo ";\n", $insert, $s;
+ echo ";\n$insert", $s;
$length = strlen($insert) + strlen($s);
}
}
@@ -175,4 +175,4 @@ function dump_headers($identifier, $multi_table = false) {
$dump_output = "<select name='output'><option value='text'>" . lang('open') . "</option><option value='file'>" . lang('save') . "</option></select>";
$dump_format = "<select name='format'><option value='sql'>" . lang('SQL') . "</option><option value='csv'>" . lang('CSV') . "</option></select>";
-$max_packet = 0;
+$max_packet = 1048576; // default, minimum is 1024
View
@@ -74,9 +74,11 @@
dump_table($_GET["select"], "");
$query = "SELECT " . ($select ? implode(", ", $select) : "*") . " FROM " . idf_escape($_GET["select"]);
if (is_array($_POST["check"])) {
+ $union = array();
foreach ($_POST["check"] as $val) {
- dump_data($_GET["select"], "INSERT", "$query WHERE " . implode(" AND ", where_check($val)) . " LIMIT 1");
+ $union[] = "($query WHERE " . implode(" AND ", where_check($val)) . " LIMIT 1)";
}
+ dump_data($_GET["select"], "INSERT", implode(" UNION ALL ", $union));
} else {
dump_data($_GET["select"], "INSERT", $query . ($where ? " WHERE " . implode(" AND ", $where) : ""));
}

0 comments on commit fa5c952

Please sign in to comment.