1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-30 09:39:51 +02:00

Compare commits

...

2 Commits

Author SHA1 Message Date
Jakub Vrana
7341756579 Show commands in navigation 2010-05-20 22:25:39 +02:00
Jakub Vrana
946eb154f6 ON DELETE action for foreign keys in Create table 2010-05-20 22:06:34 +02:00
5 changed files with 27 additions and 13 deletions

View File

@@ -5,7 +5,7 @@ $partition_by = array('HASH', 'LINEAR HASH', 'KEY', 'LINEAR KEY', 'RANGE', 'LIST
$referencable_primary = referencable_primary($TABLE);
$foreign_keys = array();
foreach ($referencable_primary as $table_name => $field) {
$foreign_keys[idf_escape($table_name) . "." . idf_escape($field["field"])] = $table_name;
$foreign_keys[str_replace("`", "``", $table_name) . "`" . str_replace("`", "``", $field["field"])] = $table_name; // not idf_escape() - used in JS
}
$orig_fields = array();
@@ -44,7 +44,7 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"]
$fields[] = array($field["orig"], $process_field, $after);
}
if (!isset($types[$field["type"]])) {
$foreign[] = ($TABLE != "" ? "ADD " : " ") . "FOREIGN KEY (" . idf_escape($field["field"]) . ") REFERENCES " . idf_escape($foreign_keys[$field["type"]]) . " (" . idf_escape($type_field["field"]) . ")";
$foreign[] = ($TABLE != "" ? "ADD " : " ") . "FOREIGN KEY (" . idf_escape($field["field"]) . ") REFERENCES " . idf_escape($foreign_keys[$field["type"]]) . " (" . idf_escape($type_field["field"]) . ")" . (in_array($field["on_delete"], $on_actions) ? " ON DELETE $field[on_delete]" : "");
}
}
$after = "AFTER " . idf_escape($field["field"]);

View File

@@ -566,11 +566,18 @@ document.getElementById('username').focus();
* @return null
*/
function tablesPrint($tables) {
echo "<p id='tables'>\n";
echo "<ul id='tables'>\n";
$i = 1;
foreach ($tables as $table => $type) {
echo '<a href="' . h(ME) . 'select=' . urlencode($table) . '">' . bold(lang('select'), $_GET["select"] == $table) . '</a> ';
echo '<a href="' . h(ME) . 'table=' . urlencode($table) . '">' . bold($this->tableName(array("Name" => $table)), $_GET["table"] == $table) . "</a><br>\n"; //! Adminer::tableName may work with full table status
echo "<li onmouseover=\"toggle('table-$i');\" onmouseout=\"toggle('table-$i');\"><a href='" . h(ME) . "table=" . urlencode($table) . "'>" . bold($this->tableName(array("Name" => $table)), $_GET["table"] == $table) . "</a>"; //! Adminer::tableName may work with full table status
echo "<span id='table-$i' class='hidden'>";
echo ' <a href="' . h(ME) . 'select=' . urlencode($table) . '">' . bold(lang('select'), $_GET["select"] == $table) . '</a>';
echo ' <a href="' . h(ME) . 'create=' . urlencode($table) . '">' . bold(lang('alter'), $_GET["create"] == $table) . '</a>';
echo ' <a href="' . h(ME) . 'edit=' . urlencode($table) . '">' . bold(lang('insert'), $_GET["edit"] == $table) . '</a>';
echo "</span>\n";
$i++;
}
echo "</ul>\n";
}
}

View File

