Selectable ON UPDATE CURRENT_TIMESTAMP field in create table

This commit is contained in:
Jakub Vrana 2013-04-17 09:41:58 -07:00
parent 7af362554a
commit 46a7e7eea0
5 changed files with 6 additions and 10 deletions

View file

@ -36,11 +36,6 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"]
if (!$field["has_default"]) {
$field["default"] = null;
}
$default = eregi_replace(" *on update CURRENT_TIMESTAMP", "", $field["default"]);
if ($default != $field["default"]) { // preg_replace $count is available since PHP 5.1.0
$field["on_update"] = "CURRENT_TIMESTAMP";
$field["default"] = $default;
}
if ($key == $_POST["auto_increment_col"]) {
$field["auto_increment"] = true;
}
@ -125,9 +120,6 @@ if ($_POST) {
}
foreach ($orig_fields as $field) {
$field["has_default"] = isset($field["default"]);
if ($field["on_update"]) {
$field["default"] .= " ON UPDATE $field[on_update]"; // CURRENT_TIMESTAMP
}
$row["fields"][] = $field;
}
if (support("partitioning")) {

View file

@ -152,6 +152,7 @@ function edit_type($key, $field, $collations, $foreign_keys = array()) {
<td><input name="<?php echo $key; ?>[length]" value="<?php echo h($field["length"]); ?>" size="3" onfocus="editingLengthFocus(this);"><td class="options"><?php //! type="number" with enabled JavaScript
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>' : '');
echo (isset($field['on_update']) ? "<select name='$key" . "[on_update]'" . ($field["type"] == "timestamp" ? "" : " class='hidden'") . '>' . optionlist(array("" => "(" . lang('ON UPDATE') . ")", "CURRENT_TIMESTAMP"), $field["on_update"]) . '</select>' : '');
echo ($foreign_keys ? "<select name='$key" . "[on_delete]'" . (ereg("`", $field["type"]) ? "" : " class='hidden'") . "><option value=''>(" . lang('ON DELETE') . ")" . optionlist(explode("|", $on_actions), $field["on_delete"]) . "</select> " : " "); // space for IE
}
@ -189,7 +190,7 @@ function process_field($field, $type_field) {
process_type($type_field),
($field["null"] ? " NULL" : " NOT NULL"), // NULL for timestamp
(isset($field["default"]) ? " DEFAULT " . ((ereg("time", $field["type"]) && eregi('^CURRENT_TIMESTAMP$', $field["default"])) || ($field["type"] == "bit" && ereg("^([0-9]+|b'[0-1]+')\$", $field["default"])) ? $field["default"] : q($field["default"])) : ""),
($field["on_update"] ? " ON UPDATE $field[on_update]" : ""),
($field["type"] == "timestamp" && $field["on_update"] ? " ON UPDATE $field[on_update]" : ""),
(support("comment") && $field["comment"] != "" ? " COMMENT " . q($field["comment"]) : ""),
($field["auto_increment"] ? auto_increment() : null),
);

View file

@ -365,6 +365,9 @@ function editingTypeChange(type) {
if (el.name == name + '[unsigned]') {
el.className = (/(int|float|double|decimal)$/.test(text) ? '' : 'hidden');
}
if (el.name == name + '[on_update]') {
el.className = (text == 'timestamp' ? '' : 'hidden');
}
if (el.name == name + '[on_delete]') {
el.className = (/`/.test(text) ? '' : 'hidden');
}

View file

@ -4,6 +4,7 @@ Increase default select limit to 50
Display SQL edit form on Ctrl+click on the select query
Display SQL history from oldest
Recover original view, trigger, routine if creating fails
Selectable ON UPDATE CURRENT_TIMESTAMP field in create table
Clear column name after resetting search (bug #3601200)
Explain partitions in SQL query (bug #3600150)
Allow loading more data with inline edit (bug #3605531)

View file

@ -9,7 +9,6 @@ Draggable columns in alter table (thanks to Michal Manak)
<option class> for system databases and schemas - information_schema and driver-specific (thanks to Vaclav Novotny)
Define foreign keys name - http://forum.zdrojak.root.cz/index.php?topic=185.msg1255#msg1255
Skinnable plus.gif and other images - http://typo3.org/extensions/repository/view/t3adminer/current/
Selectable <option>(on update)<option>CURRENT_TIMESTAMP for timestamp - https://sourceforge.net/projects/adminer/forums/forum/960418/topic/4568650
? Filter by value in row under <thead> in select
? Column and table names auto-completition in SQL textarea - http://blog.quplo.com/2010/06/css-code-completion-in-your-browser/
? Aliasing of built-in functions can save 7 KB, function minification can save 7 KB, substitution of repetitive $a["a"] can save 4 KB, substitution of $_GET and friends can save 2 KB, aliasing of $connection->query can save 24 B, JS Closure compiler can save 2 KB, not enclosing HTML attribute values can save 1.2 KB, replacing \\n by \n can save .3 KB