bug #1567316, renaming a db containing a view

This commit is contained in:
Marc Delisle
2006-10-18 13:03:57 +00:00
parent 034f80db3d
commit 6e7eba3d5b
3 changed files with 41 additions and 4 deletions

View File

@@ -5,6 +5,10 @@ phpMyAdmin - ChangeLog
$Id$ $Id$
$HeadURL$ $HeadURL$
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-18 Michal Čihař <michal@cihar.com> 2006-10-18 Michal Čihař <michal@cihar.com>
* libraries/transformations/text_plain__dateformat.inc.php, lang/*: * libraries/transformations/text_plain__dateformat.inc.php, lang/*:
Support displaying in UTC (RFE #1440386). Support displaying in UTC (RFE #1440386).

View File

@@ -52,7 +52,19 @@ 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
/**
* @todo support a view of a view
*/
if (PMA_Table::isView($db, $table)) {
$views[] = $table;
continue;
}
$back = $sql_query; $back = $sql_query;
$sql_query = ''; $sql_query = '';
@@ -83,9 +95,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'])) {
/** /**

View File

@@ -503,7 +503,7 @@ class PMA_Table {
/** /**
* Copies or renames table * Copies or renames table
* @todo use RENAME for move operations * @todo 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
@@ -572,8 +572,22 @@ 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;
} }