Просмотр исходного кода

OQL arguments: when the value of a query argument is null, it must be considered as being a valid argument (was reported as missing). Improved the error reporting when the argument is in the form :this->attcode and the attcode is not valid for the class of 'this'.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3999 a333f486-631f-4898-b8df-5754b55c2be0
romainq 9 лет назад
Родитель
Сommit
353e6a0ffc
1 измененных файлов с 10 добавлено и 6 удалено
  1. 10 6
      core/oql/expression.class.inc.php

+ 10 - 6
core/oql/expression.class.inc.php

@@ -686,10 +686,10 @@ class VariableExpression extends UnaryExpression
 	
 	public function GetAsScalar($aArgs)
 	{
-		$value = null;
+		$oRet = null;
 		if (array_key_exists($this->m_sName, $aArgs))
 		{
-			$value = $aArgs[$this->m_sName];
+			$oRet = new ScalarExpression($aArgs[$this->m_sName]);
 		}
 		elseif (($iPos = strpos($this->m_sName, '->')) !== false)
 		{
@@ -700,19 +700,23 @@ class VariableExpression extends UnaryExpression
 				$oObj = $aArgs[$sParamName.'->object()'];
 				if ($sAttCode == 'id')
 				{
-					$value = $oObj->GetKey();
+					$oRet = new ScalarExpression($oObj->GetKey());
+				}
+				elseif (MetaModel::IsValidAttCode(get_class($oObj), $sAttCode))
+				{
+					$oRet = new ScalarExpression($oObj->Get($sAttCode));
 				}
 				else
 				{
-					$value = $oObj->Get($sAttCode);
+					throw new CoreException("Query argument {$this->m_sName} not matching any attribute of class ".get_class($oObj));
 				}
 			}
 		}
-		if (is_null($value))
+		if (is_null($oRet))
 		{
 			throw new MissingQueryArgument('Missing query argument', array('expecting'=>$this->m_sName, 'available'=>array_keys($aArgs)));
 		}
-		return new ScalarExpression($value);
+		return $oRet;
 	}
 }