From 029a63a1f576c0987c1fb8f40d47dbd2224fdaad Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Tue, 4 Jul 2006 15:53:41 +0000 Subject: [PATCH] single-table copy did not copy the constraints --- ChangeLog | 5 +++++ db_operations.php | 2 +- libraries/Table.class.php | 15 ++++++++------- libraries/export/sql.php | 11 ++++++++--- tbl_properties_operations.php | 2 +- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index b51505e87..cfa4abae5 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,11 @@ phpMyAdmin - ChangeLog $Id$ $Source$ +2006-07-04 Marc Delisle + * db_operations.php, tbl_properties_operations.php, + libraries/Table.class.php, libraries/export/sql.php: + a single-table copy did not copy the constraints + 2006-07-04 Sebastian Mendel * js\querywindow.js, libraries\footer.inc.php: renamed JavaScript function refreshLeft() to refreshNavigation() diff --git a/db_operations.php b/db_operations.php index 423aa4107..6ec83fa79 100644 --- a/db_operations.php +++ b/db_operations.php @@ -264,7 +264,7 @@ if (!$is_information_schema) { id="checkbox_auto_increment" style="vertical-align: middle" />
-
diff --git a/libraries/Table.class.php b/libraries/Table.class.php index 8602c4b0b..d7cde6f10 100644 --- a/libraries/Table.class.php +++ b/libraries/Table.class.php @@ -540,6 +540,7 @@ class PMA_Table { require_once './libraries/export/sql.php'; $no_constraints_comments = true; + $GLOBALS['sql_constraints_query'] = ''; $sql_structure = PMA_getTableDef($source_db, $source_table, "\n", $err_url); unset($no_constraints_comments); $parsed_sql = PMA_SQP_parse($sql_structure); @@ -595,9 +596,9 @@ class PMA_Table { @PMA_DBI_query($sql_structure); $GLOBALS['sql_query'] .= "\n" . $sql_structure . ';'; - if (($move || isset($GLOBALS['constraints'])) - && isset($GLOBALS['sql_constraints'])) { - $parsed_sql = PMA_SQP_parse($GLOBALS['sql_constraints']); + if (($move || isset($GLOBALS['add_constraints'])) + && isset($GLOBALS['sql_constraints_query'])) { + $parsed_sql = PMA_SQP_parse($GLOBALS['sql_constraints_query']); $i = 0; // find the first quote_backtick, it must be the source table name @@ -624,11 +625,11 @@ class PMA_Table { // Generate query back - $GLOBALS['sql_constraints'] = PMA_SQP_formatHtml($parsed_sql, + $GLOBALS['sql_constraints_query'] = PMA_SQP_formatHtml($parsed_sql, 'query_only'); - PMA_DBI_query($GLOBALS['sql_constraints']); - $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints']; - unset($GLOBALS['sql_constraints']); + PMA_DBI_query($GLOBALS['sql_constraints_query']); + $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints_query']; + unset($GLOBALS['sql_constraints_query']); } } else { diff --git a/libraries/export/sql.php b/libraries/export/sql.php index 59c9b124b..e31876a00 100644 --- a/libraries/export/sql.php +++ b/libraries/export/sql.php @@ -346,6 +346,7 @@ function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false) global $sql_backquotes; global $cfgRelation; global $sql_constraints; + global $sql_constraints_query; // just the text of the query $schema_create = ''; $auto_increment = ''; @@ -456,7 +457,7 @@ function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false) } // let's do the work - $sql_constraints .= 'ALTER TABLE ' . PMA_backquote($table) . $crlf; + $sql_constraints_query .= 'ALTER TABLE ' . PMA_backquote($table) . $crlf; $first = TRUE; for ($j = $i; $j < $sql_count; $j++) { @@ -465,9 +466,11 @@ function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false) $sql_constraints .= $crlf; } if (strpos($sql_lines[$j], 'CONSTRAINT') === FALSE) { - $sql_constraints .= preg_replace('/(FOREIGN[\s]+KEY)/', 'ADD \1', $sql_lines[$j]); + $sql_constraints_query .= preg_replace('/(FOREIGN[\s]+KEY)/', 'ADD \1', $sql_lines[$j]); + $sql_constraints .= $sql_constraints_query; } else { - $sql_constraints .= preg_replace('/(CONSTRAINT)/', 'ADD \1', $sql_lines[$j]); + $sql_constraints_query .= preg_replace('/(CONSTRAINT)/', 'ADD \1', $sql_lines[$j]); + $sql_constraints .= $sql_constraints_query; } $first = FALSE; } else { @@ -475,6 +478,8 @@ function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false) } } $sql_constraints .= ';' . $crlf; + $sql_constraints_query .= ';'; + $create_query = implode($crlf, array_slice($sql_lines, 0, $i)) . $crlf . implode($crlf, array_slice($sql_lines, $j, $sql_count - 1)); unset($sql_lines); } diff --git a/tbl_properties_operations.php b/tbl_properties_operations.php index 9ea66bcd3..c9faf788f 100644 --- a/tbl_properties_operations.php +++ b/tbl_properties_operations.php @@ -368,7 +368,7 @@ foreach ($dblist as $each_db) { // foreign keys if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'innodb')) { ?> - +