diff --git a/core/dbobjectsearch.class.php b/core/dbobjectsearch.class.php index b5f34bb5c..5a060d793 100644 --- a/core/dbobjectsearch.class.php +++ b/core/dbobjectsearch.class.php @@ -1426,6 +1426,7 @@ class DBObjectSearch extends DBSearch } } $sRawId .= $bGetCount; + $sRawId .= implode(',', $aSelectedClasses); // Unions may alter the list of selected columns $sOqlId = md5($sRawId); } else @@ -1476,7 +1477,7 @@ class DBObjectSearch extends DBSearch if (!isset($oSQLQuery)) { $oKPI = new ExecutionKPI(); - $oSQLQuery = $oSearch->BuildSQLQueryStruct($aAttToLoad, $bGetCount, $aModifierProperties, $aGroupByExpr); + $oSQLQuery = $oSearch->BuildSQLQueryStruct($aAttToLoad, $bGetCount, $aModifierProperties, $aGroupByExpr, $aSelectedClasses); $oKPI->ComputeStats('BuildSQLQueryStruct', $sOqlQuery); if (self::$m_bQueryCacheEnabled) diff --git a/test/testlist.inc.php b/test/testlist.inc.php index 0490d0de1..e1568da48 100644 --- a/test/testlist.inc.php +++ b/test/testlist.inc.php @@ -5363,3 +5363,45 @@ class TestParsingOptimization extends TestBizModel } } } + +class TestUnions extends TestBizModel +{ + static public function GetName() + { + return 'Unions'; + } + + static public function GetDescription() + { + return 'Checking a few UNION queries'; + } + + protected function DoExecute() + { + // The two first items did reveal an issue with the query cache, + //because SELECT Person on the second line must not give the same query as SELECT Person on the first line + $aQueries = array( + "SELECT Person UNION SELECT Person" => true, + "SELECT Person UNION SELECT Team" => true, + "SELECT Person UNION SELECT Contact" => true, + "SELECT Contact UNION SELECT Person" => true, + "SELECT Person UNION SELECT Organization" => false, + ); + foreach ($aQueries as $sQuery => $bSuccess) + { + echo "
Successfully tested the SQL query.
\n"; + } + catch (OQLException $e) + { + if ($bSuccess) throw $e; + } + } + } +}