Work with default values
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1169 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
5c862bac67
commit
5cac902d75
|
@ -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"]]]);
|
$type_field = (isset($types[$field["type"]]) ? $field : $referencable_primary[$foreign_keys[$field["type"]]]);
|
||||||
if (strlen($field["field"])) {
|
if (strlen($field["field"])) {
|
||||||
if ($type_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"]) {
|
if (!$field["has_default"]) {
|
||||||
$field["default"] = null;
|
$field["default"] = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,8 +102,6 @@ function edit_type($key, $field, $collations, $foreign_keys = array()) {
|
||||||
<td><?php
|
<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 "<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 ($unsigned ? " <select name='$key" . "[unsigned]'" . (!$field["type"] || ereg('(int|float|double|decimal)$', $field["type"]) ? "" : " class='hidden'") . '><option>' . optionlist($unsigned, $field["unsigned"]) . '</select>' : '');
|
||||||
?>
|
|
||||||
<?php
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function process_length($length) {
|
function process_length($length) {
|
||||||
|
@ -112,7 +110,7 @@ function process_length($length) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function process_type($field, $collate = "COLLATE") {
|
function process_type($field, $collate = "COLLATE") {
|
||||||
global $connection, $enum_length, $unsigned;
|
global $connection, $unsigned;
|
||||||
return " $field[type]"
|
return " $field[type]"
|
||||||
. (strlen($field["length"]) && !ereg('^date|time$', $field["type"]) ? "(" . process_length($field["length"]) . ")" : "")
|
. (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]" : "")
|
. (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) {
|
function process_field($field, $type_field) {
|
||||||
global $connection;
|
global $connection;
|
||||||
$default = $field["default"] . ($field["on_update"] ? " ON UPDATE $field[on_update]" : "");
|
|
||||||
return idf_escape($field["field"]) . process_type($type_field)
|
return idf_escape($field["field"]) . process_type($type_field)
|
||||||
. ($field["null"] ? " NULL" : " NOT NULL") // NULL for timestamp
|
. ($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"])
|
. " COMMENT " . $connection->quote($field["comment"])
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
|
@ -223,7 +223,7 @@ function fields($table) {
|
||||||
"default" => (strlen($row["Default"]) || ereg("char", $match[1]) ? $row["Default"] : null),
|
"default" => (strlen($row["Default"]) || ereg("char", $match[1]) ? $row["Default"] : null),
|
||||||
"null" => ($row["Null"] == "YES"),
|
"null" => ($row["Null"] == "YES"),
|
||||||
"auto_increment" => ($row["Extra"] == "auto_increment"),
|
"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"],
|
"collation" => $row["Collation"],
|
||||||
"privileges" => array_flip(explode(",", $row["Privileges"])),
|
"privileges" => array_flip(explode(",", $row["Privileges"])),
|
||||||
"comment" => $row["Comment"],
|
"comment" => $row["Comment"],
|
||||||
|
|
|
@ -42,7 +42,7 @@ if ($_POST) {
|
||||||
<form action="" method="post" id="form">
|
<form action="" method="post" id="form">
|
||||||
<table cellspacing="0">
|
<table cellspacing="0">
|
||||||
<?php edit_fields($row["fields"], $collations, $routine); ?>
|
<?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>
|
</table>
|
||||||
<p><textarea name="definition" rows="10" cols="80" style="width: 98%;"><?php echo h($row["definition"]); ?></textarea>
|
<p><textarea name="definition" rows="10" cols="80" style="width: 98%;"><?php echo h($row["definition"]); ?></textarea>
|
||||||
<p>
|
<p>
|
||||||
|
|
Loading…
Reference in a new issue