You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IExpressionBuilder.php 12KB

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