]> git.joonet.de Git - adminer.git/commitdiff
Work with default values
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Tue, 6 Oct 2009 10:40:52 +0000 (10:40 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Tue, 6 Oct 2009 10:40:52 +0000 (10:40 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1169 7c3ca157-0c34-0410-bff1-cbf682f78f5c

adminer/create.inc.php
adminer/include/editing.inc.php
adminer/include/mysql.inc.php
adminer/procedure.inc.php

index 5ff58c7e8952c3176c991a2de0442423c364c6d6..15da283fce91f0bb31854e2fe3a9321f39a5c0d3 100644 (file)
@@ -37,6 +37,11 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"]
                $type_field = (isset($types[$field["type"]]) ? $field : $referencable_primary[$foreign_keys[$field["type"]]]);
                if (strlen($field["field"])) {
                        if ($type_field) {
+                               $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 (!$field["has_default"]) {
                                        $field["default"] = null;
                                }
index 79509487fc3b54e827db7b6de7c3de8ef8fcc1d2..0bb59de4ec84b7856340aa7ea8c07be1ecb3a4fe 100644 (file)
@@ -100,10 +100,8 @@ function edit_type($key, $field, $collations, $foreign_keys = array()) {
 <td><select name="<?php echo $key; ?>[type]" class="type" onchange="editing_type_change(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">
 <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>' : '');
-?>
-<?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>' : '');
 }
 
 function process_length($length) {
@@ -112,7 +110,7 @@ function process_length($length) {
 }
 
 function process_type($field, $collate = "COLLATE") {
-       global $connection, $enum_length, $unsigned;
+       global $connection, $unsigned;
        return " $field[type]"
                . (strlen($field["length"]) && !ereg('^date|time$', $field["type"]) ? "(" . process_length($field["length"]) . ")" : "")
                . (ereg('int|float|double|decimal', $field["type"]) && in_array($field["unsigned"], $unsigned) ? " $field[unsigned]" : "")
@@ -122,10 +120,10 @@ function process_type($field, $collate = "COLLATE") {
 
 function process_field($field, $type_field) {
        global $connection;
-       $default = $field["default"] . ($field["on_update"] ? " ON UPDATE $field[on_update]" : "");
        return idf_escape($field["field"]) . process_type($type_field)
                . ($field["null"] ? " NULL" : " NOT NULL") // NULL for timestamp
-               . (!isset($field["default"]) || $field["auto_increment"] || ereg('text|blob', $field["type"]) ? "" : " DEFAULT " . ($field["type"] == "timestamp" && eregi("^CURRENT_TIMESTAMP( on update CURRENT_TIMESTAMP)?$", $default) ? $default : $connection->quote($default)))
+               . (!isset($field["default"]) ? "" : " DEFAULT " . ($field["type"] == "timestamp" && eregi("^CURRENT_TIMESTAMP$", $field["default"]) ? $field["default"] : $connection->quote($field["default"])))
+               . ($field["on_update"] ? " ON UPDATE $field[on_update]" : "")
                . " COMMENT " . $connection->quote($field["comment"])
        ;
 }
index 250db857c429894826bcdd94d611a45a284e85c8..ac78e6f64b8390f37fdd244d65f0f4e74beb0e56 100644 (file)
@@ -223,7 +223,7 @@ function fields($table) {
                                "default" => (strlen($row["Default"]) || ereg("char", $match[1]) ? $row["Default"] : null),
                                "null" => ($row["Null"] == "YES"),
                                "auto_increment" => ($row["Extra"] == "auto_increment"),
-                               "on_update" => (preg_match('~^on update (.+)~', $row["Extra"], $match) ? $match[1] : ""),
+                               "on_update" => (eregi('^on update (.+)', $row["Extra"], $match) ? $match[1] : ""), //! available since MySQL 5.1.23
                                "collation" => $row["Collation"],
                                "privileges" => array_flip(explode(",", $row["Privileges"])),
                                "comment" => $row["Comment"],
index a9e68652c4f9b341847259b2359f7341ffe18830..1d42eaba4710f8233cb2af01f0f8e7cbd5ec8f82 100644 (file)
@@ -42,7 +42,7 @@ if ($_POST) {
 <form action="" method="post" id="form">
 <table cellspacing="0">
 <?php edit_fields($row["fields"], $collations, $routine); ?>
-<?php if (isset($_GET["function"])) { ?><tr><td><?php echo lang('Return type'); ?><?php echo edit_type("returns", $row["returns"], $collations); ?><?php } ?>
+<?php if (isset($_GET["function"])) { ?><tr><td><?php echo lang('Return type') . edit_type("returns", $row["returns"], $collations); ?><?php } ?>
 </table>
 <p><textarea name="definition" rows="10" cols="80" style="width: 98%;"><?php echo h($row["definition"]); ?></textarea>
 <p>