Skip to content

Commit

Permalink
Fixes jdorn#81: Pivot report type is not formatting the SQL correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
uded committed Sep 5, 2013
1 parent fa73568 commit 7c12347
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/adodb/pivottable.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
*
* @returns Sql generated
*/

function PivotTableSQL(&$db, $tables, $rowfields, $colfield, $where = false,
$aggfield = false, $sumlabel = "Sum {}", $aggfn = "SUM", $includeaggfield = true, $showcount = true)
{
function PivotTableSQL(&$db, $tables, $rowfields, $colfield, $where = false,
$aggfield = false, $sumlabel = "Sum {}", $aggfn = "SUM", $includeaggfield = true, $showcount = true) {
if ($aggfield) {
$hidecnt = true;
} else {
Expand All @@ -42,7 +40,7 @@ function PivotTableSQL(&$db, $tables, $rowfields, $colfield, $where = false,

if ($where) $where = "\nWHERE $where";
if (!is_array($colfield)) $colarr = $db->GetCol("select distinct $colfield from $tables $where order by 1");
if (!$aggfield) $hidecnt = false;
$hidecnt = $aggfield ? true : false;

$sel = "$rowfields, ";
if (is_array($colfield)) {
Expand Down Expand Up @@ -86,7 +84,7 @@ function PivotTableSQL(&$db, $tables, $rowfields, $colfield, $where = false,
if ($includeaggfield && ($aggfield && $aggfield != '1')) {
$agg = "$aggfn($aggfield)";
if (strstr($sumlabel, '{}')) {
$sumlabel = trim(strstr($sumlabel, '{}', true)).' '.trim($aggfield).'", ';
$sumlabel = trim($sumlabel, ' \t\n\r\0\x0B{}').' '.trim($aggfield);
}
$sel .= "\n\t$agg AS \"$sumlabel\", ";
}
Expand All @@ -103,4 +101,4 @@ function PivotTableSQL(&$db, $tables, $rowfields, $colfield, $where = false,
$sql = "SELECT $sel \nFROM $tables $where \nGROUP BY $rowfields";

return $sql;
}
}

0 comments on commit 7c12347

Please sign in to comment.