From 5a14068c2c753425b52b4a0d6fa3592e37c5c449 Mon Sep 17 00:00:00 2001 From: Mike Ho Date: Thu, 6 Jan 2011 13:55:46 -0800 Subject: [PATCH] Fixed sql syntax issue on QQCustomFrom clauses on queries with joins --- includes/qcodo/_core/framework/QQuery.class.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/includes/qcodo/_core/framework/QQuery.class.php b/includes/qcodo/_core/framework/QQuery.class.php index 2156fec1..9ddd0690 100644 --- a/includes/qcodo/_core/framework/QQuery.class.php +++ b/includes/qcodo/_core/framework/QQuery.class.php @@ -1529,10 +1529,10 @@ class QQueryBuilder extends QBaseClass { protected $intColumnAliasCount = 0; protected $strTableAliasArray; protected $intTableAliasCount = 0; - protected $intCustomFromCount = 0; protected $strFromArray; protected $strJoinArray; protected $strJoinConditionArray; + protected $strCustomFromArray; protected $strWhereArray; protected $strOrderByArray; protected $strGroupByArray; @@ -1579,7 +1579,8 @@ public function AddFromItem($strTableName, $strAliasOverride = null) { $this->strEscapeIdentifierBegin, $strTableName, $this->strEscapeIdentifierEnd, $this->strEscapeIdentifierBegin, $strTableAlias, $this->strEscapeIdentifierEnd); } else { - $this->strFromArray[$strTableName . '+' . ($this->intCustomFromCount++)] = sprintf('%s%s%s AS %s%s%s', + // If an AliasOverride was submitted, we are doing a "custom from" + $this->strCustomFromArray[$strTableName . '+' . count($this->strCustomFromArray)] = sprintf('%s%s%s AS %s%s%s', $this->strEscapeIdentifierBegin, $strTableName, $this->strEscapeIdentifierEnd, $this->strEscapeIdentifierBegin, $strAliasOverride, $this->strEscapeIdentifierEnd); } @@ -1771,6 +1772,10 @@ public function GetStatement() { implode(",\r\n ", $this->strFromArray), implode("\r\n ", $this->strJoinArray)); + // Custom "FROM" Columns + if (count($this->strCustomFromArray)) + $strSql .= ",\r\n " . implode(",\r\n ", $this->strCustomFromArray); + // WHERE Clause if (count($this->strWhereArray)) { $strWhere = implode("\r\n ", $this->strWhereArray);