OQL: Fixed a number of bugs, and implemented new features

- bug: a JOIN b on b.extkey = a.id
- bug: operators precedence (still a shift-reduce conflict with JOINS)
- changed pkey into id (preserved the compatibility for DBObjectSearch::AddCondition()
- allow implicit class name in WHERE condition
- bug: wrong report on typo error
- suggest an alternative in case of typo error

SVN:code[12]
This commit is contained in:
Romain Quetiez
2009-03-27 14:36:14 +00:00
parent a0f4fdb130
commit 8d9ea9dcdd
15 changed files with 989 additions and 612 deletions

View File

@@ -1,30 +1,70 @@
<?
// Position a string within an OQL query
// This is a must if we want to be able to pinpoint an error at any stage of the query interpretation
// In particular, the normalization phase requires this
class OqlName
{
protected $m_sValue;
protected $m_iPos;
public function __construct($sValue, $iPos)
{
$this->m_iPos = $iPos;
$this->m_sValue = $sValue;
}
public function GetValue()
{
return $this->m_sValue;
}
public function GetPos()
{
return $this->m_iPos;
}
public function __toString()
{
return $this->m_sValue;
}
}
class OqlJoinSpec
{
protected $m_sClass;
protected $m_sClassAlias;
protected $m_oClass;
protected $m_oClassAlias;
protected $m_oLeftField;
protected $m_oRightField;
protected $m_oNextJoinspec;
public function __construct($sClass, $sClassAlias, BinaryExpression $oExpression)
public function __construct($oClass, $oClassAlias, BinaryExpression $oExpression)
{
$this->m_sClass = $sClass;
$this->m_sClassAlias = $sClassAlias;
$this->m_oClass = $oClass;
$this->m_oClassAlias = $oClassAlias;
$this->m_oLeftField = $oExpression->GetLeftExpr();
$this->m_oRightField = $oExpression->GetRightExpr();
}
public function GetClass()
{
return $this->m_sClass;
return $this->m_oClass->GetValue();
}
public function GetClassAlias()
{
return $this->m_sClassAlias;
return $this->m_oClassAlias->GetValue();
}
public function GetClassDetails()
{
return $this->m_oClass;
}
public function GetClassAliasDetails()
{
return $this->m_oClassAlias;
}
public function GetLeftField()
{
return $this->m_oLeftField;
@@ -45,18 +85,30 @@ class ScalarOqlExpression extends ScalarExpression
class FieldOqlExpression extends FieldExpression
{
protected $m_iPosition; // position in the source string
public function __construct($iPosition, $sName, $sParent = '')
protected $m_oParent;
protected $m_oName;
public function __construct($oName, $oParent = null)
{
$this->m_iPosition = $iPosition;
parent::__construct($sName, $sParent);
if (is_null($oParent))
{
$oParent = new OqlName('', 0);
}
$this->m_oParent = $oParent;
$this->m_oName = $oName;
parent::__construct($oName->GetValue(), $oParent->GetValue());
}
public function GetPosition()
public function GetParentDetails()
{
return $this->m_iPosition;
}
return $this->m_oParent;
}
public function GetNameDetails()
{
return $this->m_oName;
}
}
class ListOqlExpression extends ListExpression
@@ -72,27 +124,37 @@ class IntervalOqlExpression extends IntervalExpression
}
class OqlQuery
{
protected $m_sClass;
protected $m_sClassAlias;
protected $m_oClass;
protected $m_oClassAlias;
protected $m_aJoins; // array of OqlJoinSpec
protected $m_oCondition; // condition tree (expressions)
public function __construct($sClass, $sClassAlias = '', $oCondition = null, $aJoins = null)
public function __construct($oClass, $oClassAlias = '', $oCondition = null, $aJoins = null)
{
$this->m_sClass = $sClass;
$this->m_sClassAlias = $sClassAlias;
$this->m_oClass = $oClass;
$this->m_oClassAlias = $oClassAlias;
$this->m_aJoins = $aJoins;
$this->m_oCondition = $oCondition;
}
public function GetClass()
{
return $this->m_sClass;
return $this->m_oClass->GetValue();
}
public function GetClassAlias()
{
return $this->m_sClassAlias;
return $this->m_oClassAlias->GetValue();
}
public function GetClassDetails()
{
return $this->m_oClass;
}
public function GetClassAliasDetails()
{
return $this->m_oClassAlias;
}
public function GetJoins()
{
return $this->m_aJoins;