IExpressionBuilder.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Robin Appelman <robin@icewind.nl>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCP\DB\QueryBuilder;
  25. use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
  26. /**
  27. * This class provides a wrapper around Doctrine's ExpressionBuilder
  28. * @since 8.2.0
  29. */
  30. interface IExpressionBuilder {
  31. /**
  32. * @since 9.0.0
  33. */
  34. const EQ = ExpressionBuilder::EQ;
  35. /**
  36. * @since 9.0.0
  37. */
  38. const NEQ = ExpressionBuilder::NEQ;
  39. /**
  40. * @since 9.0.0
  41. */
  42. const LT = ExpressionBuilder::LT;
  43. /**
  44. * @since 9.0.0
  45. */
  46. const LTE = ExpressionBuilder::LTE;
  47. /**
  48. * @since 9.0.0
  49. */
  50. const GT = ExpressionBuilder::GT;
  51. /**
  52. * @since 9.0.0
  53. */
  54. const GTE = ExpressionBuilder::GTE;
  55. /**
  56. * Creates a conjunction of the given boolean expressions.
  57. *
  58. * Example:
  59. *
  60. * [php]
  61. * // (u.type = ?) AND (u.role = ?)
  62. * $expr->andX('u.type = ?', 'u.role = ?'));
  63. *
  64. * @param mixed $x Optional clause. Defaults = null, but requires
  65. * at least one defined when converting to string.
  66. *
  67. * @return \OCP\DB\QueryBuilder\ICompositeExpression
  68. * @since 8.2.0
  69. */
  70. public function andX($x = null);
  71. /**
  72. * Creates a disjunction of the given boolean expressions.
  73. *
  74. * Example:
  75. *
  76. * [php]
  77. * // (u.type = ?) OR (u.role = ?)
  78. * $qb->where($qb->expr()->orX('u.type = ?', 'u.role = ?'));
  79. *
  80. * @param mixed $x Optional clause. Defaults = null, but requires
  81. * at least one defined when converting to string.
  82. *
  83. * @return \OCP\DB\QueryBuilder\ICompositeExpression
  84. * @since 8.2.0
  85. */
  86. public function orX($x = null);
  87. /**
  88. * Creates a comparison expression.
  89. *
  90. * @param mixed $x The left expression.
  91. * @param string $operator One of the IExpressionBuilder::* constants.
  92. * @param mixed $y The right expression.
  93. * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
  94. * required when comparing text fields for oci compatibility
  95. *
  96. * @return string
  97. * @since 8.2.0 - Parameter $type was added in 9.0.0
  98. */
  99. public function comparison($x, $operator, $y, $type = null);
  100. /**
  101. * Creates an equality comparison expression with the given arguments.
  102. *
  103. * First argument is considered the left expression and the second is the right expression.
  104. * When converted to string, it will generated a <left expr> = <right expr>. Example:
  105. *
  106. * [php]
  107. * // u.id = ?
  108. * $expr->eq('u.id', '?');
  109. *
  110. * @param mixed $x The left expression.
  111. * @param mixed $y The right expression.
  112. * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
  113. * required when comparing text fields for oci compatibility
  114. *
  115. * @return string
  116. * @since 8.2.0 - Parameter $type was added in 9.0.0
  117. */
  118. public function eq($x, $y, $type = null);
  119. /**
  120. * Creates a non equality comparison expression with the given arguments.
  121. * First argument is considered the left expression and the second is the right expression.
  122. * When converted to string, it will generated a <left expr> <> <right expr>. Example:
  123. *
  124. * [php]
  125. * // u.id <> 1
  126. * $q->where($q->expr()->neq('u.id', '1'));
  127. *
  128. * @param mixed $x The left expression.
  129. * @param mixed $y The right expression.
  130. * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
  131. * required when comparing text fields for oci compatibility
  132. *
  133. * @return string
  134. * @since 8.2.0 - Parameter $type was added in 9.0.0
  135. */
  136. public function neq($x, $y, $type = null);
  137. /**
  138. * Creates a lower-than comparison expression with the given arguments.
  139. * First argument is considered the left expression and the second is the right expression.
  140. * When converted to string, it will generated a <left expr> < <right expr>. Example:
  141. *
  142. * [php]
  143. * // u.id < ?
  144. * $q->where($q->expr()->lt('u.id', '?'));
  145. *
  146. * @param mixed $x The left expression.
  147. * @param mixed $y The right expression.
  148. * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
  149. * required when comparing text fields for oci compatibility
  150. *
  151. * @return string
  152. * @since 8.2.0 - Parameter $type was added in 9.0.0
  153. */
  154. public function lt($x, $y, $type = null);
  155. /**
  156. * Creates a lower-than-equal comparison expression with the given arguments.
  157. * First argument is considered the left expression and the second is the right expression.
  158. * When converted to string, it will generated a <left expr> <= <right expr>. Example:
  159. *
  160. * [php]
  161. * // u.id <= ?
  162. * $q->where($q->expr()->lte('u.id', '?'));
  163. *
  164. * @param mixed $x The left expression.
  165. * @param mixed $y The right expression.
  166. * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
  167. * required when comparing text fields for oci compatibility
  168. *
  169. * @return string
  170. * @since 8.2.0 - Parameter $type was added in 9.0.0
  171. */
  172. public function lte($x, $y, $type = null);
  173. /**
  174. * Creates a greater-than comparison expression with the given arguments.
  175. * First argument is considered the left expression and the second is the right expression.
  176. * When converted to string, it will generated a <left expr> > <right expr>. Example:
  177. *
  178. * [php]
  179. * // u.id > ?
  180. * $q->where($q->expr()->gt('u.id', '?'));
  181. *
  182. * @param mixed $x The left expression.
  183. * @param mixed $y The right expression.
  184. * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
  185. * required when comparing text fields for oci compatibility
  186. *
  187. * @return string
  188. * @since 8.2.0 - Parameter $type was added in 9.0.0
  189. */
  190. public function gt($x, $y, $type = null);
  191. /**
  192. * Creates a greater-than-equal comparison expression with the given arguments.
  193. * First argument is considered the left expression and the second is the right expression.
  194. * When converted to string, it will generated a <left expr> >= <right expr>. Example:
  195. *
  196. * [php]
  197. * // u.id >= ?
  198. * $q->where($q->expr()->gte('u.id', '?'));
  199. *
  200. * @param mixed $x The left expression.
  201. * @param mixed $y The right expression.
  202. * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
  203. * required when comparing text fields for oci compatibility
  204. *
  205. * @return string
  206. * @since 8.2.0 - Parameter $type was added in 9.0.0
  207. */
  208. public function gte($x, $y, $type = null);
  209. /**
  210. * Creates an IS NULL expression with the given arguments.
  211. *
  212. * @param string $x The field in string format to be restricted by IS NULL.
  213. *
  214. * @return string
  215. * @since 8.2.0
  216. */
  217. public function isNull($x);
  218. /**
  219. * Creates an IS NOT NULL expression with the given arguments.
  220. *
  221. * @param string $x The field in string format to be restricted by IS NOT NULL.
  222. *
  223. * @return string
  224. * @since 8.2.0
  225. */
  226. public function isNotNull($x);
  227. /**
  228. * Creates a LIKE() comparison expression with the given arguments.
  229. *
  230. * @param string $x Field in string format to be inspected by LIKE() comparison.
  231. * @param mixed $y Argument to be used in LIKE() comparison.
  232. * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
  233. * required when comparing text fields for oci compatibility
  234. *
  235. * @return string
  236. * @since 8.2.0 - Parameter $type was added in 9.0.0
  237. */
  238. public function like($x, $y, $type = null);
  239. /**
  240. * Creates a NOT LIKE() comparison expression with the given arguments.
  241. *
  242. * @param string $x Field in string format to be inspected by NOT LIKE() comparison.
  243. * @param mixed $y Argument to be used in NOT LIKE() comparison.
  244. * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
  245. * required when comparing text fields for oci compatibility
  246. *
  247. * @return string
  248. * @since 8.2.0 - Parameter $type was added in 9.0.0
  249. */
  250. public function notLike($x, $y, $type = null);
  251. /**
  252. * Creates a ILIKE() comparison expression with the given arguments.
  253. *
  254. * @param string $x Field in string format to be inspected by ILIKE() comparison.
  255. * @param mixed $y Argument to be used in ILIKE() comparison.
  256. * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
  257. * required when comparing text fields for oci compatibility
  258. *
  259. * @return string
  260. * @since 9.0.0
  261. */
  262. public function iLike($x, $y, $type = null);
  263. /**
  264. * Creates a IN () comparison expression with the given arguments.
  265. *
  266. * @param string $x The field in string format to be inspected by IN() comparison.
  267. * @param string|array $y The placeholder or the array of values to be used by IN() comparison.
  268. * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
  269. * required when comparing text fields for oci compatibility
  270. *
  271. * @return string
  272. * @since 8.2.0 - Parameter $type was added in 9.0.0
  273. */
  274. public function in($x, $y, $type = null);
  275. /**
  276. * Creates a NOT IN () comparison expression with the given arguments.
  277. *
  278. * @param string $x The field in string format to be inspected by NOT IN() comparison.
  279. * @param string|array $y The placeholder or the array of values to be used by NOT IN() comparison.
  280. * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
  281. * required when comparing text fields for oci compatibility
  282. *
  283. * @return string
  284. * @since 8.2.0 - Parameter $type was added in 9.0.0
  285. */
  286. public function notIn($x, $y, $type = null);
  287. /**
  288. * Creates a bitwise AND comparison
  289. *
  290. * @param string|ILiteral $x The field or value to check
  291. * @param int $y Bitmap that must be set
  292. * @return IQueryFunction
  293. * @since 12.0.0
  294. */
  295. public function bitwiseAnd($x, $y);
  296. /**
  297. * Creates a bitwise OR comparison
  298. *
  299. * @param string|ILiteral $x The field or value to check
  300. * @param int $y Bitmap that must be set
  301. * @return IQueryFunction
  302. * @since 12.0.0
  303. */
  304. public function bitwiseOr($x, $y);
  305. /**
  306. * Quotes a given input parameter.
  307. *
  308. * @param mixed $input The parameter to be quoted.
  309. * @param mixed|null $type One of the IQueryBuilder::PARAM_* constants
  310. *
  311. * @return string
  312. * @since 8.2.0
  313. */
  314. public function literal($input, $type = null);
  315. /**
  316. * Returns a IQueryFunction that casts the column to the given type
  317. *
  318. * @param string $column
  319. * @param mixed $type One of IQueryBuilder::PARAM_*
  320. * @return string
  321. * @since 9.0.0
  322. */
  323. public function castColumn($column, $type);
  324. }