Skip to content

Commit

Permalink
bug 1388048, constraints copied too early when copying a db
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Delisle committed Jul 4, 2006
1 parent 029a63a commit e79079b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
6 changes: 4 additions & 2 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ $Source$

2006-07-04 Marc Delisle <[email protected]>
* 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 <[email protected]>
* js\querywindow.js, libraries\footer.inc.php: renamed JavaScript function
Expand Down
18 changes: 17 additions & 1 deletion db_operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
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;
Expand All @@ -70,13 +74,25 @@

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');
Expand Down
20 changes: 14 additions & 6 deletions libraries/Table.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ function duplicateInfo($work, $pma_table, $get_fields, $where_fields,
*
* @author Michal Cihar <[email protected]>
*/
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;

Expand Down Expand Up @@ -541,13 +541,14 @@ function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $

$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') {
Expand Down Expand Up @@ -597,13 +598,17 @@ function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $
$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()
Expand All @@ -623,13 +628,16 @@ function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $
}
}


// 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 {
Expand Down
2 changes: 1 addition & 1 deletion tbl_move_copy.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
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));
Expand Down

0 comments on commit e79079b

Please sign in to comment.