Permalink
Browse files

bug #1168996, error copying InnoDB table with FK constraints to a tab…

…le in the same db
  • Loading branch information...
1 parent 01a27e8 commit d1e2332b42c02cc0f33e315ade103b6f0401eb9d @lem9 lem9 committed Apr 1, 2005
Showing with 26 additions and 6 deletions.
  1. +2 −0 ChangeLog
  2. +24 −6 libraries/tbl_move_copy.php
View
@@ -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).
@@ -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)) {

0 comments on commit d1e2332

Please sign in to comment.