diff --git a/adminer/create.inc.php b/adminer/create.inc.php index eb37ad48..b636ca18 100644 --- a/adminer/create.inc.php +++ b/adminer/create.inc.php @@ -36,7 +36,7 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"] $fields[] = "\n" . (strlen($_GET["create"]) ? (strlen($field["orig"]) ? "CHANGE " . idf_escape($field["orig"]) . " " : "ADD ") : " ") . idf_escape($field["field"]) . process_type($type_field) . ($field["null"] ? " NULL" : " NOT NULL") // NULL for timestamp - . (strlen($_GET["create"]) && strlen($field["orig"]) && isset($orig_fields[$field["orig"]]["default"]) && $field["type"] != "timestamp" ? " DEFAULT " . $dbh->quote($orig_fields[$field["orig"]]["default"]) : "") //! timestamp + . (!$field["has_default"] || $field["auto_increment"] || ereg('text|blob', $field["type"]) ? "" : " DEFAULT " . ($field["type"] == "timestamp" && eregi("^CURRENT_TIMESTAMP( on update CURRENT_TIMESTAMP)?$", $field["default"]) ? $field["default"] : $dbh->quote($field["default"]))) . ($key == $_POST["auto_increment_col"] ? " AUTO_INCREMENT$auto_increment_index" : "") . " COMMENT " . $dbh->quote($field["comment"]) . (strlen($_GET["create"]) ? " $after" : "") @@ -105,7 +105,14 @@ if ($_POST) { $row = table_status($_GET["create"]); table_comment($row); $row["name"] = $_GET["create"]; - $row["fields"] = array_values($orig_fields); + $row["fields"] = array(); + 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 ($dbh->server_info >= 5.1) { $from = "FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = " . $dbh->quote($_GET["db"]) . " AND TABLE_NAME = " . $dbh->quote($_GET["create"]); $result = $dbh->query("SELECT PARTITION_METHOD, PARTITION_ORDINAL_POSITION, PARTITION_EXPRESSION $from ORDER BY PARTITION_ORDINAL_POSITION DESC LIMIT 1"); @@ -124,7 +131,7 @@ if ($_POST) { } $collations = collations(); -$suhosin = floor(extension_loaded("suhosin") ? (min(ini_get("suhosin.request.max_vars"), ini_get("suhosin.post.max_vars")) - 13) / 8 : 0); +$suhosin = floor(extension_loaded("suhosin") ? (min(ini_get("suhosin.request.max_vars"), ini_get("suhosin.post.max_vars")) - 13) / 10 : 0); // 10 - number of fields per row, 13 - number of other fields if ($suhosin && count($row["fields"]) > $suhosin) { echo "

" . h(lang('Maximum number of allowed fields exceeded. Please increase %s and %s.', 'suhosin.post.max_vars', 'suhosin.request.max_vars')) . "\n"; } @@ -143,7 +150,8 @@ if ($suhosin && count($row["fields"]) > $suhosin) { : "> : " maxlength="60">

