]> git.joonet.de Git - adminer.git/commitdiff
MySQL: Allow moving views to other DB and renaming DB with views (bug #783)
authorJakub Vrana <jakub@vrana.cz>
Fri, 12 Feb 2021 10:49:35 +0000 (11:49 +0100)
committerJakub Vrana <jakub@vrana.cz>
Fri, 12 Feb 2021 10:49:35 +0000 (11:49 +0100)
adminer/drivers/mysql.inc.php
changes.txt

index d77289ecb19a14110ad84fd5bd6b25d0f6786883..a2728941922a91b1584e9091e9777a4775a82103 100644 (file)
@@ -797,12 +797,27 @@ if (!defined("DRIVER")) {
        * @return bool
        */
        function move_tables($tables, $views, $target) {
+               global $connection;
                $rename = array();
-               foreach (array_merge($tables, $views) as $table) { // views will report SQL error
+               foreach ($tables as $table) {
                        $rename[] = table($table) . " TO " . idf_escape($target) . "." . table($table);
                }
-               return queries("RENAME TABLE " . implode(", ", $rename));
+               if (!$rename || queries("RENAME TABLE " . implode(", ", $rename))) {
+                       $definitions = array();
+                       foreach ($views as $table) {
+                               $definitions[table($table)] = view($table);
+                       }
+                       $connection->select_db($target);
+                       $db = idf_escape(DB);
+                       foreach ($definitions as $name => $view) {
+                               if (!queries("CREATE VIEW $name AS " . str_replace(" $db.", " ", $view["select"])) || !queries("DROP VIEW $db.$name")) {
+                                       return false;
+                               }
+                       }
+                       return true;
+               }
                //! move triggers
+               return false;
        }
 
        /** Copy tables to other schema
index d5211cc16ea66a5d900ce54b8b7055f798d4fac2..5c6929de88bf4fb59e34b6ba2faada99eec062b6 100644 (file)
@@ -1,5 +1,6 @@
 Adminer 4.8.1-dev:
 Fix more PHP 8 warnings (bug #781)
+MySQL: Allow moving views to other DB and renaming DB with views (bug #783)
 
 Adminer 4.8.0 (released 2021-02-10):
 Support function default values in insert (bug #713)