MINOR Fixed the SQLQuery to return empty query in only certain cases

This commit is contained in:
Stig Lindqvist 2011-09-27 13:28:19 +13:00 committed by Stig Lindqvist
parent b6f88036eb
commit 73c249128b

View File

@ -457,10 +457,6 @@ class SQLQuery {
function sql() { function sql() {
// TODO: Don't require this internal-state manipulate-and-preserve - let sqlQueryToString() handle the new syntax // TODO: Don't require this internal-state manipulate-and-preserve - let sqlQueryToString() handle the new syntax
$origFrom = $this->from; $origFrom = $this->from;
if(!$this->from) {
return '';
}
// Build from clauses // Build from clauses
foreach($this->from as $alias => $join) { foreach($this->from as $alias => $join) {
@ -474,12 +470,19 @@ class SQLQuery {
$this->from[$alias] = strtoupper($join['type']) . " JOIN \"{$join['table']}\" AS \"$alias\" ON $filter"; $this->from[$alias] = strtoupper($join['type']) . " JOIN \"{$join['table']}\" AS \"$alias\" ON $filter";
} }
} }
$sql = DB::getConn()->sqlQueryToString($this); $sql = DB::getConn()->sqlQueryToString($this);
if($this->replacementsOld) $sql = str_replace($this->replacementsOld, $this->replacementsNew, $sql); if($this->replacementsOld) {
$sql = str_replace($this->replacementsOld, $this->replacementsNew, $sql);
}
$this->from = $origFrom; $this->from = $origFrom;
// The query was most likely just created and then exectued.
if($sql === 'SELECT *') {
return '';
}
return $sql; return $sql;
} }