Treat binary type as hex

This commit is contained in:
Jakub Vrana 2010-09-28 10:02:55 +02:00
parent 4af4018a06
commit 5a73c01212
5 changed files with 15 additions and 10 deletions

View file

@ -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" => "+/-",

View file

@ -150,8 +150,8 @@ document.getElementById('username').focus();
* @return string
*/
function selectVal($val, $link, $field) {
$return = ($val != "<i>NULL</i>" && $field["type"] == "char" ? "<code>$val</code>" : $val);
if (ereg('binary|blob|bytea|raw|file', $field["type"]) && !is_utf8($val)) {
$return = ($val != "<i>NULL</i>" && ereg("^char|binary", $field["type"]) ? "<code>$val</code>" : $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 ? "<a href='$link'>$return</a>" : $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;
}

View file

@ -573,14 +573,14 @@ function input($field, $value, $function) {
$checked = (is_int($value) ? ($value >> $i) & 1 : in_array($val, explode(",", $value), true));
echo " <label><input type='checkbox' name='fields[$name][$i]' value='" . (1 << $i) . "'" . ($checked ? ' checked' : '') . "$onchange>" . h($val) . '</label>';
}
} 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 "<input type='file' name='fields-$name'$onchange>";
} elseif (ereg('text|lob', $field["type"])) {
echo "<textarea " . ($jush != "sqlite" || ereg("\n", $value) ? "cols='50' rows='12'" : "cols='30' rows='1' style='height: 1.2em;'") . "$attrs>" . h($value) . '</textarea>'; // 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 "<input value='" . h($value) . "'" . ($maxlength ? " maxlength='$maxlength'" : "") . (ereg('char', $field["type"]) && $field["length"] > 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 "<input value='" . h($value) . "'" . ($maxlength ? " maxlength='$maxlength'" : "") . (ereg('char|binary', $field["type"]) && $maxlength > 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

View file

@ -286,7 +286,7 @@ if (!$columns) {
if (!isset($val)) {
$val = "<i>NULL</i>";
} 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 == "") {

View file

@ -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)