Skip to content

Commit

Permalink
DbCube: fix PostgreSQL support
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-Gelf committed Dec 6, 2016
1 parent 134422c commit 3107867
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions library/Cube/DbCube.php
Expand Up @@ -199,7 +199,7 @@ protected function rollupQuery()
* The full query wraps the rollup query in a sub-query to work around
* MySQL limitations. This is required to not get into trouble when ordering,
* especially combined with the need to keep control over (eventually desired)
* NULL value fact colums
* NULL value fact columns
*
* @return \Zend_Db_Select
*/
Expand Down Expand Up @@ -237,6 +237,17 @@ public function db()
return $this->db;
}

/**
* Whether our connection is PostgreSQL
*
* @return bool
*/
public function isPgsql()
{
return $this->connection->getDbType() === 'pgsql';
}


/**
* This prepares the rollup query
*
Expand All @@ -252,6 +263,7 @@ protected function prepareRollupQuery()

$dimensions = $this->listDimensions();
$this->finalizeInnerQuery();
$columns = array();
foreach ($dimensions as $dimension) {
$columns[$dimension] = $alias . '.' . $dimension;
}
Expand All @@ -263,7 +275,13 @@ protected function prepareRollupQuery()
$select = $this->db()->select()->from(
array($alias => $this->innerQuery()),
$columns
)->group('(' . implode('), (', $dimensions) . ') WITH ROLLUP');
);

if ($this->isPgsql()) {
$select->group('ROLLUP (' . implode('), (', $dimensions) . ')');
} else {
$select->group('(' . implode('), (', $dimensions) . ') WITH ROLLUP');
}

return $select;
}
Expand Down

0 comments on commit 3107867

Please sign in to comment.