diff --git a/ChangeLog b/ChangeLog index 8956b4f1ed..c9ff68303b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,7 @@ phpMyAdmin - ChangeLog - bug #4392 Cannot see databases in nav panel on databases grouping when disabled database expansion - bug #4419 No more calendar into search tab - bug #4398 Monitor should fit into screen width +- bug #4418 When copying databases, primary key attributes get lost 4.2.1.0 (2014-05-13) - bug #4380 Cannot display table structure with enums containing special characters diff --git a/libraries/Table.class.php b/libraries/Table.class.php index fe4369e220..977d22a9da 100644 --- a/libraries/Table.class.php +++ b/libraries/Table.class.php @@ -1011,15 +1011,43 @@ class PMA_Table $GLOBALS['sql_indexes'] = PMA_SQP_format( $parsed_sql, 'query_only' ); - if ($mode == 'one_table') { + if ($mode == 'one_table' || $mode == 'db_copy') { $GLOBALS['dbi']->query($GLOBALS['sql_indexes']); } $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_indexes']; - if ($mode == 'one_table') { + if ($mode == 'one_table' || $mode == 'db_copy') { unset($GLOBALS['sql_indexes']); } + } + /* + * add AUTO_INCREMENT to the table + * + * @todo refactor with similar code above + */ + if (! empty($GLOBALS['sql_auto_increments'])) { + if ($mode == 'one_table' || $mode == 'db_copy') { + $parsed_sql = PMA_SQP_parse($GLOBALS['sql_auto_increments']); + $i = 0; + + // find the first $table_delimiter, it must be the source + // table name + while ($parsed_sql[$i]['type'] != $table_delimiter) { + $i++; + } + + // replace it by the target table name, no need + // to backquote() + $parsed_sql[$i]['data'] = $target; + + // Generate query back + $GLOBALS['sql_auto_increments'] = PMA_SQP_format( + $parsed_sql, 'query_only' + ); + $GLOBALS['dbi']->query($GLOBALS['sql_auto_increments']); + $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_auto_increments']; + } } } else { diff --git a/libraries/operations.lib.php b/libraries/operations.lib.php index ce5edbdbfb..d4df2cd58a 100644 --- a/libraries/operations.lib.php +++ b/libraries/operations.lib.php @@ -390,7 +390,7 @@ function PMA_getSqlConstraintsQueryForFullDb( $sql_constraints = ''; $sql_drop_foreign_keys = ''; $export_sql_plugin->getTableDef( - $db, $each_table, "\n", '', false, false + $db, $each_table, "\n", '', false, false, false, false ); if ($move && ! empty($sql_drop_foreign_keys)) { $GLOBALS['dbi']->query($sql_drop_foreign_keys); diff --git a/libraries/plugins/export/ExportSql.class.php b/libraries/plugins/export/ExportSql.class.php index 902523804a..15071c6849 100644 --- a/libraries/plugins/export/ExportSql.class.php +++ b/libraries/plugins/export/ExportSql.class.php @@ -1002,15 +1002,18 @@ class ExportSql extends ExportPlugin /** * Returns $table's CREATE definition * - * @param string $db the database name - * @param string $table the table name - * @param string $crlf the end of line sequence - * @param string $error_url the url to go back in case of error - * @param bool $show_dates whether to include creation/update/check - * dates - * @param bool $add_semicolon whether to add semicolon and end-of-line at - * the end - * @param bool $view whether we're handling a view + * @param string $db the database name + * @param string $table the table name + * @param string $crlf the end of line sequence + * @param string $error_url the url to go back in case + * of error + * @param bool $show_dates whether to include creation/ + * update/check dates + * @param bool $add_semicolon whether to add semicolon and + * end-of-line at the end + * @param bool $view whether we're handling a view + * @param bool $update_indexes_increments whether we need to update + * two global variables * * @return string resulting schema */ @@ -1021,7 +1024,8 @@ class ExportSql extends ExportPlugin $error_url, $show_dates = false, $add_semicolon = true, - $view = false + $view = false, + $update_indexes_increments = true ) { global $sql_drop_table, $sql_backquotes, $sql_constraints, $sql_constraints_query, $sql_indexes, $sql_indexes_query, @@ -1260,7 +1264,7 @@ class ExportSql extends ExportPlugin //if there are indexes // (look for KEY followed by whitespace to avoid matching // keyworks like PACK_KEYS) - if (preg_match( + if ($update_indexes_increments && preg_match( '@KEY[\s]+@', $create_query )) { @@ -1298,7 +1302,7 @@ class ExportSql extends ExportPlugin . PMA_Util::backquoteCompat($table, $compat) . $crlf; } - if (preg_match( + if ($update_indexes_increments && preg_match( '@AUTO_INCREMENT@', $create_query )) { @@ -1348,7 +1352,7 @@ class ExportSql extends ExportPlugin } for ($k = 0; $k < $sql_count; $k++) { - if (preg_match( + if ($update_indexes_increments && preg_match( '( AUTO_INCREMENT | AUTO_INCREMENT,| AUTO_INCREMENT$)', $sql_lines[$k] )) { @@ -1361,7 +1365,7 @@ class ExportSql extends ExportPlugin " AUTO_INCREMENT", "", $sql_lines[$k] ); } - if (preg_match( + if ($update_indexes_increments && preg_match( '@[\s]+(AUTO_INCREMENT=)@', $sql_lines[$k] )) { @@ -1434,7 +1438,7 @@ class ExportSql extends ExportPlugin . $matches[3]; } $first = false; - } else if (preg_match( + } else if ($update_indexes_increments && preg_match( '@KEY[\s]+@', $sql_lines[$j] )) {