Skip to content

Commit

Permalink
Simplify work with NULL values in select
Browse files Browse the repository at this point in the history
  • Loading branch information
vrana committed May 14, 2012
1 parent 20cf6d2 commit c4a5724
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions adminer/include/adminer.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ function rowDescriptions($rows, $foreignKeys) {
* @return string
*/
function selectVal($val, $link, $field) {
$return = ($val != "<i>NULL</i>" && ereg("char|binary", $field["type"]) && !ereg("var", $field["type"]) ? "<code>$val</code>" : $val);
$return = ($val === null ? "<i>NULL</i>" : (ereg("char|binary", $field["type"]) && !ereg("var", $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 = lang('%d byte(s)', strlen($val));
}
return ($link ? "<a href='$link'>$return</a>" : $return);
}
Expand Down
14 changes: 7 additions & 7 deletions adminer/select.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,18 +297,18 @@
}
$link = "";
$val = $adminer->editVal($val, $field);
if (!isset($val)) {
$val = "<i>NULL</i>";
} else {
if ($val !== null) {
if (ereg('blob|bytea|raw|file', $field["type"]) && $val != "") {
$link = h(ME . 'download=' . urlencode($TABLE) . '&field=' . urlencode($key) . $unique_idf);
}
if ($val === "") { // === - may be int
$val = "&nbsp;";
} elseif ($text_length != "" && ereg('text|blob', $field["type"]) && is_utf8($val)) {
$val = shorten_utf8($val, max(0, +$text_length)); // usage of LEFT() would reduce traffic but complicate query - expected average speedup: .001 s VS .01 s on local network
} else {
$val = h($val);
} elseif (is_utf8($val)) {
if ($text_length != "" && ereg('text|blob', $field["type"])) {
$val = shorten_utf8($val, max(0, +$text_length)); // usage of LEFT() would reduce traffic but complicate query - expected average speedup: .001 s VS .01 s on local network
} else {
$val = h($val);
}
}

if (!$link) { // link related items
Expand Down
1 change: 1 addition & 0 deletions changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ MySQL: inform about disabled event_scheduler
SQLite: support binary data
PostgreSQL: approximate row count in table overview
Oracle: schema, processlist, table overview numbers
Simplify work with NULL values (customization)
Replace JSMin by better JavaScript minifier
Don't use AJAX links and forms
Ukrainian translation
Expand Down
2 changes: 1 addition & 1 deletion editor/include/adminer.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function rowDescriptions($rows, $foreignKeys) {
}

function selectVal($val, $link, $field) {
$return = ($val == "<i>NULL</i>" ? "&nbsp;" : $val);
$return = ($val === null ? "&nbsp;" : $val);
if (ereg('blob|bytea', $field["type"]) && !is_utf8($val)) {
$return = lang('%d byte(s)', strlen($val));
if (ereg("^(GIF|\xFF\xD8\xFF|\x89PNG\x0D\x0A\x1A\x0A)", $val)) { // GIF|JPG|PNG, getimagetype() works with filename
Expand Down

0 comments on commit c4a5724

Please sign in to comment.