From 5acd5a2afb484608eaed1853108a2e1ce51ec59e Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Mon, 13 Jul 2009 16:33:54 +0000 Subject: [PATCH] Use NOW for timestamp edit (thanks to paranoiq) git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@814 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- adminer/call.inc.php | 2 +- adminer/edit.inc.php | 3 ++- adminer/include/functions.inc.php | 4 ++-- adminer/include/mysql.inc.php | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/adminer/call.inc.php b/adminer/call.inc.php index 5d2e1475..cc4666a7 100644 --- a/adminer/call.inc.php +++ b/adminer/call.inc.php @@ -57,7 +57,7 @@ if ($in) { if (strlen($value) && ($field["type"] == "enum" || $field["type"] == "set")) { $value = intval($value); } - input($key, $field, $value); // param name can be empty + input($key, $field, $value, (string) $_POST["function"][$name]); // param name can be empty echo "\n"; } echo "\n"; diff --git a/adminer/edit.inc.php b/adminer/edit.inc.php index 40ca0081..c94a824c 100644 --- a/adminer/edit.inc.php +++ b/adminer/edit.inc.php @@ -78,7 +78,8 @@ if ($fields) { ? (strlen($row[$name]) && ($field["type"] == "enum" || $field["type"] == "set") ? intval($row[$name]) : $row[$name]) : ($_POST["clone"] && $field["auto_increment"] ? "" : ($where ? $field["default"] : false)) ); - input($name, $field, $value); + $function = ($_POST["save"] ? (string) $_POST["function"][$name] : ($field[($where ? "on_update" : "default")] == "CURRENT_TIMESTAMP" ? "now" : ($value === false ? null : (isset($value) ? '' : 'NULL')))); + input($name, $field, $value, $function); if (isset($_GET["default"]) && $field["type"] == "timestamp") { if (!isset($create) && !$_POST) { //! disable sql_mode NO_FIELD_OPTIONS diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 4b34ffe6..791dca36 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -257,7 +257,7 @@ function hidden_fields($process, $ignore = array()) { } } -function input($name, $field, $value) { +function input($name, $field, $value, $function) { global $types; $name = htmlspecialchars(bracket_escape($name)); echo ""; @@ -301,7 +301,7 @@ function input($name, $field, $value) { if ($field["null"] || isset($_GET["default"])) { array_unshift($options, "NULL"); } - echo (count($options) > 1 || isset($_GET["select"]) ? '' : " ") . ''; + echo (count($options) > 1 || isset($_GET["select"]) ? '' : " ") . ''; if ($field["type"] == "set") { //! 64 bits preg_match_all("~'((?:[^']+|'')*)'~", $field["length"], $matches); foreach ($matches[1] as $i => $val) { diff --git a/adminer/include/mysql.inc.php b/adminer/include/mysql.inc.php index e55614a3..eecba2f6 100644 --- a/adminer/include/mysql.inc.php +++ b/adminer/include/mysql.inc.php @@ -262,6 +262,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] : ""), "collation" => $row["Collation"], "privileges" => array_flip(explode(",", $row["Privileges"])), "comment" => $row["Comment"],