foreign_key_row.phtml
8.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
$js_msg = '';
$this_params = null;
if (isset($one_key['constraint'])) {
$drop_fk_query = 'ALTER TABLE ' . PMA_Util::backquote($GLOBALS['table'])
. ' DROP FOREIGN KEY '
. PMA_Util::backquote($one_key['constraint']) . ';';
$this_params = $GLOBALS['url_params'];
$this_params['goto'] = 'tbl_relation.php';
$this_params['back'] = 'tbl_relation.php';
$this_params['sql_query'] = $drop_fk_query;
$this_params['message_to_show'] = sprintf(
__('Foreign key constraint %s has been dropped'),
$one_key['constraint']
);
$js_msg = PMA_jsFormat(
'ALTER TABLE ' . $GLOBALS['table']
. ' DROP FOREIGN KEY '
. $one_key['constraint'] . ';'
);
}
// For ON DELETE and ON UPDATE, the default action
// is RESTRICT as per MySQL doc; however, a SHOW CREATE TABLE
// won't display the clause if it's set as RESTRICT.
$on_delete = isset($one_key['on_delete'])
? $one_key['on_delete'] : 'RESTRICT';
$on_update = isset($one_key['on_update'])
? $one_key['on_update'] : 'RESTRICT';
$column_array = array();
$column_array[''] = '';
foreach ($columns as $column) {
if (! empty($column['Key'])) {
$column_array[$column['Field']] = $column['Field'];
}
}
$foreign_table = false;
// foreign database dropdown
$foreign_db = (isset($one_key['ref_db_name'])) ? $one_key['ref_db_name'] : $db;
$tables = array();
if ($foreign_db) {
$foreign_table = isset($one_key['ref_table_name'])
? $one_key['ref_table_name'] : '';
// In Drizzle, 'SHOW TABLE STATUS' will show status only for the tables
// which are currently in the table cache. Hence we have to use
// 'SHOW TABLES' and manualy retrieve table engine values.
if (PMA_DRIZZLE) {
$tables_rs = $GLOBALS['dbi']->query(
'SHOW TABLES FROM ' . PMA_Util::backquote($foreign_db),
null,
PMA_DatabaseInterface::QUERY_STORE
);
while ($row = $GLOBALS['dbi']->fetchArray($tables_rs)) {
$engine = $GLOBALS['dbi']->getTable(
$foreign_db,
$row[0]
)->getStatusInfo('Engine');
if (isset($engine)
&& /*overload*/mb_strtoupper($engine) == $tbl_storage_engine
) {
$tables[] = $row[0];
}
}
} else {
$tables_rs = $GLOBALS['dbi']->query(
'SHOW TABLE STATUS FROM ' . PMA_Util::backquote($foreign_db),
null,
PMA_DatabaseInterface::QUERY_STORE
);
while ($row = $GLOBALS['dbi']->fetchRow($tables_rs)) {
if (isset($row[1])
&& /*overload*/mb_strtoupper($row[1]) == $tbl_storage_engine
) {
$tables[] = $row[0];
}
}
}
}
?>
<tr class="<?php echo ($odd_row ? 'odd' : 'even'); ?>">
<!-- Drop key anchor -->
<td>
<?php if (isset($one_key['constraint'])): ?>
<input type="hidden"
class="drop_foreign_key_msg"
value="<?php echo $js_msg; ?>" />
<a class="drop_foreign_key_anchor ajax"
href="sql.php<?php echo PMA_URL_getCommon($this_params); ?>" >
<?php echo PMA_Util::getIcon('b_drop.png', __('Drop')); ?>
</a>
<?php endif; ?>
</td>
<td>
<span class="formelement clearfloat">
<input type="text" name="constraint_name[<?php echo $i; ?>]"
value="<?php if (isset($one_key['constraint']))
echo htmlspecialchars($one_key['constraint']); ?>"
placeholder="<?php echo __('Constraint name'); ?>"
maxlength="64" />
</span>
<div class="floatleft">
<span class="formelement">
<?php echo PMA\Template::get('table/relation/dropdown_generate')->render(
array(
'dropdown_question' => 'ON DELETE',
'select_name' => 'on_delete[' . $i . ']',
'choices' => $options_array,
'selected_value' => $on_delete
)
); ?>
</span>
<span class="formelement">
<?php echo PMA\Template::get('table/relation/dropdown_generate')->render(
array(
'dropdown_question' => 'ON UPDATE',
'select_name' => 'on_update[' . $i . ']',
'choices' => $options_array,
'selected_value' => $on_update
)
); ?>
</span>
</div>
</td>
<td>
<?php if (isset($one_key['index_list'])): ?>
<?php foreach ($one_key['index_list'] as $key => $column): ?>
<span class="formelement clearfloat">
<?php echo PMA\Template::get('table/relation/dropdown_generate')->render(
array(
'dropdown_question' => '',
'select_name' => 'foreign_key_fields_name[' . $i . '][]',
'choices' => $column_array,
'selected_value' => $column
)
); ?>
</span>
<?php endforeach; ?>
<?php else: ?>
<span class="formelement clearfloat">
<?php echo PMA\Template::get('table/relation/dropdown_generate')->render(
array(
'dropdown_question' => '',
'select_name' => 'foreign_key_fields_name[' . $i . '][]',
'choices' => $column_array,
'selected_value' => ''
)
); ?>
</span>
<?php endif; ?>
<a class="formelement clearfloat add_foreign_key_field"
href=""
data-index="<?php echo $i; ?>">
<?php echo __('+ Add column'); ?>
</a>
</td>
<td>
<span class="formelement clearfloat">
<?php echo PMA\Template::get('table/relation/relational_dropdown')->render(
array(
'name' => 'destination_foreign_db[' . $i . ']',
'title' => __('Database'),
'values' => $GLOBALS['pma']->databases,
'foreign' => $foreign_db
)
); ?>
</td>
<td>
<span class="formelement clearfloat">
<?php echo PMA\Template::get('table/relation/relational_dropdown')->render(
array(
'name' => 'destination_foreign_table[' . $i . ']',
'title' => __('Table'),
'values' => $tables,
'foreign' => $foreign_table
)
); ?>
</span>
</td>
<td>
<?php if ($foreign_db && $foreign_table): ?>
<?php foreach ($one_key['ref_index_list'] as $foreign_column): ?>
<?php
$table_obj = new PMA_Table($foreign_table, $foreign_db);
$columns = $table_obj->getUniqueColumns(false, false);
?>
<span class="formelement clearfloat">
<?php echo PMA\Template::get('table/relation/relational_dropdown')->render(
array(
'name' => 'destination_foreign_column[' . $i . '][]',
'title' => __('Column'),
'values' => $columns,
'foreign' => $foreign_column
)
); ?>
</span>
<?php endforeach; ?>
<?php else: ?>
<span class="formelement clearfloat">
<?php echo PMA\Template::get('table/relation/relational_dropdown')->render(
array(
'name' => 'destination_foreign_column[' . $i . '][]',
'title' => __('Column'),
'values' => array(),
'foreign' => ''
)
); ?>
</span>
<?php endif; ?>
</td>
</tr>