Permalink
Browse files

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

  • Loading branch information...
1 parent 34adf46 commit 63c400f95d26f543c7b5a2c87ce5bb54acad42db @vrana committed Apr 29, 2013
Showing with 32 additions and 25 deletions.
  1. +17 −19 adminer/dump.inc.php
  2. +14 −6 adminer/include/adminer.inc.php
  3. +1 −0 changes.txt
View
@@ -70,30 +70,28 @@
$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");
@@ -590,22 +590,30 @@ function dumpDatabase($db) {
/** 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 ($is_view == 2) {
+ $fields = array();
+ foreach (fields($table) as $name => $field) {
+ $fields[] = idf_escape($name) . " $field[full_type]";
+ }
+ $create = "CREATE TABLE " . table($table) . " (" . implode(", ", $fields) . ")";
+ } else {
+ $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 ($style == "DROP+CREATE" || $is_view == 1) {
+ echo "DROP " . ($is_view == 2 ? "VIEW" : "TABLE") . " IF EXISTS " . table($table) . ";\n";
}
- if ($is_view) {
+ if ($is_view == 1) {
$create = remove_definer($create);
}
echo "$create;\n\n";
View
@@ -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

0 comments on commit 63c400f

Please sign in to comment.