Simplify work with NULL values in select

This commit is contained in:
Jakub Vrana 2012-05-13 23:24:39 -07:00
parent 20cf6d29c5
commit c4a57246ac
4 changed files with 11 additions and 10 deletions

View file

@ -184,9 +184,9 @@ username.form['driver'].onchange();
* @return string * @return string
*/ */
function selectVal($val, $link, $field) { 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)) { 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); return ($link ? "<a href='$link'>$return</a>" : $return);
} }

View file

@ -297,18 +297,18 @@ if (!$columns) {
} }
$link = ""; $link = "";
$val = $adminer->editVal($val, $field); $val = $adminer->editVal($val, $field);
if (!isset($val)) { if ($val !== null) {
$val = "<i>NULL</i>";
} else {
if (ereg('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); $link = h(ME . 'download=' . urlencode($TABLE) . '&field=' . urlencode($key) . $unique_idf);
} }
if ($val === "") { // === - may be int if ($val === "") { // === - may be int
$val = "&nbsp;"; $val = "&nbsp;";
} elseif ($text_length != "" && ereg('text|blob', $field["type"]) && is_utf8($val)) { } elseif (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 if ($text_length != "" && ereg('text|blob', $field["type"])) {
} else { $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
$val = h($val); } else {
$val = h($val);
}
} }
if (!$link) { // link related items if (!$link) { // link related items

View file

@ -7,6 +7,7 @@ MySQL: inform about disabled event_scheduler
SQLite: support binary data SQLite: support binary data
PostgreSQL: approximate row count in table overview PostgreSQL: approximate row count in table overview
Oracle: schema, processlist, table overview numbers Oracle: schema, processlist, table overview numbers
Simplify work with NULL values (customization)
Replace JSMin by better JavaScript minifier Replace JSMin by better JavaScript minifier
Don't use AJAX links and forms Don't use AJAX links and forms
Ukrainian translation Ukrainian translation

View file

@ -159,7 +159,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
} }
function selectVal($val, $link, $field) { 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)) { if (ereg('blob|bytea', $field["type"]) && !is_utf8($val)) {
$return = lang('%d byte(s)', strlen($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 if (ereg("^(GIF|\xFF\xD8\xFF|\x89PNG\x0D\x0A\x1A\x0A)", $val)) { // GIF|JPG|PNG, getimagetype() works with filename