bug 1388048, constraints copied too early when copying a db

This commit is contained in:
Marc Delisle
2006-07-04 16:46:09 +00:00
parent 029a63a1f5
commit e79079b0c4
4 changed files with 36 additions and 10 deletions

View File

@@ -7,8 +7,10 @@ $Source$
2006-07-04 Marc Delisle <lem9@users.sourceforge.net>
* db_operations.php, tbl_properties_operations.php,
libraries/Table.class.php, libraries/export/sql.php:
a single-table copy did not copy the constraints
libraries/Table.class.php, libraries/export/sql.php,
tbl_move_copy.php:
a single-table copy did not copy the constraints;
also bug #1388048, contraints copied too early when copying a db
2006-07-04 Sebastian Mendel <cybot_tm@users.sourceforge.net>
* js\querywindow.js, libraries\footer.inc.php: renamed JavaScript function

View File

@@ -46,6 +46,10 @@ if (isset($db) &&
PMA_DBI_query($local_query);
}
if (isset($GLOBALS['add_constraints'])) {
$GLOBALS['sql_constraints_query_full_db'] = '';
}
$tables_full = PMA_DBI_get_tables_full($db);
foreach ($tables_full as $table => $tmp) {
$back = $sql_query;
@@ -70,13 +74,25 @@ if (isset($db) &&
if ($this_what != 'nocopy') {
PMA_Table::moveCopy($db, $table, $newname, $table,
isset($this_what) ? $this_what : 'data', $move);
isset($this_what) ? $this_what : 'data', $move, 'db_copy');
if (isset($GLOBALS['add_constraints'])) {
$GLOBALS['sql_constraints_query_full_db'] .= $GLOBALS['sql_constraints_query'];
unset($GLOBALS['sql_constraints_query']);
}
}
$sql_query = $back . $sql_query;
}
unset($table);
// now that all tables exist, create all the accumulated constraints
if (isset($GLOBALS['add_constraints'])) {
PMA_DBI_query($GLOBALS['sql_constraints_query_full_db']);
// and prepare to display them
$GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints_query_full_db'];
unset($GLOBALS['sql_constraints_query_full_db']);
}
// Duplicate the bookmarks for this db (done once for each db)
if ($db != $newname) {
$get_fields = array('user', 'label', 'query');

View File

@@ -505,7 +505,7 @@ class PMA_Table {
*
* @author Michal Cihar <michal@cihar.com>
*/
function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $move)
function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $move, $mode)
{
global $dblist, $err_url;
@@ -541,13 +541,14 @@ class PMA_Table {
$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);
$analyzed_sql = PMA_SQP_analyze($parsed_sql);
$i = 0;
if (empty($analyzed_sql[0]['create_table_fields'])) {
// lem9: this is not a CREATE TABLE, so find the first VIEW
// this is not a CREATE TABLE, so find the first VIEW
$target_for_view = PMA_backquote($target_db);
while (true) {
if ($parsed_sql[$i]['type'] == 'alpha_reservedWord' && $parsed_sql[$i]['data'] == 'VIEW') {
@@ -597,13 +598,17 @@ class PMA_Table {
$GLOBALS['sql_query'] .= "\n" . $sql_structure . ';';
if (($move || isset($GLOBALS['add_constraints']))
&& isset($GLOBALS['sql_constraints_query'])) {
&& !empty($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
while ($parsed_sql[$i]['type'] != 'quote_backtick') {
$i++;
// maybe someday we should guard against going over limit
//if ($i == $parsed_sql['len']) {
// break;
//}
}
// replace it by the target table name, no need to PMA_backquote()
@@ -623,13 +628,16 @@ class PMA_Table {
}
}
// Generate query back
$GLOBALS['sql_constraints_query'] = PMA_SQP_formatHtml($parsed_sql,
'query_only');
PMA_DBI_query($GLOBALS['sql_constraints_query']);
if ($mode == 'one_table') {
PMA_DBI_query($GLOBALS['sql_constraints_query']);
}
$GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints_query'];
unset($GLOBALS['sql_constraints_query']);
if ($mode == 'one_table') {
unset($GLOBALS['sql_constraints_query']);
}
}
} else {

View File

@@ -30,7 +30,7 @@ if (isset($new_name) && trim($new_name) != '') {
if ($db == $target_db && $table == $new_name) {
$message = (isset($submit_move) ? $strMoveTableSameNames : $strCopyTableSameNames);
} else {
PMA_Table::moveCopy($db, $table, $target_db, $new_name, $what, isset($submit_move));
PMA_Table::moveCopy($db, $table, $target_db, $new_name, $what, isset($submit_move), 'one_table');
$js_to_run = 'functions.js';
$message = (isset($submit_move) ? $strMoveTableOK : $strCopyTableOK);
$message = sprintf($message, htmlspecialchars($table), htmlspecialchars($new_name));