diff --git a/adminer/edit.inc.php b/adminer/edit.inc.php index ffe892e7..951be334 100644 --- a/adminer/edit.inc.php +++ b/adminer/edit.inc.php @@ -3,14 +3,14 @@ $where = (isset($_GET["select"]) ? "" : where($_GET)); $update = ($where || $_POST["edit"]); $fields = fields($_GET["edit"]); foreach ($fields as $name => $field) { - if ((isset($_GET["default"]) ? $field["auto_increment"] || ereg('text|blob', $field["type"]) : !isset($field["privileges"][$update ? "update" : "insert"])) || !strlen($adminer->fieldName($field))) { + if (!isset($field["privileges"][$update ? "update" : "insert"]) || !strlen($adminer->fieldName($field))) { unset($fields[$name]); } } if ($_POST && !$error && !isset($_GET["select"])) { $location = $_SERVER["REQUEST_URI"]; // continue edit or insert if (!$_POST["insert"]) { - $location = ME . (isset($_GET["default"]) ? "table=" : "select=") . urlencode($_GET["edit"]); + $location = ME . "select=" . urlencode($_GET["edit"]); $i = 0; // append &set converted to &where foreach ((array) $_GET["set"] as $key => $val) { if ($val == $_POST["fields"][$key]) { @@ -21,24 +21,14 @@ if ($_POST && !$error && !isset($_GET["select"])) { $set = array(); foreach ($fields as $name => $field) { $val = process_input($field); - if (!isset($_GET["default"])) { - if ($val !== false || !$update) { - $set[] = "\n" . idf_escape($name) . " = " . ($val !== false ? $val : "''"); - } - } elseif ($val !== false) { - if ($field["type"] == "timestamp" && $val != "NULL") { //! doesn't allow DEFAULT NULL and no ON UPDATE - $set[] = "\nMODIFY " . idf_escape($name) . " timestamp" . ($field["null"] ? " NULL" : "") . " DEFAULT $val" . ($_POST["on_update"][bracket_escape($name)] ? " ON UPDATE CURRENT_TIMESTAMP" : ""); - } else { - $set[] = "\nALTER " . idf_escape($name) . ($val == "NULL" ? " DROP DEFAULT" : " SET DEFAULT $val"); - } + if ($val !== false || !$update) { + $set[] = "\n" . idf_escape($name) . " = " . ($val !== false ? $val : "''"); } } if (!$set) { redirect($location); } - if (isset($_GET["default"])) { - query_redirect("ALTER TABLE " . idf_escape($_GET["edit"]) . implode(",", $set), $location, lang('Default values have been set.')); - } elseif ($update) { + if ($update) { query_redirect("UPDATE " . idf_escape($_GET["edit"]) . " SET" . implode(",", $set) . "\nWHERE $where\nLIMIT 1", $location, lang('Item has been updated.')); } else { query_redirect("INSERT INTO " . idf_escape($_GET["edit"]) . " SET" . implode(",", $set), $location, lang('Item has been inserted.')); @@ -47,9 +37,9 @@ if ($_POST && !$error && !isset($_GET["select"])) { $table_name = $adminer->tableName(table_status($_GET["edit"])); page_header( - (isset($_GET["default"]) ? lang('Default values') : ($update ? lang('Edit') : lang('Insert'))), + ($update ? lang('Edit') : lang('Insert')), $error, - array((isset($_GET["default"]) ? "table" : "select") => array($_GET["edit"], $table_name)), + array("select" => array($_GET["edit"], $table_name)), $table_name ); @@ -89,14 +79,6 @@ if ($fields) { } $function = ($_POST["save"] ? (string) $_POST["function"][$name] : ($where && $field["on_update"] == "CURRENT_TIMESTAMP" ? "now" : ($value === false ? null : (isset($value) ? '' : 'NULL')))); input($field, $value, $function); - if (isset($_GET["default"]) && $field["type"] == "timestamp") { - if (!isset($create) && !$_POST) { - //! disable sql_mode NO_FIELD_OPTIONS - $create = $dbh->result($dbh->query("SHOW CREATE TABLE " . idf_escape($_GET["edit"])), 1); - } - $checked = ($_POST ? $_POST["on_update"][bracket_escape($name)] : preg_match("~\n\\s*" . preg_quote(idf_escape($name), '~') . " timestamp.* on update CURRENT_TIMESTAMP~i", $create)); - echo ''; - } echo "\n"; } echo "\n"; @@ -111,7 +93,7 @@ if (isset($_GET["select"])) { } if ($fields) { echo "\n"; - if (!isset($_GET["default"]) && !isset($_GET["select"])) { + if (!isset($_GET["select"])) { echo "\n"; } } diff --git a/adminer/editing.js b/adminer/editing.js index 802b4abc..1d1bafcb 100644 --- a/adminer/editing.js +++ b/adminer/editing.js @@ -125,10 +125,10 @@ function editing_type_change(type) { } } -function column_comments_click(checked) { +function column_show(checked, column) { var trs = document.getElementById('edit-fields').getElementsByTagName('tr'); for (var i=0; i < trs.length; i++) { - trs[i].getElementsByTagName('td')[5].className = (checked ? '' : 'hidden'); + trs[i].getElementsByTagName('td')[column].className = (checked ? 'nowrap' : 'hidden'); } } diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 77954298..2cbfa2d1 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -346,26 +346,24 @@ class Adminer { */ function editFunctions($field) { $return = array(""); - if (!isset($_GET["default"])) { - if (ereg('char|date|time', $field["type"])) { - $return = (ereg('char', $field["type"]) ? array("", "md5", "sha1", "password", "uuid") : array("", "now")); //! JavaScript for disabling maxlength + if (ereg('char|date|time', $field["type"])) { + $return = (ereg('char', $field["type"]) ? array("", "md5", "sha1", "password", "uuid") : array("", "now")); //! JavaScript for disabling maxlength + } + if (!isset($_GET["call"]) && (isset($_GET["select"]) || where($_GET))) { + // relative functions + if (ereg('int|float|double|decimal', $field["type"])) { + $return = array("", "+", "-"); } - if (!isset($_GET["call"]) && (isset($_GET["select"]) || where($_GET))) { - // relative functions - if (ereg('int|float|double|decimal', $field["type"])) { - $return = array("", "+", "-"); - } - if (ereg('date', $field["type"])) { - $return[] = "+ interval"; - $return[] = "- interval"; - } - if (ereg('time', $field["type"])) { - $return[] = "addtime"; - $return[] = "subtime"; - } + if (ereg('date', $field["type"])) { + $return[] = "+ interval"; + $return[] = "- interval"; + } + if (ereg('time', $field["type"])) { + $return[] = "addtime"; + $return[] = "subtime"; } } - if ($field["null"] || isset($_GET["default"])) { + if ($field["null"]) { array_unshift($return, "NULL"); } return $return; diff --git a/adminer/include/editing.inc.php b/adminer/include/editing.inc.php index e0168b0d..e5f18799 100644 --- a/adminer/include/editing.inc.php +++ b/adminer/include/editing.inc.php @@ -73,6 +73,7 @@ function edit_fields($fields, $collations, $type = "TABLE", $allowed = 0, $forei +