Cleanup phpMyAdmin tables also after multi submit actions (RFE #749989).

This commit is contained in:
Michal Čihař
2003-06-06 10:02:58 +00:00
parent ab5dd3adb4
commit 69cefd5bf9
4 changed files with 159 additions and 121 deletions

View File

@@ -7,6 +7,8 @@ $Source$
2003-06-06 Michal Cihar <nijel@users.sourceforge.net> 2003-06-06 Michal Cihar <nijel@users.sourceforge.net>
* mult_submits.inc.php3: Missing ;. * mult_submits.inc.php3: Missing ;.
* libraries/relation_cleanup.lib.php3, mult_submits.inc.php3, sql.php3:
Cleanup phpMyAdmin tables also after multi submit actions (RFE #749989).
2003-06-05 Marc Delisle <lem9@users.sourceforge.net> 2003-06-05 Marc Delisle <lem9@users.sourceforge.net>
* Documentation.html: new faq 6.20 about CREATE TEMPORARY TABLES * Documentation.html: new faq 6.20 about CREATE TEMPORARY TABLES

View File

@@ -0,0 +1,145 @@
<?php
/* $Id$ */
// vim: expandtab sw=4 ts=4 sts=4:
/**
* Set of functions used for cleaning up phpMyAdmin tables
*/
if (!defined('PMA_RELATION_CLEANUP_LIB_INCLUDED')){
define('PMA_RELATION_CLEANUP_LIB_INCLUDED', 1);
include('./libraries/relation.lib.php3');
$cfgRelation = PMA_getRelationsParam();
function PMA_relationsCleanupColumn($db, $table, $column) {
global $cfgRelation;
if ($cfgRelation['commwork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
. ' AND column_name = \'' . PMA_sqlAddslashes(urldecode($column)) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
if ($cfgRelation['displaywork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_info'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
. ' AND display_field = \'' . PMA_sqlAddslashes(urldecode($column)) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
if ($cfgRelation['relwork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
. ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\''
. ' AND master_field = \'' . PMA_sqlAddslashes(urldecode($column)) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
. ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND foreign_table = \'' . PMA_sqlAddslashes($table) . '\''
. ' AND foreign_field = \'' . PMA_sqlAddslashes(urldecode($column)) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
}
function PMA_relationsCleanupTable($db, $table) {
global $cfgRelation;
if ($cfgRelation['commwork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
if ($cfgRelation['displaywork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_info'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
if ($cfgRelation['pdfwork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_coords'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
if ($cfgRelation['relwork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
. ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
. ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND foreign_table = \'' . PMA_sqlAddslashes($table) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
}
function PMA_relationsCleanupDatabase($db) {
global $cfgRelation;
if ($cfgRelation['commwork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
if ($cfgRelation['bookmarkwork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['bookmark'])
. ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
if ($cfgRelation['displaywork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_info'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
if ($cfgRelation['pdfwork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_coords'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
if ($cfgRelation['relwork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
. ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
. ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
}
} // $__PMA_RELATION_CLEANUP_LIB__
?>

View File

@@ -158,17 +158,23 @@ if (!empty($submit_mult) && !empty($what)) {
*/ */
else if ($mult_btn == $strYes) { else if ($mult_btn == $strYes) {
if ($query_type == 'drop_db' || $query_type == 'drop_tbl' || $query_type == 'drop_fld') {
include('./libraries/relation_cleanup.lib.php3');
}
$sql_query = ''; $sql_query = '';
$selected_cnt = count($selected); $selected_cnt = count($selected);
for ($i = 0; $i < $selected_cnt; $i++) { for ($i = 0; $i < $selected_cnt; $i++) {
switch ($query_type) { switch ($query_type) {
case 'drop_db': case 'drop_db':
PMA_relationsCleanupDatabase($selected[$i]);
$a_query = 'DROP DATABASE ' $a_query = 'DROP DATABASE '
. PMA_backquote(urldecode($selected[$i])); . PMA_backquote(urldecode($selected[$i]));
$reload = 1; $reload = 1;
break; break;
case 'drop_tbl': case 'drop_tbl':
PMA_relationsCleanupTable($db, $selected[$i]);
$sql_query .= (empty($sql_query) ? 'DROP TABLE ' : ', ') $sql_query .= (empty($sql_query) ? 'DROP TABLE ' : ', ')
. PMA_backquote(urldecode($selected[$i])) . PMA_backquote(urldecode($selected[$i]))
. (($i == $selected_cnt-1) ? ';' : ''); . (($i == $selected_cnt-1) ? ';' : '');
@@ -205,6 +211,7 @@ else if ($mult_btn == $strYes) {
break; break;
case 'drop_fld': case 'drop_fld':
PMA_relationsCleanupTable($db, $table, $selected[$i]);
$sql_query .= (empty($sql_query) ? 'ALTER TABLE ' . PMA_backquote($table) : ',') $sql_query .= (empty($sql_query) ? 'ALTER TABLE ' . PMA_backquote($table) : ',')
. ' DROP ' . PMA_backquote(urldecode($selected[$i])) . ' DROP ' . PMA_backquote(urldecode($selected[$i]))
. (($i == $selected_cnt-1) ? ';' : ''); . (($i == $selected_cnt-1) ? ';' : '');

126
sql.php3
View File

@@ -457,95 +457,12 @@ else {
// garvin: if a table or database gets dropped, check column comments. // garvin: if a table or database gets dropped, check column comments.
if (isset($purge) && $purge == '1') { if (isset($purge) && $purge == '1') {
include('./libraries/relation.lib.php3'); include('./libraries/relation_cleanup.lib.php3');
$cfgRelation = PMA_getRelationsParam();
if (isset($table) && isset($db) && !empty($table) && !empty($db)) { if (isset($table) && isset($db) && !empty($table) && !empty($db)) {
// garvin: Only a table is deleted. Remove all references in PMA_* PMA_relationsCleanupTable($db, $table);
if ($cfgRelation['commwork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
if ($cfgRelation['displaywork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_info'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
if ($cfgRelation['pdfwork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_coords'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
if ($cfgRelation['relwork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
. ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
. ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND foreign_table = \'' . PMA_sqlAddslashes($table) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
} elseif (isset($db) && !empty($db)) { } elseif (isset($db) && !empty($db)) {
// garvin: A whole DB gets deleted. Remove all references in PMA_* PMA_relationsCleanupDatabase($db);
if ($cfgRelation['commwork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
if ($cfgRelation['bookmarkwork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['bookmark'])
. ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
if ($cfgRelation['displaywork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_info'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
if ($cfgRelation['pdfwork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_coords'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
if ($cfgRelation['relwork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
. ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
. ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
} else { } else {
// garvin: VOID. No DB/Table gets deleted. // garvin: VOID. No DB/Table gets deleted.
} // end if relation-stuff } // end if relation-stuff
@@ -555,42 +472,9 @@ else {
if (isset($cpurge) && $cpurge == '1' && isset($purgekey) if (isset($cpurge) && $cpurge == '1' && isset($purgekey)
&& isset($db) && isset($table) && isset($db) && isset($table)
&& !empty($db) && !empty($table) && !empty($purgekey)) { && !empty($db) && !empty($table) && !empty($purgekey)) {
include('./libraries/relation.lib.php3'); include('./libraries/relation_cleanup.lib.php3');
$cfgRelation = PMA_getRelationsParam(); PMA_relationsCleanupColumnt($db, $table, $purgekey);
if ($cfgRelation['commwork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
. ' AND column_name = \'' . PMA_sqlAddslashes(urldecode($purgekey)) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
if ($cfgRelation['displaywork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_info'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
. ' AND display_field = \'' . PMA_sqlAddslashes(urldecode($purgekey)) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
if ($cfgRelation['relwork']) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
. ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\''
. ' AND master_field = \'' . PMA_sqlAddslashes(urldecode($purgekey)) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
. ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND foreign_table = \'' . PMA_sqlAddslashes($table) . '\''
. ' AND foreign_field = \'' . PMA_sqlAddslashes(urldecode($purgekey)) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query);
unset($rmv_query);
}
} // end if column PMA_* purge } // end if column PMA_* purge
} // end else "didn't ask to see php code" } // end else "didn't ask to see php code"