Skip to content

Commit

Permalink
MySQL: Allow moving views to other DB and renaming DB with views (bug…
Browse files Browse the repository at this point in the history
… #783)
  • Loading branch information
vrana committed Feb 12, 2021
1 parent 5a1498d commit e9e61fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
19 changes: 17 additions & 2 deletions adminer/drivers/mysql.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -797,12 +797,27 @@ function drop_tables($tables) {
* @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
Expand Down
1 change: 1 addition & 0 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit e9e61fc

Please sign in to comment.