From c4a57246ac86f299941b2afaae381ea12422646c Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Sun, 13 May 2012 23:24:39 -0700 Subject: [PATCH] Simplify work with NULL values in select --- adminer/include/adminer.inc.php | 4 ++-- adminer/select.inc.php | 14 +++++++------- changes.txt | 1 + editor/include/adminer.inc.php | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index a46461dd..dd8ff195 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -184,9 +184,9 @@ username.form['driver'].onchange(); * @return string */ function selectVal($val, $link, $field) { - $return = ($val != "NULL" && ereg("char|binary", $field["type"]) && !ereg("var", $field["type"]) ? "$val" : $val); + $return = ($val === null ? "NULL" : (ereg("char|binary", $field["type"]) && !ereg("var", $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 = lang('%d byte(s)', strlen($val)); } return ($link ? "$return" : $return); } diff --git a/adminer/select.inc.php b/adminer/select.inc.php index e0d994c5..3a5a3e41 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -297,18 +297,18 @@ if (!$columns) { } $link = ""; $val = $adminer->editVal($val, $field); - if (!isset($val)) { - $val = "NULL"; - } 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 = " "; - } 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 diff --git a/changes.txt b/changes.txt index 4ee0aea5..0841cc81 100644 --- a/changes.txt +++ b/changes.txt @@ -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 diff --git a/editor/include/adminer.inc.php b/editor/include/adminer.inc.php index 11d40d54..1830851e 100644 --- a/editor/include/adminer.inc.php +++ b/editor/include/adminer.inc.php @@ -159,7 +159,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5 } function selectVal($val, $link, $field) { - $return = ($val == "NULL" ? " " : $val); + $return = ($val === null ? " " : $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