Преглед на файлове

N.536 Regression introduced in [r4469] (N.505), itself fixing a regression introduced in [r4404]. REQUIRES TESTING

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4488 a333f486-631f-4898-b8df-5754b55c2be0
romainq преди 8 години
родител
ревизия
f58c412702
променени са 2 файла, в които са добавени 44 реда и са изтрити 1 реда
  1. 2 1
      core/dbobjectsearch.class.php
  2. 42 0
      test/testlist.inc.php

+ 2 - 1
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)

+ 42 - 0
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 "<h5>To Parse: ".htmlentities($sQuery, ENT_QUOTES, 'UTF-8')."</h5>\n";
+			try
+			{
+				$oSearch = DBSearch::FromOQL($sQuery);
+				if (!$bSuccess) throw new Exception('This query should not be parsable!');
+
+				CMDBSource::TestQuery($oSearch->MakeSelectQuery());
+				echo "<p>Successfully tested the SQL query.</p>\n";
+			}
+			catch (OQLException $e)
+			{
+				if ($bSuccess) throw $e;
+			}
+		}
+	}
+}