Export Output in select.inc.php
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@447 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
ec23248c51
commit
9890b6c22d
53
dump.inc.php
53
dump.inc.php
|
@ -75,22 +75,24 @@ function dump($db, $style) {
|
|||
echo ($_POST["format"] != "csv" ? "USE " . idf_escape($db) . ";\n" : "");
|
||||
if (!strlen($_GET["db"])) {
|
||||
$views = array();
|
||||
$result = $mysql->query("SHOW TABLE STATUS");
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
if (isset($row["Engine"])) {
|
||||
if ($_POST["format"] == "csv") {
|
||||
ob_start();
|
||||
if ($_POST["tables"][0] || $_POST["data"][0]) {
|
||||
$result = $mysql->query("SHOW TABLE STATUS");
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
if (isset($row["Engine"])) {
|
||||
if ($_POST["format"] == "csv") {
|
||||
ob_start();
|
||||
}
|
||||
dump_table($row["Name"], $_POST["tables"][0]);
|
||||
dump_data($row["Name"], $_POST["data"][0]);
|
||||
if ($_POST["format"] == "csv") {
|
||||
echo tar_file("$db/$row[Name].csv", ob_get_clean());
|
||||
}
|
||||
} else {
|
||||
$views[] = $row["Name"];
|
||||
}
|
||||
dump_table($row["Name"], $_POST["tables"][0]);
|
||||
dump_data($row["Name"], $_POST["data"][0]);
|
||||
if ($_POST["format"] == "csv") {
|
||||
echo tar_file("$db/$row[Name].csv", ob_get_clean());
|
||||
}
|
||||
} else {
|
||||
$views[] = $row["Name"];
|
||||
}
|
||||
$result->free();
|
||||
}
|
||||
$result->free();
|
||||
if ($_POST["format"] != "csv") {
|
||||
foreach ($views as $view) {
|
||||
dump_table($view, $_POST["tables"][0]);
|
||||
|
@ -112,10 +114,7 @@ function tar_file($filename, $contents) {
|
|||
}
|
||||
|
||||
if ($_POST) {
|
||||
$filename = (strlen($_GET["db"]) ? preg_replace('~[^a-z0-9_]~i', '-', (strlen($_GET["dump"]) ? $_GET["dump"] : $_GET["db"])) : "dump");
|
||||
$ext = ($_POST["format"] == "sql" ? "sql" : (!strlen($_GET["db"]) || count(array_filter($_POST["tables"]) + array_filter($_POST["data"])) > 1 ? "tar" : "csv"));
|
||||
header("Content-Type: " . ($ext == "tar" ? "application/x-tar" : ($ext == "sql" || $_POST["output"] != "file" ? "text/plain" : "text/csv")) . "; charset=utf-8");
|
||||
header("Content-Disposition: " . ($_POST["output"] == "file" ? "attachment" : "inline") . "; filename=$filename.$ext");
|
||||
$ext = dump_headers((strlen($_GET["dump"]) ? $_GET["dump"] : $_GET["db"]), (!strlen($_GET["db"]) || count(array_filter($_POST["tables"]) + array_filter($_POST["data"])) > 1));
|
||||
if ($_POST["format"] != "csv") {
|
||||
$max_packet = 16777216;
|
||||
echo "SET NAMES utf8;\n";
|
||||
|
@ -133,14 +132,16 @@ if ($_POST) {
|
|||
}
|
||||
if (strlen($_GET["db"])) {
|
||||
foreach ($_POST["tables"] as $key => $style) {
|
||||
$table = bracket_escape($key, "back");
|
||||
if ($ext == "tar") {
|
||||
ob_start();
|
||||
}
|
||||
dump_table($table, $style);
|
||||
dump_data($table, $_POST["data"][$key]);
|
||||
if ($ext == "tar") {
|
||||
echo tar_file("$table.csv", ob_get_clean());
|
||||
if ($style || $_POST["data"][$key]) {
|
||||
$table = bracket_escape($key, "back");
|
||||
if ($ext == "tar") {
|
||||
ob_start();
|
||||
}
|
||||
dump_table($table, $style);
|
||||
dump_data($table, $_POST["data"][$key]);
|
||||
if ($ext == "tar") {
|
||||
echo tar_file("$table.csv", ob_get_clean());
|
||||
}
|
||||
}
|
||||
}
|
||||
dump_routines($_GET["db"]);
|
||||
|
@ -163,7 +164,7 @@ function check(td, name, value) {
|
|||
</script>
|
||||
|
||||
<form action="" method="post">
|
||||
<p><?php echo lang('Output') . ": <select name='output'><option value='text'>" . lang('open') . "</option><option value='file'>" . lang('save') . "</option></select> " . $dump_options; ?></p>
|
||||
<p><?php echo $dump_options; ?></p>
|
||||
|
||||
<?php
|
||||
echo "<table border='1' cellspacing='0' cellpadding='2'>\n<thead><tr><th>" . lang('Database') . "</th>";
|
||||
|
|
|
@ -56,5 +56,13 @@ function dump_data($table, $style, $from = "") {
|
|||
}
|
||||
}
|
||||
|
||||
$dump_options = lang('Format') . ": <select name='format'><option value='sql'>" . lang('SQL') . "</option><option value='csv'>" . lang('CSV') . "</option></select>";
|
||||
function dump_headers($identifier, $multi_table = false) {
|
||||
$filename = (strlen($identifier) ? preg_replace('~[^a-z0-9_]~i', '-', $identifier) : "dump");
|
||||
$ext = ($_POST["format"] == "sql" ? "sql" : ($multi_table ? "tar" : "csv"));
|
||||
header("Content-Type: " . ($ext == "tar" ? "application/x-tar" : ($ext == "sql" || $_POST["output"] != "file" ? "text/plain" : "text/csv")) . "; charset=utf-8");
|
||||
header("Content-Disposition: " . ($_POST["output"] == "file" ? "attachment" : "inline") . "; filename=$filename.$ext");
|
||||
return $ext;
|
||||
}
|
||||
|
||||
$dump_options = lang('Output') . ": <select name='output'><option value='text'>" . lang('open') . "</option><option value='file'>" . lang('save') . "</option></select> " . lang('Format') . ": <select name='format'><option value='sql'>" . lang('SQL') . "</option><option value='csv'>" . lang('CSV') . "</option></select>";
|
||||
$max_packet = 0;
|
||||
|
|
|
@ -172,4 +172,6 @@ $translations = array(
|
|||
'Tables' => 'Tabulky',
|
||||
'Structure' => 'Struktura',
|
||||
'Data' => 'Data',
|
||||
'Export selected' => 'Exportovat označené',
|
||||
'Export result' => 'Exportovat výsledek',
|
||||
);
|
||||
|
|
|
@ -64,8 +64,7 @@ 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"));
|
||||
dump_headers($_GET["select"]);
|
||||
}
|
||||
if (isset($_POST["truncate"])) {
|
||||
$result = $mysql->query($where ? "DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : "TRUNCATE " . idf_escape($_GET["select"]));
|
||||
|
|
Loading…
Reference in a new issue