bug #1567316, rename a db containing a view
This commit is contained in:
@@ -5,6 +5,10 @@ phpMyAdmin - ChangeLog
|
|||||||
$Id$
|
$Id$
|
||||||
$Source$
|
$Source$
|
||||||
|
|
||||||
|
2006-10-18 Marc Delisle <lem9@users.sourceforge.net>
|
||||||
|
* db_operations.php, libraries/Table.class.php: bug #1567316,
|
||||||
|
renaming a db containing a view
|
||||||
|
|
||||||
2006-10-10 Michal Čihař <michal@cihar.com>
|
2006-10-10 Michal Čihař <michal@cihar.com>
|
||||||
* Documentation.html: Sync with trunk.
|
* Documentation.html: Sync with trunk.
|
||||||
|
|
||||||
|
@@ -52,7 +52,18 @@ if (isset($db) &&
|
|||||||
}
|
}
|
||||||
|
|
||||||
$tables_full = PMA_DBI_get_tables_full($db);
|
$tables_full = PMA_DBI_get_tables_full($db);
|
||||||
|
$views = array();
|
||||||
foreach ($tables_full as $table => $tmp) {
|
foreach ($tables_full as $table => $tmp) {
|
||||||
|
// to be able to rename a db containing views, we
|
||||||
|
// first collect in $views all the views we find and we
|
||||||
|
// will handle them after the tables; however, this
|
||||||
|
// does not support the case when a view is based on a view
|
||||||
|
|
||||||
|
if (PMA_Table::isView($db, $table)) {
|
||||||
|
$views[] = $table;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$back = $sql_query;
|
$back = $sql_query;
|
||||||
$sql_query = '';
|
$sql_query = '';
|
||||||
|
|
||||||
@@ -83,9 +94,16 @@ if (isset($db) &&
|
|||||||
}
|
}
|
||||||
|
|
||||||
$sql_query = $back . $sql_query;
|
$sql_query = $back . $sql_query;
|
||||||
}
|
} // end (foreach)
|
||||||
unset($table);
|
unset($table);
|
||||||
|
|
||||||
|
// handle the views
|
||||||
|
foreach ($views as $view) {
|
||||||
|
PMA_Table::moveCopy($db, $view, $newname, $view,
|
||||||
|
'structure', $move, 'db_copy');
|
||||||
|
}
|
||||||
|
unset($view, $views);
|
||||||
|
|
||||||
// now that all tables exist, create all the accumulated constraints
|
// now that all tables exist, create all the accumulated constraints
|
||||||
if (isset($GLOBALS['add_constraints'])) {
|
if (isset($GLOBALS['add_constraints'])) {
|
||||||
// FIXME: this works with mysqli but not with mysql,
|
// FIXME: this works with mysqli but not with mysql,
|
||||||
|
@@ -502,7 +502,7 @@ class PMA_Table {
|
|||||||
/**
|
/**
|
||||||
* Copies or renames table
|
* Copies or renames table
|
||||||
* FIXME: use RENAME for move operations
|
* FIXME: use RENAME for move operations
|
||||||
* - works only if the databases are on the same filesystem,
|
* - would work only if the databases are on the same filesystem,
|
||||||
* how can we check that? try the operation and
|
* how can we check that? try the operation and
|
||||||
* catch an error?
|
* catch an error?
|
||||||
* - for views, only if MYSQL > 50013
|
* - for views, only if MYSQL > 50013
|
||||||
@@ -571,7 +571,21 @@ class PMA_Table {
|
|||||||
|
|
||||||
/* no need to PMA_backquote() */
|
/* no need to PMA_backquote() */
|
||||||
if (isset($target_for_view)) {
|
if (isset($target_for_view)) {
|
||||||
|
// this a view definition; we just found the first db name
|
||||||
|
// that follows DEFINER VIEW
|
||||||
|
// so change it for the new db name
|
||||||
$parsed_sql[$i]['data'] = $target_for_view;
|
$parsed_sql[$i]['data'] = $target_for_view;
|
||||||
|
// then we have to find all references to the source db
|
||||||
|
// and change them to the target db, ensuring we stay into
|
||||||
|
// the $parsed_sql limits
|
||||||
|
$last = $parsed_sql['len'] - 1;
|
||||||
|
$backquoted_source_db = PMA_backquote($source_db);
|
||||||
|
for (++$i; $i <= $last; $i++) {
|
||||||
|
if ($parsed_sql[$i]['type'] == 'quote_backtick' && $parsed_sql[$i]['data'] == $backquoted_source_db) {
|
||||||
|
$parsed_sql[$i]['data'] = $target_for_view;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset($last,$backquoted_source_db);
|
||||||
} else {
|
} else {
|
||||||
$parsed_sql[$i]['data'] = $target;
|
$parsed_sql[$i]['data'] = $target;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user