From ec23248c51b70b72432aaff66498af584697dcc2 Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Sat, 16 Aug 2008 21:15:46 +0000 Subject: [PATCH] Exportable select git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@446 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- dump.inc.php | 5 +---- export.inc.php | 7 +++++-- select.inc.php | 31 +++++++++++++++++++++++-------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/dump.inc.php b/dump.inc.php index e469e9da..c9da9986 100644 --- a/dump.inc.php +++ b/dump.inc.php @@ -163,10 +163,7 @@ function check(td, name, value) {
-

-: -: -

+

" . $dump_options; ?>

\n" . lang('Database') . ""; diff --git a/export.inc.php b/export.inc.php index 84026693..070f0132 100644 --- a/export.inc.php +++ b/export.inc.php @@ -8,13 +8,13 @@ function dump_csv($row) { echo implode(",", $row) . "\n"; } -function dump_data($table, $style) { +function dump_data($table, $style, $from = "") { global $mysql, $max_packet; if ($style) { if ($_POST["format"] != "csv" && $style == "TRUNCATE, INSERT") { echo "TRUNCATE " . idf_escape($table) . ";\n"; } - $result = $mysql->query("SELECT * FROM " . idf_escape($table)); //! enum and set as numbers, binary as _binary, microtime + $result = $mysql->query("SELECT * " . ($from ? $from : "FROM " . idf_escape($table))); //! enum and set as numbers, binary as _binary, microtime if ($result) { $insert = "INSERT INTO " . idf_escape($table) . " VALUES "; $length = 0; @@ -55,3 +55,6 @@ function dump_data($table, $style) { echo "\n"; } } + +$dump_options = lang('Format') . ": "; +$max_packet = 0; diff --git a/select.inc.php b/select.inc.php index f5075103..4353c1bd 100644 --- a/select.inc.php +++ b/select.inc.php @@ -1,4 +1,6 @@ ", "<=", ">=", "!=", "LIKE", "REGEXP", "IN", "IS NULL"); @@ -61,22 +63,31 @@ $from = "FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" if ($_POST && !$error) { $result = true; $deleted = 0; + if ($_POST["export"] || $_POST["export_result"]) { + header("Content-Type: text/plain; charset=utf-8"); + header("Content-Disposition: inline; filename=" . preg_replace('~[^a-z0-9_]~i', '-', $_GET["select"]) . "." . ($_POST["format"] == "sql" ? "sql" : "csv")); + } if (isset($_POST["truncate"])) { $result = $mysql->query($where ? "DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : "TRUNCATE " . idf_escape($_GET["select"])); $deleted = $mysql->affected_rows; + } elseif ($_POST["export_result"]) { + dump_data($_GET["select"], "INSERT", ($where ? "FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : "")); } elseif (is_array($_POST["delete"])) { foreach ($_POST["delete"] as $val) { parse_str($val, $delete); - $result = $mysql->query("DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where($delete)) . " LIMIT 1"); - if (!$result) { - break; + if ($_POST["export"]) { + dump_data($_GET["select"], "INSERT", "FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where($delete)) . " LIMIT 1"); + } else { + $result = $mysql->query("DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where($delete)) . " LIMIT 1"); + if (!$result) { + break; + } + $deleted += $mysql->affected_rows; } - $deleted += $mysql->affected_rows; } } elseif ($_POST["delete_selected"]) { - if (!$_GET["page"]) { - $result = $mysql->query("DELETE $from"); - $deleted = $mysql->affected_rows; + if ($_POST["export"]) { + dump_data($_GET["select"], "INSERT", $from); } else { $result1 = $mysql->query("SELECT * $from"); while ($row1 = $result1->fetch_assoc()) { @@ -90,6 +101,9 @@ if ($_POST && !$error) { $result1->free(); } } + if ($_POST["export"] || $_POST["export_result"]) { + exit; + } if ($result) { redirect(remove_from_uri("page"), lang('%d item(s) have been deleted.', $deleted)); } @@ -264,7 +278,8 @@ for (var i=0; > i; i++) { echo "\n"; } echo "\n"; - echo "

" . (count($group) == count($select) ? " " : "") . "

\n"; + echo "
" . lang('Delete') . "" . (count($group) == count($select) ? " " : "") . "
\n"; + echo "
" . lang('Export') . "$dump_options " . (count($group) == count($select) ? " " : "") . "
\n"; //! output, format echo "
\n"; if (intval($limit) && ($found_rows = $mysql->result($mysql->query(count($group) < count($select) ? " SELECT FOUND_ROWS()" : "SELECT COUNT(*) FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "")))) > $limit) { $max_page = floor(($found_rows - 1) / $limit);