diff --git a/core/sqlobjectquery.class.inc.php b/core/sqlobjectquery.class.inc.php index 72290f0c0..ab7136a4b 100644 --- a/core/sqlobjectquery.class.inc.php +++ b/core/sqlobjectquery.class.inc.php @@ -47,7 +47,7 @@ class SQLObjectQuery extends SQLQuery private $m_aValues = array(); // Values to set in case of an update query private $m_oSelectedIdField = null; private $m_aJoinSelects = array(); - private $m_bBeautifulQuery = false; + protected $m_bBeautifulQuery = false; // Data set by PrepareRendering() private $__aFrom; @@ -245,6 +245,12 @@ class SQLObjectQuery extends SQLQuery } // Interface, build the SQL query + + /** + * @param array $aArgs + * @return string + * @throws CoreException + */ public function RenderDelete($aArgs = array()) { $this->PrepareRendering(); @@ -270,6 +276,7 @@ class SQLObjectQuery extends SQLQuery $sWhere = self::ClauseWhere($this->m_oConditionExpr, $aArgs); return "DELETE $sDelete FROM $sFrom WHERE $sWhere"; } + return ''; } /** @@ -283,7 +290,9 @@ class SQLObjectQuery extends SQLQuery } /** - * Needed for the unions + * Needed for the unions + * @param $aOrderBy + * @return string */ public function RenderOrderByClause($aOrderBy) { @@ -293,6 +302,12 @@ class SQLObjectQuery extends SQLQuery } // Interface, build the SQL query + + /** + * @param array $aArgs + * @return string + * @throws CoreException + */ public function RenderUpdate($aArgs = array()) { $this->PrepareRendering(); @@ -303,6 +318,17 @@ class SQLObjectQuery extends SQLQuery } // Interface, build the SQL query + + /** + * @param array $aOrderBy + * @param array $aArgs + * @param int $iLimitCount + * @param int $iLimitStart + * @param bool $bGetCount + * @param bool $bBeautifulQuery + * @return string + * @throws CoreException + */ public function RenderSelect($aOrderBy = array(), $aArgs = array(), $iLimitCount = 0, $iLimitStart = 0, $bGetCount = false, $bBeautifulQuery = false) { $this->m_bBeautifulQuery = $bBeautifulQuery; @@ -351,6 +377,13 @@ class SQLObjectQuery extends SQLQuery } // Interface, build the SQL query + + /** + * @param array $aArgs + * @param bool $bBeautifulQuery + * @return string + * @throws CoreException + */ public function RenderGroupBy($aArgs = array(), $bBeautifulQuery = false) { $this->m_bBeautifulQuery = $bBeautifulQuery; @@ -385,6 +418,7 @@ class SQLObjectQuery extends SQLQuery private function PrepareSingleTable(SQLObjectQuery $oRootQuery, &$aFrom, $sCallerAlias = '', $aJoinData) { $aTranslationTable[$this->m_sTable]['*'] = $this->m_sTableAlias; + $sJoinCond = ''; // Handle the various kinds of join (or first table in the list) // @@ -502,7 +536,7 @@ class SQLObjectQuery extends SQLQuery { $oRightSelect = $aJoinData["select"]; - $sJoinTableAlias = $oRightSelect->PrepareSingleTable($oRootQuery, $aTempFrom, $this->m_sTableAlias, $aJoinData); + $oRightSelect->PrepareSingleTable($oRootQuery, $aTempFrom, $this->m_sTableAlias, $aJoinData); } $aFrom[$this->m_sTableAlias]['subfrom'] = $aTempFrom; @@ -578,7 +612,7 @@ class SQLObjectQuery extends SQLQuery } if (isset($aJoinInfo["on_expression"])) { - $sJoinCond = $aJoinInfo["on_expression"]->CollectUsedParents($aTables); + $aJoinInfo["on_expression"]->CollectUsedParents($aTables); } } } @@ -606,7 +640,7 @@ class SQLObjectQuery extends SQLQuery } if (isset($aJoinInfo["on_expression"])) { - $sJoinCond = $aJoinInfo["on_expression"]->CollectUsedParents($aTables); + $aJoinInfo["on_expression"]->CollectUsedParents($aTables); } $bResult = true; } diff --git a/core/sqlquery.class.inc.php b/core/sqlquery.class.inc.php index 57b15e5bd..4370f8c8a 100644 --- a/core/sqlquery.class.inc.php +++ b/core/sqlquery.class.inc.php @@ -39,7 +39,7 @@ require_once('cmdbsource.class.inc.php'); abstract class SQLQuery { private $m_SourceOQL = ''; - private $m_bBeautifulQuery = false; + protected $m_bBeautifulQuery = false; public function __construct() { @@ -101,6 +101,13 @@ abstract class SQLQuery return $sDelTables; } + /** + * @param $aFrom + * @param null $sIndent + * @param int $iIndentLevel + * @return string + * @throws CoreException + */ protected static function ClauseFrom($aFrom, $sIndent = null, $iIndentLevel = 0) { $sLineBreakLong = $sIndent ? "\n".str_repeat($sIndent, $iIndentLevel + 1) : ''; diff --git a/core/sqlunionquery.class.inc.php b/core/sqlunionquery.class.inc.php index 238a823e9..64192fbd4 100644 --- a/core/sqlunionquery.class.inc.php +++ b/core/sqlunionquery.class.inc.php @@ -58,7 +58,7 @@ class SQLUnionQuery extends SQLQuery { $aQueriesHtml[] = '

'.$oSQLQuery->DisplayHtml().'

'; } - echo implode('UNION', $aQueries); + echo implode('UNION', $aQueriesHtml); } public function AddInnerJoin($oSQLQuery, $sLeftField, $sRightField, $sRightTable = '') @@ -69,12 +69,21 @@ class SQLUnionQuery extends SQLQuery } } + /** + * @param array $aArgs + * @throws Exception + */ public function RenderDelete($aArgs = array()) { throw new Exception(__class__.'::'.__function__.'Not implemented !'); } // Interface, build the SQL query + + /** + * @param array $aArgs + * @throws Exception + */ public function RenderUpdate($aArgs = array()) { throw new Exception(__class__.'::'.__function__.'Not implemented !'); @@ -85,7 +94,6 @@ class SQLUnionQuery extends SQLQuery { $this->m_bBeautifulQuery = $bBeautifulQuery; $sLineSep = $this->m_bBeautifulQuery ? "\n" : ''; - $sIndent = $this->m_bBeautifulQuery ? " " : null; $aSelects = array(); foreach ($this->aQueries as $oSQLQuery) @@ -102,13 +110,6 @@ class SQLUnionQuery extends SQLQuery } else { - $aSelects = array(); - foreach ($this->aQueries as $oSQLQuery) - { - // Render SELECT without orderby/limit/count - $aSelects[] = $oSQLQuery->RenderSelect(array(), $aArgs, 0, 0, false, $bBeautifulQuery); - } - $sSelect = $this->aQueries[0]->RenderSelectClause(); $sOrderBy = $this->aQueries[0]->RenderOrderByClause($aOrderBy); if (!empty($sOrderBy)) { @@ -132,7 +133,6 @@ class SQLUnionQuery extends SQLQuery { $this->m_bBeautifulQuery = $bBeautifulQuery; $sLineSep = $this->m_bBeautifulQuery ? "\n" : ''; - $sIndent = $this->m_bBeautifulQuery ? " " : null; $aSelects = array(); foreach ($this->aQueries as $oSQLQuery)