diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 65e0dffc..de991560 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -612,13 +612,19 @@ DROP PROCEDURE adminer_alter; if ($_POST["format"] == "sql" && $style == "TRUNCATE+INSERT") { 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 if ($result) { $insert = ""; $buffer = ""; while ($row = $result->fetch_assoc()) { if ($_POST["format"] != "sql") { + if ($style == "table") { + dump_csv(array_keys($row)); + $style = "INSERT"; + } dump_csv($row); } else { if (!$insert) { diff --git a/adminer/select.inc.php b/adminer/select.inc.php index 0d814612..94850652 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -56,30 +56,21 @@ if ($_POST && !$error) { if ($_POST["export"]) { $adminer->dumpHeaders($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()) { $where2 = $where; if (is_array($_POST["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 { $union = array(); foreach ($_POST["check"] as $val) { // 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) . ")"; } - $adminer->dumpData($TABLE, "INSERT", implode(" UNION ALL ", $union)); + $query = implode(" UNION ALL ", $union); } + $adminer->dumpData($TABLE, "table", $query); exit; } if (!$adminer->selectEmailProcess($where, $foreign_keys)) { diff --git a/adminer/sql.inc.php b/adminer/sql.inc.php index 2ffb4eea..48bca21e 100644 --- a/adminer/sql.inc.php +++ b/adminer/sql.inc.php @@ -1,4 +1,11 @@ dumpHeaders("sql"); + $adminer->dumpTable("", ""); + $adminer->dumpData("", "table", $_POST["query"]); + exit; +} + restart_session(); $history_all = &get_session("queries"); $history = &$history_all[DB]; @@ -43,6 +50,9 @@ if (!$error && $_POST) { $errors = array(); $parse = '[\'`"]' . ($jush == "pgsql" ? '|\\$[^$]*\\$' : ($jush == "mssql" || $jush == "sqlite" ? '|\\[' : '')) . '|/\\*|-- |#'; //! ` and # not everywhere $total_start = explode(" ", microtime()); + parse_str($_COOKIE["adminer_export"], $adminer_export); + $dump_format = $adminer->dumpFormat(); + unset($dump_format["sql"]); while ($query != "") { if (!$offset && $jush == "sql" && preg_match('~^\\s*DELIMITER\\s+(.+)~i', $query, $match)) { $delimiter = $match[1]; @@ -102,14 +112,26 @@ if (!$error && $_POST) { $print = ""; } select($result, $connection2); + echo "
\n"; echo "

" . ($result->num_rows ? lang('%d row(s)', $result->num_rows) : "") . $time; + $id = "export-$commands"; + $export = ", " . lang('Export') . "" + ; if ($connection2 && preg_match("~^($space|\\()*SELECT\\b~isU", $q) && ($explain = explain($connection2, $q))) { $id = "explain-$commands"; - echo ", EXPLAIN\n"; + echo ", EXPLAIN$export\n"; echo "

\n"; + } else { + echo "$export\n"; } + echo "
\n"; } $start = $end; } while ($connection->next_result());