Simplify export
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@637 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
5ce6201aa3
commit
f507c81863
59
dump.inc.php
59
dump.inc.php
|
@ -10,7 +10,7 @@ function tar_file($filename, $contents) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_POST) {
|
if ($_POST) {
|
||||||
$ext = dump_headers((strlen($_GET["dump"]) ? $_GET["dump"] : $_GET["db"]), (!strlen($_GET["db"]) || count(array_filter((array) $_POST["tables"]) + array_filter((array) $_POST["data"])) > 1));
|
$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") {
|
if ($_POST["format"] != "csv") {
|
||||||
$max_packet = 1048576; // default, minimum is 1024
|
$max_packet = 1048576; // default, minimum is 1024
|
||||||
echo "SET NAMES utf8;\n";
|
echo "SET NAMES utf8;\n";
|
||||||
|
@ -19,15 +19,15 @@ if ($_POST) {
|
||||||
echo "\n";
|
echo "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($_POST["databases"] as $db => $style) {
|
$style = $_POST["db_style"];
|
||||||
$db = bracket_escape($db, "back");
|
foreach ((strlen($_GET["db"]) ? array($_GET["db"]) : (array) $_POST["databases"]) as $db) {
|
||||||
if ($dbh->select_db($db)) {
|
if ($dbh->select_db($db)) {
|
||||||
if ($_POST["format"] != "csv" && ereg('CREATE', $style) && ($result = $dbh->query("SHOW CREATE DATABASE " . idf_escape($db)))) {
|
if ($_POST["format"] != "csv" && ereg('CREATE', $style) && ($result = $dbh->query("SHOW CREATE DATABASE " . idf_escape($db)))) {
|
||||||
if ($style == "DROP, CREATE") {
|
if ($style == "DROP+CREATE") {
|
||||||
echo "DROP DATABASE IF EXISTS " . idf_escape($db) . ";\n";
|
echo "DROP DATABASE IF EXISTS " . idf_escape($db) . ";\n";
|
||||||
}
|
}
|
||||||
$create = $dbh->result($result, 1);
|
$create = $dbh->result($result, 1);
|
||||||
echo ($style == "CREATE, ALTER" ? preg_replace('~^CREATE DATABASE ~', '\\0IF NOT EXISTS ', $create) : $create) . ";\n";
|
echo ($style == "CREATE+ALTER" ? preg_replace('~^CREATE DATABASE ~', '\\0IF NOT EXISTS ', $create) : $create) . ";\n";
|
||||||
$result->free();
|
$result->free();
|
||||||
}
|
}
|
||||||
if ($style && $_POST["format"] != "csv") {
|
if ($style && $_POST["format"] != "csv") {
|
||||||
|
@ -52,35 +52,38 @@ if ($_POST) {
|
||||||
echo ($out ? "DELIMITER ;;\n\n$out" . "DELIMITER ;\n\n" : "");
|
echo ($out ? "DELIMITER ;;\n\n$out" . "DELIMITER ;\n\n" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($style || strlen($_GET["db"])) && (array_filter((array) $_POST["tables"]) || array_filter((array) $_POST["data"]))) {
|
if ($_POST["table_style"] || $_POST["data_style"]) {
|
||||||
$views = array();
|
$views = array();
|
||||||
$result = $dbh->query("SHOW TABLE STATUS");
|
$result = $dbh->query("SHOW TABLE STATUS");
|
||||||
while ($row = $result->fetch_assoc()) {
|
while ($row = $result->fetch_assoc()) {
|
||||||
$key = (strlen($_GET["db"]) ? bracket_escape($row["Name"]) : 0);
|
$table = (!strlen($_GET["db"]) || in_array($row["Name"], (array) $_POST["tables"]));
|
||||||
if ($_POST["tables"][$key] || $_POST["data"][$key]) {
|
$data = (!strlen($_GET["db"]) || in_array($row["Name"], (array) $_POST["data"]));
|
||||||
|
if ($table || $data) {
|
||||||
if (isset($row["Engine"])) {
|
if (isset($row["Engine"])) {
|
||||||
if ($ext == "tar") {
|
if ($ext == "tar") {
|
||||||
ob_start();
|
ob_start();
|
||||||
}
|
}
|
||||||
dump_table($row["Name"], $_POST["tables"][$key]);
|
dump_table($row["Name"], ($table ? $_POST["table_style"] : ""));
|
||||||
dump_data($row["Name"], $_POST["data"][$key]);
|
if ($data) {
|
||||||
|
dump_data($row["Name"], $_POST["data_style"]);
|
||||||
|
}
|
||||||
if ($ext == "tar") {
|
if ($ext == "tar") {
|
||||||
echo tar_file((strlen($_GET["db"]) ? "" : "$db/") . "$row[Name].csv", ob_get_clean());
|
echo tar_file((strlen($_GET["db"]) ? "" : "$db/") . "$row[Name].csv", ob_get_clean());
|
||||||
} elseif ($_POST["format"] != "csv") {
|
} elseif ($_POST["format"] != "csv") {
|
||||||
echo "\n";
|
echo "\n";
|
||||||
}
|
}
|
||||||
} elseif ($_POST["format"] != "csv") {
|
} elseif ($_POST["format"] != "csv") {
|
||||||
$views[$row["Name"]] = $_POST["tables"][$key];
|
$views[] = $row["Name"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$result->free();
|
$result->free();
|
||||||
foreach ($views as $view => $style1) {
|
foreach ($views as $view) {
|
||||||
dump_table($view, $style1, true);
|
dump_table($view, $_POST["table_style"], true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($dbh->server_info >= 5 && $style == "CREATE, ALTER" && $_POST["format"] != "csv") {
|
if ($style == "CREATE+ALTER" && $_POST["format"] != "csv") {
|
||||||
$query = "SELECT TABLE_NAME, ENGINE, TABLE_COLLATION, TABLE_COMMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE()";
|
$query = "SELECT TABLE_NAME, ENGINE, TABLE_COLLATION, TABLE_COMMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE()";
|
||||||
?>
|
?>
|
||||||
DELIMITER ;;
|
DELIMITER ;;
|
||||||
|
@ -131,23 +134,30 @@ page_header(lang('Export'), "", (strlen($_GET["export"]) ? array("table" => $_GE
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
<table border="0">
|
<table cellspacing="0">
|
||||||
<?php
|
<?php
|
||||||
|
$db_style = array('USE', 'DROP+CREATE', 'CREATE');
|
||||||
|
$table_style = array('DROP+CREATE', 'CREATE');
|
||||||
|
$data_style = array('TRUNCATE+INSERT', 'INSERT', 'INSERT+UPDATE');
|
||||||
|
if ($dbh->server_info >= 5) {
|
||||||
|
$db_style[] = 'CREATE+ALTER';
|
||||||
|
$table_style[] = 'CREATE+ALTER';
|
||||||
|
}
|
||||||
echo "<tr><th>" . lang('Output') . "</th><td>$dump_output</td></tr>\n";
|
echo "<tr><th>" . lang('Output') . "</th><td>$dump_output</td></tr>\n";
|
||||||
echo "<tr><th>" . lang('Format') . "</th><td>$dump_format</td></tr>\n";
|
echo "<tr><th>" . lang('Format') . "</th><td>$dump_format</td></tr>\n";
|
||||||
echo "<tr><th>" . lang('Database') . "</th><td><select name=''><option></option>" . optionlist(array('USE', 'DROP, CREATE', 'CREATE', 'CREATE, ALTER'), (strlen($_GET["db"]) ? '' : 'CREATE')) . "</select></td></tr>\n";
|
echo "<tr><th>" . lang('Database') . "</th><td><select name='db_style'><option></option>" . optionlist($db_style, (strlen($_GET["db"]) ? '' : 'CREATE')) . "</select></td></tr>\n";
|
||||||
echo "<tr><th>" . lang('Tables') . "</th><td><select name=''><option></option>" . optionlist(array('DROP, CREATE', 'CREATE', 'CREATE, ALTER'), 'DROP, CREATE') . "</select></td></tr>\n";
|
echo "<tr><th>" . lang('Tables') . "</th><td><select name='table_style'><option></option>" . optionlist($table_style, 'DROP+CREATE') . "</select></td></tr>\n";
|
||||||
echo "<tr><th>" . lang('Data') . "</th><td><select name=''><option></option>" . optionlist(array('TRUNCATE, INSERT', 'INSERT', 'UPDATE'), 'INSERT') . "</select></td></tr>\n"; // INSERT INTO ... ON DUPLICATE KEY UPDATE
|
echo "<tr><th>" . lang('Data') . "</th><td><select name='data_style'><option></option>" . optionlist($data_style, 'INSERT') . "</select></td></tr>\n";
|
||||||
?>
|
?>
|
||||||
</table>
|
</table>
|
||||||
<p><input type="submit" value="<?php echo lang('Export'); ?>" /></p>
|
<p><input type="submit" value="<?php echo lang('Export'); ?>" /></p>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
if (!strlen($_GET["db"])) {
|
if (!strlen($_GET["db"])) {
|
||||||
echo "<table cellspacing='0'>\n<thead><tr><th><input type='checkbox' id='check-databases' onclick='dump_check(this, /^databases\\[/);' checked='checked' />" . lang('Database') . "</th></tr></thead>\n";
|
echo "<table cellspacing='0'>\n<thead><tr><th align='left'><label><input type='checkbox' id='check-databases' checked='checked' onclick='dump_check(this, /^databases\\[/);' />" . lang('Database') . "</label></th></tr></thead>\n";
|
||||||
foreach (get_databases() as $db) {
|
foreach (get_databases() as $db) {
|
||||||
if ($db != "information_schema" || $dbh->server_info < 5) {
|
if ($db != "information_schema" || $dbh->server_info < 5) {
|
||||||
echo '<tr><td><label><input type="checkbox" name="databases[' . htmlspecialchars(bracket_escape($db)) . ']" checked="checked" value="1" onclick="dump_uncheck(\'check-databases\');" />' . htmlspecialchars($db) . "</label></td></tr>\n"; //! uncheck all
|
echo '<tr><td><label><input type="checkbox" name="databases[]" value="' . htmlspecialchars($db) . '" checked="checked" onclick="dump_uncheck(\'check-databases\');" />' . htmlspecialchars($db) . "</label></td></tr>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo "</table>\n";
|
echo "</table>\n";
|
||||||
|
@ -156,22 +166,21 @@ if (!strlen($_GET["db"])) {
|
||||||
if (strlen($_GET["db"])) {
|
if (strlen($_GET["db"])) {
|
||||||
$checked = (strlen($_GET["dump"]) ? "" : " checked='checked'");
|
$checked = (strlen($_GET["dump"]) ? "" : " checked='checked'");
|
||||||
echo "<table cellspacing='0'>\n<thead><tr>";
|
echo "<table cellspacing='0'>\n<thead><tr>";
|
||||||
echo "<th style='text-align: left;'><label><input type='checkbox' id='check-tables' onclick='dump_check(this, /^tables\\[/);'$checked />" . lang('Tables') . "</label></th>";
|
echo "<th align='left'><label><input type='checkbox' id='check-tables'$checked onclick='dump_check(this, /^tables\\[/);' />" . lang('Tables') . "</label></th>";
|
||||||
echo "<th><label><input type='checkbox' id='check-data' onclick='dump_check(this, /^data\\[/);'$checked />" . lang('Data') . "</label></th>";
|
echo "<th align='right'><label>" . lang('Data') . "<input type='checkbox' id='check-data'$checked onclick='dump_check(this, /^data\\[/);' /></label></th>";
|
||||||
echo "</tr></thead>\n";
|
echo "</tr></thead>\n";
|
||||||
$views = "";
|
$views = "";
|
||||||
$result = $dbh->query("SHOW TABLE STATUS");
|
$result = $dbh->query("SHOW TABLE STATUS");
|
||||||
while ($row = $result->fetch_assoc()) {
|
while ($row = $result->fetch_assoc()) {
|
||||||
$checked = (strlen($_GET["dump"]) && $row["Name"] != $_GET["dump"] ? '' : " checked='checked'");
|
$checked = (strlen($_GET["dump"]) && $row["Name"] != $_GET["dump"] ? '' : " checked='checked'");
|
||||||
$print = '<tr><td><label><input type="checkbox" name="tables[' . htmlspecialchars(bracket_escape($row["Name"])) . "]\"$checked value='1' onclick=\"dump_uncheck('check-tables');\" />" . htmlspecialchars($row["Name"]) . "</label></td>"; //! uncheck all
|
$print = '<tr><td><label><input type="checkbox" name="tables[]" value="' . htmlspecialchars($row["Name"]) . "\"$checked onclick=\"dump_uncheck('check-tables');\" />" . htmlspecialchars($row["Name"]) . "</label></td>";
|
||||||
if (!$row["Engine"]) {
|
if (!$row["Engine"]) {
|
||||||
$views .= "$print</tr>\n";
|
$views .= "$print</tr>\n";
|
||||||
} else {
|
} else {
|
||||||
echo $print . '<td><input type="checkbox" name="data[' . htmlspecialchars(bracket_escape($row["Name"])) . "]\"$checked value='1' onclick=\"dump_uncheck('check-data');\" /></td></tr>\n";
|
echo "$print<td align='right'><label>" . ($row["Engine"] == "InnoDB" && $row["Rows"] ? lang('~ %s', $row["Rows"]) : $row["Rows"]) . '<input type="checkbox" name="data[]" value="' . htmlspecialchars($row["Name"]) . "\"$checked onclick=\"dump_uncheck('check-data');\" /></label></td></tr>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo "$views</table>\n";
|
echo "$views</table>\n";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<p><input type="submit" value="<?php echo lang('Export'); ?>" /></p>
|
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -18,15 +18,14 @@ function dump_table($table, $style, $is_view = false) {
|
||||||
} elseif ($style) {
|
} elseif ($style) {
|
||||||
$result = $dbh->query("SHOW CREATE TABLE " . idf_escape($table));
|
$result = $dbh->query("SHOW CREATE TABLE " . idf_escape($table));
|
||||||
if ($result) {
|
if ($result) {
|
||||||
if ($style == "DROP, CREATE") {
|
if ($style == "DROP+CREATE") {
|
||||||
echo "DROP " . ($is_view ? "VIEW" : "TABLE") . " IF EXISTS " . idf_escape($table) . ";\n";
|
echo "DROP " . ($is_view ? "VIEW" : "TABLE") . " IF EXISTS " . idf_escape($table) . ";\n";
|
||||||
}
|
}
|
||||||
$create = $dbh->result($result, 1);
|
$create = $dbh->result($result, 1);
|
||||||
$result->free();
|
$result->free();
|
||||||
echo ($style != "CREATE, ALTER" ? $create : ($is_view ? substr_replace($create, " OR REPLACE", 6, 0) : substr_replace($create, " IF NOT EXISTS", 12, 0))) . ";\n\n";
|
echo ($style != "CREATE+ALTER" ? $create : ($is_view ? substr_replace($create, " OR REPLACE", 6, 0) : substr_replace($create, " IF NOT EXISTS", 12, 0))) . ";\n\n";
|
||||||
}
|
}
|
||||||
if ($dbh->server_info >= 5) {
|
if ($style == "CREATE+ALTER" && !$is_view) {
|
||||||
if ($style == "CREATE, ALTER" && !$is_view) {
|
|
||||||
$query = "SELECT COLUMN_NAME, COLUMN_DEFAULT, IS_NULLABLE, COLLATION_NAME, COLUMN_TYPE, EXTRA, COLUMN_COMMENT FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = '" . $dbh->escape_string($table) . "' ORDER BY ORDINAL_POSITION";
|
$query = "SELECT COLUMN_NAME, COLUMN_DEFAULT, IS_NULLABLE, COLLATION_NAME, COLUMN_TYPE, EXTRA, COLUMN_COMMENT FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = '" . $dbh->escape_string($table) . "' ORDER BY ORDINAL_POSITION";
|
||||||
?>
|
?>
|
||||||
DELIMITER ;;
|
DELIMITER ;;
|
||||||
|
@ -103,6 +102,7 @@ DROP PROCEDURE phpminadmin_alter;
|
||||||
//! indexes
|
//! indexes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($dbh->server_info >= 5) {
|
||||||
$result = $dbh->query("SHOW TRIGGERS LIKE '" . $dbh->escape_string(addcslashes($table, "%_")) . "'");
|
$result = $dbh->query("SHOW TRIGGERS LIKE '" . $dbh->escape_string(addcslashes($table, "%_")) . "'");
|
||||||
if ($result->num_rows) {
|
if ($result->num_rows) {
|
||||||
echo "DELIMITER ;;\n\n";
|
echo "DELIMITER ;;\n\n";
|
||||||
|
@ -119,7 +119,7 @@ DROP PROCEDURE phpminadmin_alter;
|
||||||
function dump_data($table, $style, $from = "") {
|
function dump_data($table, $style, $from = "") {
|
||||||
global $dbh, $max_packet;
|
global $dbh, $max_packet;
|
||||||
if ($style) {
|
if ($style) {
|
||||||
if ($_POST["format"] != "csv" && $style == "TRUNCATE, INSERT") {
|
if ($_POST["format"] != "csv" && $style == "TRUNCATE+INSERT") {
|
||||||
echo "TRUNCATE " . idf_escape($table) . ";\n";
|
echo "TRUNCATE " . idf_escape($table) . ";\n";
|
||||||
}
|
}
|
||||||
$result = $dbh->query("SELECT * " . ($from ? $from : "FROM " . idf_escape($table))); //! enum and set as numbers, binary as _binary, microtime
|
$result = $dbh->query("SELECT * " . ($from ? $from : "FROM " . idf_escape($table))); //! enum and set as numbers, binary as _binary, microtime
|
||||||
|
@ -129,7 +129,7 @@ function dump_data($table, $style, $from = "") {
|
||||||
while ($row = $result->fetch_assoc()) {
|
while ($row = $result->fetch_assoc()) {
|
||||||
if ($_POST["format"] == "csv") {
|
if ($_POST["format"] == "csv") {
|
||||||
dump_csv($row);
|
dump_csv($row);
|
||||||
} elseif ($style == "UPDATE") {
|
} elseif ($style == "INSERT+UPDATE") {
|
||||||
$set = array();
|
$set = array();
|
||||||
foreach ($row as $key => $val) {
|
foreach ($row as $key => $val) {
|
||||||
$row[$key] = (isset($val) ? "'" . $dbh->escape_string($val) . "'" : "NULL");
|
$row[$key] = (isset($val) ? "'" . $dbh->escape_string($val) . "'" : "NULL");
|
||||||
|
@ -155,7 +155,7 @@ function dump_data($table, $style, $from = "") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($_POST["format"] != "csv" && $style != "UPDATE" && $result->num_rows) {
|
if ($_POST["format"] != "csv" && $style != "INSERT+UPDATE" && $result->num_rows) {
|
||||||
echo ";\n";
|
echo ";\n";
|
||||||
}
|
}
|
||||||
$result->free();
|
$result->free();
|
||||||
|
|
Loading…
Reference in a new issue