Commit d56cafa0 authored by jeroendedauw's avatar jeroendedauw

Make code Ocramius certified

parent 077abc6a
...@@ -1087,9 +1087,7 @@ class QueryBuilder ...@@ -1087,9 +1087,7 @@ class QueryBuilder
{ {
$query = 'SELECT ' . implode(', ', $this->sqlParts['select']) . ' FROM '; $query = 'SELECT ' . implode(', ', $this->sqlParts['select']) . ' FROM ';
$fromClauses = $this->getFromClauses(); $query .= implode(', ', $this->getFromClauses())
$query .= implode(', ', $fromClauses)
. ($this->sqlParts['where'] !== null ? ' WHERE ' . ((string) $this->sqlParts['where']) : '') . ($this->sqlParts['where'] !== null ? ' WHERE ' . ((string) $this->sqlParts['where']) : '')
. ($this->sqlParts['groupBy'] ? ' GROUP BY ' . implode(', ', $this->sqlParts['groupBy']) : '') . ($this->sqlParts['groupBy'] ? ' GROUP BY ' . implode(', ', $this->sqlParts['groupBy']) : '')
. ($this->sqlParts['having'] !== null ? ' HAVING ' . ((string) $this->sqlParts['having']) : '') . ($this->sqlParts['having'] !== null ? ' HAVING ' . ((string) $this->sqlParts['having']) : '')
...@@ -1106,6 +1104,9 @@ class QueryBuilder ...@@ -1106,6 +1104,9 @@ class QueryBuilder
return $query; return $query;
} }
/**
* @return string[]
*/
private function getFromClauses() private function getFromClauses()
{ {
$fromClauses = array(); $fromClauses = array();
...@@ -1113,19 +1114,17 @@ class QueryBuilder ...@@ -1113,19 +1114,17 @@ class QueryBuilder
// Loop through all FROM clauses // Loop through all FROM clauses
foreach ($this->sqlParts['from'] as $from) { foreach ($this->sqlParts['from'] as $from) {
if ( $from['alias'] === null ) { if ($from['alias'] === null) {
$tableSql = $from['table']; $tableSql = $from['table'];
$tableReference = $from['table']; $tableReference = $from['table'];
} } else {
else {
$tableSql = $from['table'] . ' ' . $from['alias']; $tableSql = $from['table'] . ' ' . $from['alias'];
$tableReference = $from['alias']; $tableReference = $from['alias'];
} }
$knownAliases[$tableReference] = true; $knownAliases[$tableReference] = true;
$fromClauses[$tableReference] = $tableSql $fromClauses[$tableReference] = $tableSql . $this->getSQLForJoins($tableReference, $knownAliases);
. $this->getSQLForJoins($tableReference, $knownAliases);
} }
$this->verifyAllAliasesAreKnown($knownAliases); $this->verifyAllAliasesAreKnown($knownAliases);
...@@ -1133,6 +1132,11 @@ class QueryBuilder ...@@ -1133,6 +1132,11 @@ class QueryBuilder
return $fromClauses; return $fromClauses;
} }
/**
* @param array $knownAliases
*
* @throws QueryException
*/
private function verifyAllAliasesAreKnown(array $knownAliases) private function verifyAllAliasesAreKnown(array $knownAliases)
{ {
foreach ($this->sqlParts['join'] as $fromAlias => $joins) { foreach ($this->sqlParts['join'] as $fromAlias => $joins) {
...@@ -1142,6 +1146,9 @@ class QueryBuilder ...@@ -1142,6 +1146,9 @@ class QueryBuilder
} }
} }
/**
* @return bool
*/
private function isLimitQuery() private function isLimitQuery()
{ {
return $this->maxResults !== null || $this->firstResult !== null; return $this->maxResults !== null || $this->firstResult !== null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment