MySQL: Allow moving views to other DB and renaming DB with views (bug #783)

This commit is contained in:
Jakub Vrana 2021-02-12 11:49:35 +01:00
parent 5a1498d160
commit e9e61fce26
2 changed files with 18 additions and 2 deletions

View 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

View 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)