Skip to content
Browse files

Empty value in Editor as NULL

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@886 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent e13720e commit a78c941cd47c6da70b56b391006676e33d52fe06 jakubvrana committed Jul 23, 2009
Showing with 47 additions and 13 deletions.
  1. +27 −0 adminer/include/adminer.inc.php
  2. +1 −13 adminer/include/functions.inc.php
  3. +19 −0 editor/include/adminer.inc.php
View
27 adminer/include/adminer.inc.php
@@ -166,6 +166,33 @@ function adminer_edit_input($table, $field) {
return call_adminer('edit_input', false, $table, $field);
}
+/** Process sent input
+* @param string field name
+* @param array single field from fields()
+* @return string expression to use in a query
+*/
+function adminer_process_input($name, $field) {
+ global $dbh;
+ $idf = bracket_escape($name);
+ $function = $_POST["function"][$idf];
+ $value = $_POST["fields"][$idf];
+ $return = $dbh->quote($value);
+ if (ereg('^(now|uuid)$', $function)) {
+ $return = "$function()";
+ } elseif (ereg('^[+-]$', $function)) {
+ $return = idf_escape($name) . " $function $return";
+ } elseif (ereg('^[+-] interval$', $function)) {
+ $return = idf_escape($name) . " $function " . (preg_match("~^([0-9]+|'[0-9.: -]') [A-Z_]+$~i", $value) ? $value : $return);
+ } elseif (ereg('^(addtime|subtime)$', $function)) {
+ $return = "$function(" . idf_escape($name) . ", $return)";
+ } elseif (ereg('^(md5|sha1|password)$', $function)) {
+ $return = "$function($return)";
+ } elseif (ereg('date|time', $field["type"]) && $value == "CURRENT_TIMESTAMP") {
+ $return = $value;
+ }
+ return call_adminer('process_input', $return, $name, $field);
+}
+
/** Prints navigation after Adminer title
* @param string can be "auth" if there is no database connection or "db" if there is no database selected
* @return bool true if default navigation should be printed
View
14 adminer/include/functions.inc.php
@@ -339,20 +339,8 @@ function process_input($name, $field) {
return false; //! report errors
}
return "_binary" . $dbh->quote($file);
- } elseif (ereg('^(now|uuid)$', $function)) {
- return "$function()";
- } elseif (ereg('^[+-]$', $function)) {
- return idf_escape($name) . " $function " . $dbh->quote($value);
- } elseif (ereg('^[+-] interval$', $function)) {
- return idf_escape($name) . " $function " . (preg_match("~^([0-9]+|'[0-9.: -]') [A-Z_]+$~i", $value) ? $value : $dbh->quote($value));
- } elseif (ereg('^(addtime|subtime)$', $function)) {
- return "$function(" . idf_escape($name) . ", " . $dbh->quote($value) . ")";
- } elseif (ereg('^(md5|sha1|password)$', $function)) {
- return "$function(" . $dbh->quote($value) . ")";
- } elseif ($field["type"] == "timestamp" && $value == "CURRENT_TIMESTAMP") {
- return $value;
} else {
- return $dbh->quote($value);
+ return adminer_process_input($name, $field);
}
}
View
19 editor/include/adminer.inc.php
@@ -146,6 +146,25 @@ function adminer_edit_input($table, $field) {
return call_adminer('edit_input', $return, $table, $field);
}
+/** Process sent input
+* @param string field name
+* @param array single field from fields()
+* @return string expression to use in a query
+*/
+function adminer_process_input($name, $field) {
+ global $dbh;
+ $idf = bracket_escape($name);
+ $function = $_POST["function"][$idf];
+ $value = $_POST["fields"][$idf];
+ $return = $dbh->quote($value);
+ if (!ereg('varchar|text', $field["type"]) && !strlen($value)) {
+ $return = "NULL";
+ } elseif (ereg('date|time', $field["type"]) && $value == "CURRENT_TIMESTAMP") {
+ $return = $value;
+ }
+ return call_adminer('process_input', $return, $name, $field);
+}
+
function adminer_navigation($missing) {
global $SELF;
if (call_adminer('navigation', true, $missing) && $missing != "auth") {

0 comments on commit a78c941

Please sign in to comment.
Something went wrong with that request. Please try again.