diff options
author | Marc Delisle <marc@infomarc.info> | 2005-04-02 01:56:56 +0400 |
---|---|---|
committer | Marc Delisle <marc@infomarc.info> | 2005-04-02 01:56:56 +0400 |
commit | d1e2332b42c02cc0f33e315ade103b6f0401eb9d (patch) | |
tree | 6bee5b83d5ee307eedd807f6fff1f2156b785ef1 | |
parent | 01a27e8d26917da45ca1891140b968d37e8f7e67 (diff) |
bug #1168996, error copying InnoDB table with FK constraints to a table in the same dbRELEASE_2_6_2PL1
-rwxr-xr-x | ChangeLog | 2 | ||||
-rw-r--r-- | libraries/tbl_move_copy.php | 30 |
2 files changed, 26 insertions, 6 deletions
@@ -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 <me@derrabus.de> * left.php: Undefined offset (Bug #1174045). diff --git a/libraries/tbl_move_copy.php b/libraries/tbl_move_copy.php index 9f1d551600..548841d9bc 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)) { |