Export SQL command result (bug #3116854)
This commit is contained in:
parent
0836c34aef
commit
15715b32ff
|
@ -612,13 +612,19 @@ DROP PROCEDURE adminer_alter;
|
||||||
if ($_POST["format"] == "sql" && $style == "TRUNCATE+INSERT") {
|
if ($_POST["format"] == "sql" && $style == "TRUNCATE+INSERT") {
|
||||||
echo truncate_sql($table) . ";\n";
|
echo truncate_sql($table) . ";\n";
|
||||||
}
|
}
|
||||||
$fields = fields($table);
|
if ($_POST["format"] == "sql") {
|
||||||
|
$fields = fields($table);
|
||||||
|
}
|
||||||
$result = $connection->query($query, 1); // 1 - MYSQLI_USE_RESULT //! enum and set as numbers
|
$result = $connection->query($query, 1); // 1 - MYSQLI_USE_RESULT //! enum and set as numbers
|
||||||
if ($result) {
|
if ($result) {
|
||||||
$insert = "";
|
$insert = "";
|
||||||
$buffer = "";
|
$buffer = "";
|
||||||
while ($row = $result->fetch_assoc()) {
|
while ($row = $result->fetch_assoc()) {
|
||||||
if ($_POST["format"] != "sql") {
|
if ($_POST["format"] != "sql") {
|
||||||
|
if ($style == "table") {
|
||||||
|
dump_csv(array_keys($row));
|
||||||
|
$style = "INSERT";
|
||||||
|
}
|
||||||
dump_csv($row);
|
dump_csv($row);
|
||||||
} else {
|
} else {
|
||||||
if (!$insert) {
|
if (!$insert) {
|
||||||
|
|
|
@ -56,30 +56,21 @@ if ($_POST && !$error) {
|
||||||
if ($_POST["export"]) {
|
if ($_POST["export"]) {
|
||||||
$adminer->dumpHeaders($TABLE);
|
$adminer->dumpHeaders($TABLE);
|
||||||
$adminer->dumpTable($TABLE, "");
|
$adminer->dumpTable($TABLE, "");
|
||||||
if (ereg("[ct]sv", $_POST["format"])) { // CSV or TSV
|
|
||||||
$row = array_keys($fields);
|
|
||||||
if ($select) {
|
|
||||||
$row = array();
|
|
||||||
foreach ($select as $val) {
|
|
||||||
$row[] = (ereg('^`.*`$', $val) ? idf_unescape($val) : $val); //! columns looking like functions
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dump_csv($row);
|
|
||||||
}
|
|
||||||
if (!is_array($_POST["check"]) || $unselected === array()) {
|
if (!is_array($_POST["check"]) || $unselected === array()) {
|
||||||
$where2 = $where;
|
$where2 = $where;
|
||||||
if (is_array($_POST["check"])) {
|
if (is_array($_POST["check"])) {
|
||||||
$where2[] = "($where_check)";
|
$where2[] = "($where_check)";
|
||||||
}
|
}
|
||||||
$adminer->dumpData($TABLE, "INSERT", "SELECT $from" . ($where2 ? "\nWHERE " . implode(" AND ", $where2) : "") . $group_by);
|
$query = "SELECT $from" . ($where2 ? "\nWHERE " . implode(" AND ", $where2) : "") . $group_by;
|
||||||
} else {
|
} else {
|
||||||
$union = array();
|
$union = array();
|
||||||
foreach ($_POST["check"] as $val) {
|
foreach ($_POST["check"] as $val) {
|
||||||
// where is not unique so OR can't be used
|
// where is not unique so OR can't be used
|
||||||
$union[] = "(SELECT" . limit($from, "\nWHERE " . ($where ? implode(" AND ", $where) . " AND " : "") . where_check($val) . $group_by, 1) . ")";
|
$union[] = "(SELECT" . limit($from, "\nWHERE " . ($where ? implode(" AND ", $where) . " AND " : "") . where_check($val) . $group_by, 1) . ")";
|
||||||
}
|
}
|
||||||
$adminer->dumpData($TABLE, "INSERT", implode(" UNION ALL ", $union));
|
$query = implode(" UNION ALL ", $union);
|
||||||
}
|
}
|
||||||
|
$adminer->dumpData($TABLE, "table", $query);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
if (!$adminer->selectEmailProcess($where, $foreign_keys)) {
|
if (!$adminer->selectEmailProcess($where, $foreign_keys)) {
|
||||||
|
|
|
@ -1,4 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
if (!$error && $_POST["export"]) {
|
||||||
|
$adminer->dumpHeaders("sql");
|
||||||
|
$adminer->dumpTable("", "");
|
||||||
|
$adminer->dumpData("", "table", $_POST["query"]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
restart_session();
|
restart_session();
|
||||||
$history_all = &get_session("queries");
|
$history_all = &get_session("queries");
|
||||||
$history = &$history_all[DB];
|
$history = &$history_all[DB];
|
||||||
|
@ -43,6 +50,9 @@ if (!$error && $_POST) {
|
||||||
$errors = array();
|
$errors = array();
|
||||||
$parse = '[\'`"]' . ($jush == "pgsql" ? '|\\$[^$]*\\$' : ($jush == "mssql" || $jush == "sqlite" ? '|\\[' : '')) . '|/\\*|-- |#'; //! ` and # not everywhere
|
$parse = '[\'`"]' . ($jush == "pgsql" ? '|\\$[^$]*\\$' : ($jush == "mssql" || $jush == "sqlite" ? '|\\[' : '')) . '|/\\*|-- |#'; //! ` and # not everywhere
|
||||||
$total_start = explode(" ", microtime());
|
$total_start = explode(" ", microtime());
|
||||||
|
parse_str($_COOKIE["adminer_export"], $adminer_export);
|
||||||
|
$dump_format = $adminer->dumpFormat();
|
||||||
|
unset($dump_format["sql"]);
|
||||||
while ($query != "") {
|
while ($query != "") {
|
||||||
if (!$offset && $jush == "sql" && preg_match('~^\\s*DELIMITER\\s+(.+)~i', $query, $match)) {
|
if (!$offset && $jush == "sql" && preg_match('~^\\s*DELIMITER\\s+(.+)~i', $query, $match)) {
|
||||||
$delimiter = $match[1];
|
$delimiter = $match[1];
|
||||||
|
@ -102,14 +112,26 @@ if (!$error && $_POST) {
|
||||||
$print = "";
|
$print = "";
|
||||||
}
|
}
|
||||||
select($result, $connection2);
|
select($result, $connection2);
|
||||||
|
echo "<form action='' method='post'>\n";
|
||||||
echo "<p>" . ($result->num_rows ? lang('%d row(s)', $result->num_rows) : "") . $time;
|
echo "<p>" . ($result->num_rows ? lang('%d row(s)', $result->num_rows) : "") . $time;
|
||||||
|
$id = "export-$commands";
|
||||||
|
$export = ", <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('Export') . "</a><span id='$id' class='hidden'>: "
|
||||||
|
. html_select("output", $adminer->dumpOutput(), $adminer_export["output"]) . " "
|
||||||
|
. html_select("format", $dump_format, $adminer_export["format"])
|
||||||
|
. " <input type='hidden' name='query' value='" . h($q) . "' />"
|
||||||
|
. " <input type='hidden' name='token' value='$token' />"
|
||||||
|
. " <input type='submit' name='export' value='" . lang('Export') . "' onclick='eventStop(event);'></span>"
|
||||||
|
;
|
||||||
if ($connection2 && preg_match("~^($space|\\()*SELECT\\b~isU", $q) && ($explain = explain($connection2, $q))) {
|
if ($connection2 && preg_match("~^($space|\\()*SELECT\\b~isU", $q) && ($explain = explain($connection2, $q))) {
|
||||||
$id = "explain-$commands";
|
$id = "explain-$commands";
|
||||||
echo ", <a href='#$id' onclick=\"return !toggle('$id');\">EXPLAIN</a>\n";
|
echo ", <a href='#$id' onclick=\"return !toggle('$id');\">EXPLAIN</a>$export\n";
|
||||||
echo "<div id='$id' class='hidden'>\n";
|
echo "<div id='$id' class='hidden'>\n";
|
||||||
select($explain, $connection2, ($jush == "sql" ? "http://dev.mysql.com/doc/refman/" . substr($connection->server_info, 0, 3) . "/en/explain-output.html#" : ""));
|
select($explain, $connection2, ($jush == "sql" ? "http://dev.mysql.com/doc/refman/" . substr($connection->server_info, 0, 3) . "/en/explain-output.html#" : ""));
|
||||||
echo "</div>\n";
|
echo "</div>\n";
|
||||||
|
} else {
|
||||||
|
echo "$export\n";
|
||||||
}
|
}
|
||||||
|
echo "</form>\n";
|
||||||
}
|
}
|
||||||
$start = $end;
|
$start = $end;
|
||||||
} while ($connection->next_result());
|
} while ($connection->next_result());
|
||||||
|
|
Loading…
Reference in a new issue