@@ -108,12 +108,13 @@ function referencable_primary($self) {
* @return null
*/
function edit_type($key, $field, $collations, $foreign_keys = array()) {
global $structured_types, $unsigned, $inout;
global $structured_types, $unsigned, $inout, $on_actions;
?>
<td><select name="<?php echo $key; ?>[type]" class="type" onfocus="lastType = selectValue(this);" onchange="editingTypeChange(this);"><?php echo optionlist($structured_types + ($foreign_keys ? array(lang('Foreign keys') => $foreign_keys) : array()), $field["type"]); ?></select>
<td><input name="<?php echo $key; ?>[length]" value="<?php echo h($field["length"]); ?>" size="3" onfocus="editingLengthFocus(this);"><td><?php
echo "<select name='$key" . "[collation]'" . (ereg('(char|text|enum|set)$', $field["type"]) ? "" : " class='hidden'") . '><option value="">(' . lang('collation') . ')' . optionlist($collations, $field["collation"]) . '</select>';
echo ($unsigned ? "<select name='$key" . "[unsigned]'" . (!$field["type"] || ereg('(int|float|double|decimal)$', $field["type"]) ? "" : " class='hidden'") . '><option>' . optionlist($unsigned, $field["unsigned"]) . '</select> ' : ' '); // space for IE
echo ($unsigned ? "<select name='$key" . "[unsigned]'" . (!$field["type"] || ereg('(int|float|double|decimal)$', $field["type"]) ? "" : " class='hidden'") . '><option>' . optionlist($unsigned, $field["unsigned"]) . '</select>' : '');
echo ($foreign_keys ? "<select name='$key" . "[on_delete]'" . (ereg("`", $field["type"]) ? "" : " class='hidden'") . "><option value=''>(" . lang('ON DELETE') . ")" . optionlist($on_actions, $field["on_delete"]) . "</select> " : " "); // space for IE
}
/** Filter length value including enums

View File

@@ -18,6 +18,7 @@ td img { max-width: 200px; max-height: 200px; }
code { background: #eee; }
tr:hover td, tr:hover th { background: #ddf; }
pre { margin: 1em 0 0; }
ul { margin: 1em 0 0; }
.version { color: #777; font-size: 67%; }
.js .hidden { display: none; }
.nowrap td, .nowrap th, td.nowrap { white-space: pre; }
@@ -38,6 +39,8 @@ pre { margin: 1em 0 0; }
.type { width: 15ex; width: auto\9; }
#menu { position: absolute; margin: 10px 0 0; padding: 0 0 30px 0; top: 2em; left: 0; width: 19em; overflow: auto; overflow-y: hidden; white-space: nowrap; }
#menu p { padding: .8em 1em; margin: 0; border-bottom: 1px solid #ccc; }
#tables { padding: 0 0 0 1em; }
#tables li { list-style-type: none; }
#content { margin: 2em 0 0 21em; padding: 10px 20px 20px 0; }
#lang { position: absolute; top: 0; left: 0; line-height: 1.8em; padding: .3em 1em; }
#breadcrumb { white-space: nowrap; position: absolute; top: 0; left: 21em; background: #eee; height: 2em; line-height: 1.8em; padding: 0 1em; margin: 0 0 0 -18px; }

View File

@@ -83,7 +83,7 @@ function reEscape(s) {
* @return string
*/
function idfEscape(s) {
return '`' + s.replace(/`/, '``') + '`';
return s.replace(/`/, '``');
}
/** Detect foreign key
@@ -102,14 +102,14 @@ function editingNameChange(field) {
}
var plural = '(?:e?s)?';
var tabCol = table + plural + '_?' + column;
var re = new RegExp('(^' + idfEscape(table + plural) + '\\.' + idfEscape(column) + '$' // table_column
+ '|^' + idfEscape(tabCol) + '\\.' // table
+ '|^' + idfEscape(column + plural) + '\\.' + idfEscape(table) + '$' // column_table
+ ')|\\.' + idfEscape(tabCol) + '$' // column
var re = new RegExp('(^' + idfEscape(table + plural) + '`' + idfEscape(column) + '$' // table_column
+ '|^' + idfEscape(tabCol) + '`' // table
+ '|^' + idfEscape(column + plural) + '`' + idfEscape(table) + '$' // column_table
+ ')|`' + idfEscape(tabCol) + '$' // column
, 'i');
var candidate; // don't select anything with ambiguous match (like column `id`)
for (var i = opts.length; i--; ) {
if (opts[i].value.substr(0, 1) != '`') { // common type
if (!/`/.test(opts[i].value)) { // common type
if (i == opts.length - 2 && candidate && !match[1] && name == 'fields[1]') { // single target table, link to column, first field - probably `id`
return false;
}
@@ -215,6 +215,9 @@ function editingTypeChange(type) {
if (el.name == name + '[unsigned]') {
el.className = (/(int|float|double|decimal)$/.test(text) ? '' : 'hidden');
}
if (el.name == name + '[on_delete]') {
el.className = (/`/.test(text) ? '' : 'hidden');
}
}
}