Permalink
Browse files

Work with default values

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1169 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent 5c862ba commit 5cac902d7588be0d43dae1122ebe3a7f7bb2f20b jakubvrana committed Oct 6, 2009
Showing with 12 additions and 9 deletions.
  1. +5 −0 adminer/create.inc.php
  2. +5 −7 adminer/include/editing.inc.php
  3. +1 −1 adminer/include/mysql.inc.php
  4. +1 −1 adminer/procedure.inc.php
View
@@ -37,6 +37,11 @@
$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;
}
@@ -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"])
;
}
@@ -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"],
@@ -42,7 +42,7 @@
<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>

0 comments on commit 5cac902

Please sign in to comment.