diff --git a/ChangeLog b/ChangeLog index a7a75273d..9214b3d26 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,8 @@ $Source$ * libraries/common.lib.php: DEFAULT CURRENT_TIMESTAMP is only for TIMESTAMP (bug when changing from a TIMESTAMP to a non-TIMESTAMP type) * (same): bug #1163595, problem 4: a TIMESTAMP must be explicitely set to NULL to have the NULL attribute + * libraries/tbl_move_copy.php: bug #1168996, error copying InnoDB table + with FK constraints to a table in the same db 2005-03-31 Alexander M. Turek * left.php: Undefined offset (Bug #1174045). diff --git a/libraries/tbl_move_copy.php b/libraries/tbl_move_copy.php index 9f1d55160..548841d9b 100644 --- a/libraries/tbl_move_copy.php +++ b/libraries/tbl_move_copy.php @@ -99,8 +99,8 @@ function PMA_table_move_copy($source_db, $source_table, $target_db, $target_tabl $source = PMA_backquote($source_db) . '.' . PMA_backquote($source_table); if (empty($target_db)) $target_db = $source_db; - // This could avoid some problems with replicated databases, when - // moving table from replicated one to not replicated one + // Doing a select_db could avoid some problems with replicated databases, + // when moving table from replicated one to not replicated one PMA_DBI_select_db($target_db); $target = PMA_backquote($target_db) . '.' . PMA_backquote($target_table); @@ -150,14 +150,32 @@ function PMA_table_move_copy($source_db, $source_table, $target_db, $target_tabl if (($move || isset($GLOBALS['constraints'])) && isset($GLOBALS['sql_constraints'])) { $parsed_sql = PMA_SQP_parse($GLOBALS['sql_constraints']); - $i = 0; - while ($parsed_sql[$i]['type'] != 'quote_backtick') $i++; - /* no need to PMA_backquote() */ + // find the first quote_backtick, it must be the source table name + while ($parsed_sql[$i]['type'] != 'quote_backtick') { + $i++; + } + + // replace it by the target table name, no need to PMA_backquote() $parsed_sql[$i]['data'] = $target; - /* Generate query back */ + // now we must remove all quote_backtick that follow a CONSTRAINT + // keyword, because a constraint name must be unique in a db + + $cnt = $parsed_sql['len'] - 1; + + for ($j = $i; $j < $cnt; $j++) { + if ($parsed_sql[$j]['type'] == 'alpha_reservedWord' + && strtoupper($parsed_sql[$j]['data']) == 'CONSTRAINT') { + if ($parsed_sql[$j+1]['type'] == 'quote_backtick') { + $parsed_sql[$j+1]['data'] = ''; + } + } + } + + + // Generate query back $GLOBALS['sql_constraints'] = PMA_SQP_formatHtml($parsed_sql, 'query_only'); $result = PMA_DBI_query($GLOBALS['sql_constraints']); if (isset($sql_query)) {