2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Set of functions used for cleaning up phpMyAdmin tables
8 if (! defined('PHPMYADMIN')) {
15 require_once './libraries/relation.lib.php';
16 $cfgRelation = PMA_getRelationsParam();
18 function PMA_relationsCleanupColumn($db, $table, $column) {
20 if ($cfgRelation['commwork']) {
21 $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info'])
22 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
23 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
24 . ' AND column_name = \'' . PMA_sqlAddslashes(urldecode($column)) . '\'';
25 $rmv_rs = PMA_query_as_cu($remove_query);
29 if ($cfgRelation['displaywork']) {
30 $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_info'])
31 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
32 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
33 . ' AND display_field = \'' . PMA_sqlAddslashes(urldecode($column)) . '\'';
34 $rmv_rs = PMA_query_as_cu($remove_query);
38 if ($cfgRelation['relwork']) {
39 $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
40 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
41 . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\''
42 . ' AND master_field = \'' . PMA_sqlAddslashes(urldecode($column)) . '\'';
43 $rmv_rs = PMA_query_as_cu($remove_query);
46 $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
47 . ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\''
48 . ' AND foreign_table = \'' . PMA_sqlAddslashes($table) . '\''
49 . ' AND foreign_field = \'' . PMA_sqlAddslashes(urldecode($column)) . '\'';
50 $rmv_rs = PMA_query_as_cu($remove_query);
55 function PMA_relationsCleanupTable($db, $table) {
58 if ($cfgRelation['commwork']) {
59 $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info'])
60 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
61 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
62 $rmv_rs = PMA_query_as_cu($remove_query);
66 if ($cfgRelation['displaywork']) {
67 $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_info'])
68 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
69 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
70 $rmv_rs = PMA_query_as_cu($remove_query);
74 if ($cfgRelation['pdfwork']) {
75 $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
76 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
77 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
78 $rmv_rs = PMA_query_as_cu($remove_query);
82 if ($cfgRelation['designerwork']) {
83 $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['designer_coords'])
84 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
85 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
86 $rmv_rs = PMA_query_as_cu($remove_query);
90 if ($cfgRelation['relwork']) {
91 $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
92 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
93 . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\'';
94 $rmv_rs = PMA_query_as_cu($remove_query);
97 $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
98 . ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\''
99 . ' AND foreign_table = \'' . PMA_sqlAddslashes($table) . '\'';
100 $rmv_rs = PMA_query_as_cu($remove_query);
101 unset($remove_query);
105 function PMA_relationsCleanupDatabase($db) {
108 if ($cfgRelation['commwork']) {
109 $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info'])
110 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
111 $rmv_rs = PMA_query_as_cu($remove_query);
112 unset($remove_query);
115 if ($cfgRelation['bookmarkwork']) {
116 $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['bookmark'])
117 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\'';
118 $rmv_rs = PMA_query_as_cu($remove_query);
119 unset($remove_query);
122 if ($cfgRelation['displaywork']) {
123 $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_info'])
124 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
125 $rmv_rs = PMA_query_as_cu($remove_query);
126 unset($remove_query);
129 if ($cfgRelation['pdfwork']) {
130 $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
131 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
132 $rmv_rs = PMA_query_as_cu($remove_query);
133 unset($remove_query);
135 $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
136 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
137 $rmv_rs = PMA_query_as_cu($remove_query);
138 unset($remove_query);
141 if ($cfgRelation['designerwork']) {
142 $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['designer_coords'])
143 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
144 $rmv_rs = PMA_query_as_cu($remove_query);
145 unset($remove_query);
148 if ($cfgRelation['relwork']) {
149 $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
150 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\'';
151 $rmv_rs = PMA_query_as_cu($remove_query);
152 unset($remove_query);
154 $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
155 . ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\'';
156 $rmv_rs = PMA_query_as_cu($remove_query);
157 unset($remove_query);