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.

368 lines
12 KiB

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