oqlquery.class.inc.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Classes defined for lexical analyze (see oql-parser.y)
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  23. */
  24. // Position a string within an OQL query
  25. // This is a must if we want to be able to pinpoint an error at any stage of the query interpretation
  26. // In particular, the normalization phase requires this
  27. class OqlName
  28. {
  29. protected $m_sValue;
  30. protected $m_iPos;
  31. public function __construct($sValue, $iPos)
  32. {
  33. $this->m_iPos = $iPos;
  34. $this->m_sValue = $sValue;
  35. }
  36. public function GetValue()
  37. {
  38. return $this->m_sValue;
  39. }
  40. public function GetPos()
  41. {
  42. return $this->m_iPos;
  43. }
  44. public function __toString()
  45. {
  46. return $this->m_sValue;
  47. }
  48. }
  49. class OqlJoinSpec
  50. {
  51. protected $m_oClass;
  52. protected $m_oClassAlias;
  53. protected $m_oLeftField;
  54. protected $m_oRightField;
  55. protected $m_oNextJoinspec;
  56. public function __construct($oClass, $oClassAlias, BinaryExpression $oExpression)
  57. {
  58. $this->m_oClass = $oClass;
  59. $this->m_oClassAlias = $oClassAlias;
  60. $this->m_oLeftField = $oExpression->GetLeftExpr();
  61. $this->m_oRightField = $oExpression->GetRightExpr();
  62. }
  63. public function GetClass()
  64. {
  65. return $this->m_oClass->GetValue();
  66. }
  67. public function GetClassAlias()
  68. {
  69. return $this->m_oClassAlias->GetValue();
  70. }
  71. public function GetClassDetails()
  72. {
  73. return $this->m_oClass;
  74. }
  75. public function GetClassAliasDetails()
  76. {
  77. return $this->m_oClassAlias;
  78. }
  79. public function GetLeftField()
  80. {
  81. return $this->m_oLeftField;
  82. }
  83. public function GetRightField()
  84. {
  85. return $this->m_oRightField;
  86. }
  87. }
  88. class BinaryOqlExpression extends BinaryExpression
  89. {
  90. }
  91. class ScalarOqlExpression extends ScalarExpression
  92. {
  93. }
  94. class FieldOqlExpression extends FieldExpression
  95. {
  96. protected $m_oParent;
  97. protected $m_oName;
  98. public function __construct($oName, $oParent = null)
  99. {
  100. if (is_null($oParent))
  101. {
  102. $oParent = new OqlName('', 0);
  103. }
  104. $this->m_oParent = $oParent;
  105. $this->m_oName = $oName;
  106. parent::__construct($oName->GetValue(), $oParent->GetValue());
  107. }
  108. public function GetParentDetails()
  109. {
  110. return $this->m_oParent;
  111. }
  112. public function GetNameDetails()
  113. {
  114. return $this->m_oName;
  115. }
  116. }
  117. class VariableOqlExpression extends VariableExpression
  118. {
  119. }
  120. class ListOqlExpression extends ListExpression
  121. {
  122. }
  123. class FunctionOqlExpression extends FunctionExpression
  124. {
  125. }
  126. class IntervalOqlExpression extends IntervalExpression
  127. {
  128. }
  129. abstract class OqlQuery
  130. {
  131. protected $m_aJoins; // array of OqlJoinSpec
  132. protected $m_oCondition; // condition tree (expressions)
  133. public function __construct($oCondition = null, $aJoins = null)
  134. {
  135. $this->m_aJoins = $aJoins;
  136. $this->m_oCondition = $oCondition;
  137. }
  138. public function GetJoins()
  139. {
  140. return $this->m_aJoins;
  141. }
  142. public function GetCondition()
  143. {
  144. return $this->m_oCondition;
  145. }
  146. }
  147. class OqlObjectQuery extends OqlQuery
  148. {
  149. protected $m_aSelect; // array of selected classes
  150. protected $m_oClass;
  151. protected $m_oClassAlias;
  152. public function __construct($oClass, $oClassAlias, $oCondition = null, $aJoins = null, $aSelect = null)
  153. {
  154. $this->m_aSelect = $aSelect;
  155. $this->m_oClass = $oClass;
  156. $this->m_oClassAlias = $oClassAlias;
  157. parent::__construct($oCondition, $aJoins);
  158. }
  159. public function GetSelectedClasses()
  160. {
  161. return $this->m_aSelect;
  162. }
  163. public function GetClass()
  164. {
  165. return $this->m_oClass->GetValue();
  166. }
  167. public function GetClassAlias()
  168. {
  169. return $this->m_oClassAlias->GetValue();
  170. }
  171. public function GetClassDetails()
  172. {
  173. return $this->m_oClass;
  174. }
  175. public function GetClassAliasDetails()
  176. {
  177. return $this->m_oClassAlias;
  178. }
  179. }
  180. ?>