Procházet zdrojové kódy

N.539 Regression introduced in [r4451] on oct 7th. Some OQL were issuing a notice and some were generating a SQL query that would fail with error "Column 'functionalci_id' in where clause is ambiguous" (See CI details)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4492 a333f486-631f-4898-b8df-5754b55c2be0
romainq před 8 roky
rodič
revize
7711c1aeb7
2 změnil soubory, kde provedl 59 přidání a 1 odebrání
  1. 10 1
      core/dbobjectsearch.class.php
  2. 49 0
      test/testlist.inc.php

+ 10 - 1
core/dbobjectsearch.class.php

@@ -1237,7 +1237,16 @@ class DBObjectSearch extends DBSearch
 		$oConditionTree = $oOqlQuery->GetCondition();
 		if ($oConditionTree instanceof Expression)
 		{
-			$this->m_oSearchCondition = $this->OQLExpressionToCondition($sQuery, $oConditionTree, $aAliases);
+			$aRawAliases = array($sClassAlias => $sClass);
+			$aJoinSpecs = $oOqlQuery->GetJoins();
+			if (is_array($aJoinSpecs))
+			{
+				foreach ($aJoinSpecs as $oJoinSpec)
+				{
+					$aRawAliases[$oJoinSpec->GetClassAlias()] = $oJoinSpec->GetClass();
+				}
+			}
+			$this->m_oSearchCondition = $this->OQLExpressionToCondition($sQuery, $oConditionTree, $aRawAliases);
 		}
 
 		// Maintain an array of filters, because the flat list is in fact referring to a tree

+ 49 - 0
test/testlist.inc.php

@@ -5401,6 +5401,55 @@ class TestUnions extends TestBizModel
 			catch (OQLException $e)
 			{
 				if ($bSuccess) throw $e;
+				echo "<p>Failed as expected.</p>\n";
+			}
+		}
+	}
+}
+
+class TestImplicitAlias extends TestBizModel
+{
+	static public function GetName()
+	{
+		return 'OQLImplicitAliases';
+	}
+
+	static public function GetDescription()
+	{
+		return 'Checking implicit aliases resolution';
+	}
+
+	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 WHERE org_id = 1" => true,
+			"SELECT Person WHERE s.org_id = 1" => false,
+			"SELECT Person AS p WHERE p.org_id = 1" => true,
+			"SELECT Person AS p WHERE Person.org_id = 1" => false,
+			"SELECT P FROM Organization AS O JOIN Person AS P ON P.org_id = O.id WHERE org_id = 2" => true, // Bug N.539
+			"SELECT Server JOIN Location ON Server.location_id = Location.id" => true,
+			"SELECT Server JOIN Location ON Server.location_id = id" => false,
+			"SELECT Server JOIN Location ON Server = Location.id" => false,
+			"SELECT Server JOIN Location ON Server.location_id = Location.id WHERE Server.org_id = 1" => true,
+			"SELECT Server JOIN Location ON Server.location_id = Location.id WHERE org_id = 1" => 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;
+				echo "<p>Failed as expected.</p>\n";
 			}
 		}
 	}