From 5a73c01212dadee65dcec58492d3922e9b84afde Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Tue, 28 Sep 2010 10:02:55 +0200 Subject: [PATCH] Treat binary type as hex --- adminer/drivers/mysql.inc.php | 1 + adminer/include/adminer.inc.php | 11 +++++++---- adminer/include/functions.inc.php | 8 ++++---- adminer/select.inc.php | 2 +- changes.txt | 3 ++- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index 059e0c5b..b7eb92bf 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -915,6 +915,7 @@ if (!defined("DRIVER")) { $edit_functions = array( ///< @var array of array("$type|$type2" => "$function/$function2") functions used in editing, [0] - edit and insert, [1] - edit only array( "char" => "md5/sha1/password/encrypt/uuid", //! JavaScript for disabling maxlength + "binary" => "md5/sha1/hex", "date|time" => "now", ), array( "int|float|double|decimal" => "+/-", diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index f2144ba7..6a5897e5 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -150,8 +150,8 @@ document.getElementById('username').focus(); * @return string */ function selectVal($val, $link, $field) { - $return = ($val != "NULL" && $field["type"] == "char" ? "$val" : $val); - if (ereg('binary|blob|bytea|raw|file', $field["type"]) && !is_utf8($val)) { + $return = ($val != "NULL" && ereg("^char|binary", $field["type"]) ? "$val" : $val); + if (ereg('blob|bytea|raw|file', $field["type"]) && !is_utf8($val)) { $return = lang('%d byte(s)', strlen(html_entity_decode($val, ENT_QUOTES))); } return ($link ? "$return" : $return); @@ -163,7 +163,7 @@ document.getElementById('username').focus(); * @return string */ function editVal($val, $field) { - return $val; + return (ereg("binary", $field["type"]) ? reset(unpack("H*", $val)) : $val); } /** Print columns box in select @@ -449,9 +449,12 @@ document.getElementById('username').focus(); $return = idf_escape($name) . " $function " . (preg_match("~^([0-9]+|'[0-9.: -]') [A-Z_]+$~i", $value) ? $value : $return); } elseif (ereg('^(addtime|subtime|concat)$', $function)) { $return = "$function(" . idf_escape($name) . ", $return)"; - } elseif (ereg('^(md5|sha1|password|encrypt)$', $function)) { + } elseif (ereg('^(md5|sha1|password|encrypt|hex)$', $function)) { $return = "$function($return)"; } + if (ereg("binary", $field["type"])) { + $return = "unhex($return)"; + } return $return; } diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 9bed5072..e994e66f 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -573,14 +573,14 @@ function input($field, $value, $function) { $checked = (is_int($value) ? ($value >> $i) & 1 : in_array($val, explode(",", $value), true)); echo " '; } - } elseif (ereg('binary|blob|bytea|raw|file', $field["type"]) && ini_bool("file_uploads")) { + } elseif (ereg('blob|bytea|raw|file', $field["type"]) && ini_bool("file_uploads")) { echo ""; } elseif (ereg('text|lob', $field["type"])) { echo "'; // 1.2em - line-height } else { // int(3) is only a display hint - $maxlength = (!ereg('int', $field["type"]) && preg_match('~^([0-9]+)(,([0-9]+))?$~', $field["length"], $match) ? ($match[1] + ($match[3] ? 1 : 0) + ($match[2] && !$field["unsigned"] ? 1 : 0)) : ($types[$field["type"]] ? $types[$field["type"]] + ($field["unsigned"] ? 0 : 1) : 0)); - echo " 20 ? " size='40'" : "") . "$attrs>"; + $maxlength = (!ereg('int', $field["type"]) && preg_match('~^([0-9]+)(,([0-9]+))?$~', $field["length"], $match) ? ((ereg("binary", $field["type"]) ? 2 : 1) * $match[1] + ($match[3] ? 1 : 0) + ($match[2] && !$field["unsigned"] ? 1 : 0)) : ($types[$field["type"]] ? $types[$field["type"]] + ($field["unsigned"] ? 0 : 1) : 0)); + echo " 20 ? " size='40'" : "") . "$attrs>"; } } } @@ -615,7 +615,7 @@ function process_input($field) { if ($field["type"] == "set") { return array_sum((array) $value); } - if (ereg('binary|blob|bytea|raw|file', $field["type"]) && ini_bool("file_uploads")) { + if (ereg('blob|bytea|raw|file', $field["type"]) && ini_bool("file_uploads")) { $file = get_file("fields-$idf"); if (!is_string($file)) { return false; //! report errors diff --git a/adminer/select.inc.php b/adminer/select.inc.php index e2f332be..23af29b4 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -286,7 +286,7 @@ if (!$columns) { if (!isset($val)) { $val = "NULL"; } else { - if (ereg('binary|blob|bytea|raw|file', $field["type"]) && $val != "") { + if (ereg('blob|bytea|raw|file', $field["type"]) && $val != "") { $link = h(ME . 'download=' . urlencode($TABLE) . '&field=' . urlencode($key) . $unique_idf); } if ($val == "") { diff --git a/changes.txt b/changes.txt index d537b72b..834eed71 100644 --- a/changes.txt +++ b/changes.txt @@ -4,6 +4,7 @@ Allow concurrent logins on the same server Allow permanent login without customization In-place editation in select Foreign key options in Table creation +Treat binary type as hex Show number of tables in server overview Operator LIKE %% Remember export parameters in cookie @@ -19,7 +20,7 @@ Ability to jump to any page in select by JavaScript Display comment in table overview Link last page above data in select Link table names in SQL queries -Japanese translation +Japanese and Tamil translation Defer table information in database overview to JavaScript (performance) Big tables optimizations (performance)