oqlquery.class.inc.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. // Copyright (C) 2010-2012 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * Classes defined for lexical analyze (see oql-parser.y)
  20. *
  21. * @copyright Copyright (C) 2010-2012 Combodo SARL
  22. * @license http://opensource.org/licenses/AGPL-3.0
  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. /**
  50. *
  51. * Store hexadecimal values as strings so that we can support 64-bit values
  52. *
  53. */
  54. class OqlHexValue
  55. {
  56. protected $m_sValue;
  57. public function __construct($sValue)
  58. {
  59. $this->m_sValue = $sValue;
  60. }
  61. public function __toString()
  62. {
  63. return $this->m_sValue;
  64. }
  65. }
  66. class OqlJoinSpec
  67. {
  68. protected $m_oClass;
  69. protected $m_oClassAlias;
  70. protected $m_oLeftField;
  71. protected $m_oRightField;
  72. protected $m_sOperator;
  73. protected $m_oNextJoinspec;
  74. public function __construct($oClass, $oClassAlias, BinaryExpression $oExpression)
  75. {
  76. $this->m_oClass = $oClass;
  77. $this->m_oClassAlias = $oClassAlias;
  78. $this->m_oLeftField = $oExpression->GetLeftExpr();
  79. $this->m_oRightField = $oExpression->GetRightExpr();
  80. $this->m_oRightField = $oExpression->GetRightExpr();
  81. $this->m_sOperator = $oExpression->GetOperator();
  82. }
  83. public function GetClass()
  84. {
  85. return $this->m_oClass->GetValue();
  86. }
  87. public function GetClassAlias()
  88. {
  89. return $this->m_oClassAlias->GetValue();
  90. }
  91. public function GetClassDetails()
  92. {
  93. return $this->m_oClass;
  94. }
  95. public function GetClassAliasDetails()
  96. {
  97. return $this->m_oClassAlias;
  98. }
  99. public function GetLeftField()
  100. {
  101. return $this->m_oLeftField;
  102. }
  103. public function GetRightField()
  104. {
  105. return $this->m_oRightField;
  106. }
  107. public function GetOperator()
  108. {
  109. return $this->m_sOperator;
  110. }
  111. }
  112. class BinaryOqlExpression extends BinaryExpression
  113. {
  114. }
  115. class ScalarOqlExpression extends ScalarExpression
  116. {
  117. }
  118. class FieldOqlExpression extends FieldExpression
  119. {
  120. protected $m_oParent;
  121. protected $m_oName;
  122. public function __construct($oName, $oParent = null)
  123. {
  124. if (is_null($oParent))
  125. {
  126. $oParent = new OqlName('', 0);
  127. }
  128. $this->m_oParent = $oParent;
  129. $this->m_oName = $oName;
  130. parent::__construct($oName->GetValue(), $oParent->GetValue());
  131. }
  132. public function GetParentDetails()
  133. {
  134. return $this->m_oParent;
  135. }
  136. public function GetNameDetails()
  137. {
  138. return $this->m_oName;
  139. }
  140. }
  141. class VariableOqlExpression extends VariableExpression
  142. {
  143. }
  144. class ListOqlExpression extends ListExpression
  145. {
  146. }
  147. class FunctionOqlExpression extends FunctionExpression
  148. {
  149. }
  150. class IntervalOqlExpression extends IntervalExpression
  151. {
  152. }
  153. abstract class OqlQuery
  154. {
  155. protected $m_aJoins; // array of OqlJoinSpec
  156. protected $m_oCondition; // condition tree (expressions)
  157. public function __construct($oCondition = null, $aJoins = null)
  158. {
  159. $this->m_aJoins = $aJoins;
  160. $this->m_oCondition = $oCondition;
  161. }
  162. public function GetJoins()
  163. {
  164. return $this->m_aJoins;
  165. }
  166. public function GetCondition()
  167. {
  168. return $this->m_oCondition;
  169. }
  170. }
  171. class OqlObjectQuery extends OqlQuery
  172. {
  173. protected $m_aSelect; // array of selected classes
  174. protected $m_oClass;
  175. protected $m_oClassAlias;
  176. public function __construct($oClass, $oClassAlias, $oCondition = null, $aJoins = null, $aSelect = null)
  177. {
  178. $this->m_aSelect = $aSelect;
  179. $this->m_oClass = $oClass;
  180. $this->m_oClassAlias = $oClassAlias;
  181. parent::__construct($oCondition, $aJoins);
  182. }
  183. public function GetSelectedClasses()
  184. {
  185. return $this->m_aSelect;
  186. }
  187. public function GetClass()
  188. {
  189. return $this->m_oClass->GetValue();
  190. }
  191. public function GetClassAlias()
  192. {
  193. return $this->m_oClassAlias->GetValue();
  194. }
  195. public function GetClassDetails()
  196. {
  197. return $this->m_oClass;
  198. }
  199. public function GetClassAliasDetails()
  200. {
  201. return $this->m_oClassAlias;
  202. }
  203. }
  204. ?>