]> git.joonet.de Git - adminer.git/commitdiff
Selectable ON UPDATE CURRENT_TIMESTAMP field in create table
authorJakub Vrana <jakub@vrana.cz>
Wed, 17 Apr 2013 16:41:58 +0000 (09:41 -0700)
committerJakub Vrana <jakub@vrana.cz>
Wed, 17 Apr 2013 16:41:58 +0000 (09:41 -0700)
adminer/create.inc.php
adminer/include/editing.inc.php
adminer/static/editing.js
changes.txt
todo.txt

index 4ce934b792111932b84bfb5263c71e39bacb7b3b..a88e9a82f29007f7b217be05297e64d4e2f0e470 100644 (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")) {
index 2db781e4af36a2dae6dc29a378cb7e5c23ac51fa..7115f5b7329a4ebc870e82d08b6fdf6df36f9872 100644 (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),
        );
index 78a08f81b53bde0c2a4acdc938c5a69ac7a56db0..6b6bba4dc6ea478dbc2ab1f34ec91ed4920b6016 100644 (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');
                }
index 784425ea97d7d8be44aac4d3b1eebf2f127fcbdc..1c2e580657ccb52495fbd6dfc7636222f6776e4c 100644 (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)
index 4c59583be12e261b19ffa427eab217dec4bc0030..6448feba31e9fc008054e33f190c99f5c7435d52 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -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