From 63c400f95d26f543c7b5a2c87ce5bb54acad42db Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Mon, 29 Apr 2013 15:42:39 -0700 Subject: [PATCH] Allow exporting views dependent on each other (bug #3459151) --- adminer/dump.inc.php | 36 ++++++++++++++++----------------- adminer/include/adminer.inc.php | 22 +++++++++++++------- changes.txt | 1 + 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/adminer/dump.inc.php b/adminer/dump.inc.php index 8b2dc486..5d456d2a 100644 --- a/adminer/dump.inc.php +++ b/adminer/dump.inc.php @@ -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"); diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 02bd4a97..30e5ea19 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -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"; diff --git a/changes.txt b/changes.txt index 79124ff4..417db3cf 100644 --- a/changes.txt +++ b/changes.txt @@ -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