Adminer Editor: Missing booelan support on PostgreSQL
Database management in a single PHP file
Brought to you by:
jakubvrana
Adminer Editor does not support booleans on PostgreSQL. The following patch seems to fix it but did not test it with other drivers.
--- a/adminer/include/functions.inc.php
+++ b/adminer/include/functions.inc.php
@@ -181,7 +181,7 @@
* @return string
*/
function checkbox($name, $value, $checked, $label = "", $onclick = "", $class = "", $labelled_by = "") {
- $return = "<input type='checkbox' name='$name' value='" . h($value) . "'"
+ $return = "<input type='checkbox' name='$name' value='1'"
. ($checked ? " checked" : "")
. ($labelled_by ? " aria-labelledby='$labelled_by'" : "")
. ">"
--- a/editor/include/adminer.inc.php
+++ b/editor/include/adminer.inc.php
@@ -484,7 +484,7 @@
);
}
if (like_bool($field)) {
- return '<input type="checkbox" value="' . h($value ? $value : 1) . '"' . ($value ? ' checked' : '') . "$attrs>";
+ return '<input type="checkbox" value="' . h($value ? $value : 1) . '"' . (preg_match('~^(1|t|true|y|yes|on)$~i', $value) ? " checked='checked'" : "") . "$attrs>";
}
$hint = "";
if (preg_match('~time~', $field["type"])) {
@@ -516,7 +516,7 @@
}
$return = ($field["type"] == "bit" && preg_match('~^[0-9]+$~', $value) ? $return : q($return));
if ($value == "" && like_bool($field)) {
- $return = "0";
+ $return = false;
} elseif ($value == "" && ($field["null"] || !preg_match('~char|text~', $field["type"]))) {
$return = "NULL";
} elseif (preg_match('~^(md5|sha1)$~', $function)) {
I've included the
preg_matchpart, others seem not required.