Allow exporting views dependent on each other (bug #3459151)

This commit is contained in:
Jakub Vrana 2013-04-29 15:42:39 -07:00
parent 34adf46293
commit 63c400f95d
3 changed files with 33 additions and 26 deletions

View file

@ -70,30 +70,28 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
$table = (DB == "" || in_array($name, (array) $_POST["tables"]));
$data = (DB == "" || in_array($name, (array) $_POST["data"]));
if ($table || $data) {
if (!is_view($table_status)) {
if ($ext == "tar") {
ob_start();
}
$adminer->dumpTable($name, ($table ? $_POST["table_style"] : ""));
if ($data) {
$fields = fields($name);
$adminer->dumpData($name, $_POST["data_style"], "SELECT *" . convert_fields($fields, $fields) . " FROM " . table($name));
}
if ($is_sql && $_POST["triggers"] && $table && ($triggers = trigger_sql($name, $_POST["table_style"]))) {
echo "\nDELIMITER ;;\n$triggers\nDELIMITER ;\n";
}
if ($ext == "tar") {
echo tar_file((DB != "" ? "" : "$db/") . "$name.csv", ob_get_clean());
} elseif ($is_sql) {
echo "\n";
}
} elseif ($is_sql) {
if ($ext == "tar") {
ob_start();
}
$adminer->dumpTable($name, ($table ? $_POST["table_style"] : ""), (is_view($table_status) ? 2 : 0));
if (is_view($table_status)) {
$views[] = $name;
} elseif ($data) {
$fields = fields($name);
$adminer->dumpData($name, $_POST["data_style"], "SELECT *" . convert_fields($fields, $fields) . " FROM " . table($name));
}
if ($is_sql && $_POST["triggers"] && $table && ($triggers = trigger_sql($name, $_POST["table_style"]))) {
echo "\nDELIMITER ;;\n$triggers\nDELIMITER ;\n";
}
if ($ext == "tar") {
echo tar_file((DB != "" ? "" : "$db/") . "$name.csv", ob_get_clean());
} elseif ($is_sql) {
echo "\n";
}
}
}
foreach ($views as $view) {
$adminer->dumpTable($view, $_POST["table_style"], true);
$adminer->dumpTable($view, $_POST["table_style"], 1);
}
if ($ext == "tar") {
echo pack("x512");

View file

@ -590,22 +590,30 @@ username.form['auth[driver]'].onchange();
/** Export table structure
* @param string
* @param string
* @param bool
* @param int 0 table, 1 view, 2 temporary view table
* @return null prints data
*/
function dumpTable($table, $style, $is_view = false) {
function dumpTable($table, $style, $is_view = 0) {
if ($_POST["format"] != "sql") {
echo "\xef\xbb\xbf"; // UTF-8 byte order mark
if ($style) {
dump_csv(array_keys(fields($table)));
}
} elseif ($style) {
$create = create_sql($table, $_POST["auto_increment"]);
if ($create) {
if ($style == "DROP+CREATE") {
echo "DROP " . ($is_view ? "VIEW" : "TABLE") . " IF EXISTS " . table($table) . ";\n";
if ($is_view == 2) {
$fields = array();
foreach (fields($table) as $name => $field) {
$fields[] = idf_escape($name) . " $field[full_type]";
}
if ($is_view) {
$create = "CREATE TABLE " . table($table) . " (" . implode(", ", $fields) . ")";
} else {
$create = create_sql($table, $_POST["auto_increment"]);
}
if ($create) {
if ($style == "DROP+CREATE" || $is_view == 1) {
echo "DROP " . ($is_view == 2 ? "VIEW" : "TABLE") . " IF EXISTS " . table($table) . ";\n";
}
if ($is_view == 1) {
$create = remove_definer($create);
}
echo "$create;\n\n";

View file

@ -4,6 +4,7 @@ Print run time next to executed queries
Disable SQL export when applying functions in select
Allow using lang() in plugins (customization)
Remove bzip2 compression support
Allow exporting views dependent on each other (bug #3459151)
MySQL: Optimize create table page and Editor navigation
MySQL: Display bit type as binary number
MySQL: Improve export of binary data types