Permalink
Browse files

Display SQL function with braces in select heading

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@894 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent 004d7a9 commit ba9c9a523bab9f1fcce6aa233542193150f0efad jakubvrana committed Jul 24, 2009
Showing with 13 additions and 5 deletions.
  1. +1 −1 adminer/include/adminer.inc.php
  2. +11 −3 adminer/select.inc.php
  3. +1 −1 editor/include/adminer.inc.php
@@ -59,7 +59,7 @@ function adminer_table_name($table_status) {
* @return string
*/
function adminer_field_name($field) {
- return call_adminer('field_name', ($field ? '<span title="' . htmlspecialchars($field["full_type"]) . '">' . htmlspecialchars($field["field"]) . '</span>' : "*"), $field);
+ return call_adminer('field_name', '<span title="' . htmlspecialchars($field["full_type"]) . '">' . htmlspecialchars($field["field"]) . '</span>', $field);
}
/** Links after select heading
View
@@ -31,11 +31,18 @@
$rights += $field["privileges"];
}
+function apply_sql_function($function, $column) {
+ return ($function
+ ? ($function == "distinct" ? "COUNT(DISTINCT " : strtoupper("$function(") . "$column)")
+ : $column
+ );
+}
+
$select = array(); // select expressions, empty for *
$group = array(); // expressions without aggregation - will be used for GROUP BY if an aggregation function is used
foreach ((array) $_GET["columns"] as $key => $val) {
if ($val["fun"] == "count" || (isset($columns[$val["col"]]) && (!$val["fun"] || in_array($val["fun"], $functions) || in_array($val["fun"], $grouping)))) {
- $select[$key] = (isset($columns[$val["col"]]) ? ($val["fun"] ? ($val["fun"] == "distinct" ? "COUNT(DISTINCT " : strtoupper("$val[fun](")) . idf_escape($val["col"]) . ")" : idf_escape($val["col"])) : "COUNT(*)");
+ $select[$key] = apply_sql_function($val["fun"], (isset($columns[$val["col"]]) ? idf_escape($val["col"]) : "*"));
if (!in_array($val["fun"], $grouping)) {
$group[] = $select[$key];
}
@@ -292,10 +299,11 @@
reset($select);
foreach ($rows[0] as $key => $val) {
$val = $_GET["columns"][key($select)];
- $name = adminer_field_name($fields[$select ? $val["col"] : $key]);
+ $field = $fields[$select ? $val["col"] : $key];
+ $name = ($field ? adminer_field_name($field) : "*");
if (strlen($name)) {
$names[$key] = $name;
- echo '<th><a href="' . htmlspecialchars(remove_from_uri('(order|desc)[^=]*') . '&order%5B0%5D=' . urlencode($key) . ($_GET["order"] == array($key) && !$_GET["desc"][0] ? '&desc%5B0%5D=1' : '')) . '">' . ($val["fun"] ? strtoupper($val["fun"]) . " $name" : $name) . "</a>";
+ echo '<th><a href="' . htmlspecialchars(remove_from_uri('(order|desc)[^=]*') . '&order%5B0%5D=' . urlencode($key) . ($_GET["order"] == array($key) && !$_GET["desc"][0] ? '&desc%5B0%5D=1' : '')) . '">' . apply_sql_function($val["fun"], $name) . "</a>";
}
next($select);
}
@@ -33,7 +33,7 @@ function adminer_table_name($table_status) {
}
function adminer_field_name($field) {
- return call_adminer('field_name', ($field ? htmlspecialchars(strlen($field["comment"]) ? $field["comment"] : $field["field"]) : "*"), $field);
+ return call_adminer('field_name', htmlspecialchars(strlen($field["comment"]) ? $field["comment"] : $field["field"]), $field);
}
function adminer_select_links($table_status) {

0 comments on commit ba9c9a5

Please sign in to comment.