From 61bd5043f37218392ba1bf86afd600913adc6ad6 Mon Sep 17 00:00:00 2001 From: Garvin Hicking Date: Wed, 12 Mar 2003 15:51:51 +0000 Subject: [PATCH] RFE #571838 : Add 'DROP TABLE IF EXISTS' checkbox. --- ChangeLog | 3 +++ tbl_move_copy.php3 | 23 ++++++++++++++++++++++- tbl_properties_operations.php3 | 4 +++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 73d5d6e5f..947192094 100755 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,9 @@ $Id$ $Source$ 2003-03-12 Garvin Hicking + * tbl_move_copy.php3, tbl_properties_operations.php3: RFE #571838 : + Add 'DROP TABLE IF EXISTS' checkbox. Will maintain any existing PMA_* entries + for that table. * tbl_properties_export.php3, db_details_export.php3, libraries/display_export.lib.php3: Reworked DB/Table export, so that DB export now is a perfect look-alike except for a multi-tables dropdown. diff --git a/tbl_move_copy.php3 b/tbl_move_copy.php3 index ac0007769..f58eed4b2 100644 --- a/tbl_move_copy.php3 +++ b/tbl_move_copy.php3 @@ -146,6 +146,27 @@ if (isset($new_name) && trim($new_name) != '') { // do not create the table if dataonly if ($what != 'dataonly') { + // If table exists, and 'add drop table' is selected: Drop it! + $drop_query = ''; + if (isset($drop_if_exists) && $drop_if_exists == 'true') { + $drop_query = 'DROP TABLE IF EXISTS ' . PMA_backquote($target_db) . '.' . PMA_backquote($new_name); + $result = @PMA_mysql_query($drop_query); + if (PMA_mysql_error()) { + include('./header.inc.php3'); + PMA_mysqlDie('', $sql_structure, '', $err_url); + } + + if (isset($sql_query)) { + $sql_query .= "\n" . $drop_query . ';'; + } else { + $sql_query = $drop_query . ';'; + } + + // garvin: If an existing table gets deleted, maintain any entries + // for the PMA_* tables + $maintain_relations = true; + } + $result = @PMA_mysql_query($sql_structure); if (PMA_mysql_error()) { include('./header.inc.php3'); @@ -280,7 +301,7 @@ if (isset($new_name) && trim($new_name) != '') { $table = $new_name; } else { // garvin: Create new entries as duplicates from old PMA DBs - if ($what != 'dataonly') { + if ($what != 'dataonly' && !isset($maintain_relations)) { if ($cfgRelation['commwork']) { // Get all comments and MIME-Types for current table $comments_copy_query = 'SELECT diff --git a/tbl_properties_operations.php3 b/tbl_properties_operations.php3 index 3832d2f00..496ff93bb 100755 --- a/tbl_properties_operations.php3 +++ b/tbl_properties_operations.php3 @@ -174,7 +174,9 @@ for ($i = 0; $i < $num_dbs; $i++) {   
-    +   
+ +