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.

IQueryBuilder.php 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  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 J0WI <J0WI@users.noreply.github.com>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Robin Appelman <robin@icewind.nl>
  11. * @author Roeland Jago Douma <roeland@famdouma.nl>
  12. *
  13. * @license AGPL-3.0
  14. *
  15. * This code is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License, version 3,
  17. * as published by the Free Software Foundation.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License, version 3,
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>
  26. *
  27. */
  28. namespace OCP\DB\QueryBuilder;
  29. use Doctrine\DBAL\Connection;
  30. /**
  31. * This class provides a wrapper around Doctrine's QueryBuilder
  32. * @since 8.2.0
  33. */
  34. interface IQueryBuilder {
  35. /**
  36. * @since 9.0.0
  37. */
  38. public const PARAM_NULL = \PDO::PARAM_NULL;
  39. /**
  40. * @since 9.0.0
  41. */
  42. public const PARAM_BOOL = \PDO::PARAM_BOOL;
  43. /**
  44. * @since 9.0.0
  45. */
  46. public const PARAM_INT = \PDO::PARAM_INT;
  47. /**
  48. * @since 9.0.0
  49. */
  50. public const PARAM_STR = \PDO::PARAM_STR;
  51. /**
  52. * @since 9.0.0
  53. */
  54. public const PARAM_LOB = \PDO::PARAM_LOB;
  55. /**
  56. * @since 9.0.0
  57. */
  58. public const PARAM_DATE = 'datetime';
  59. /**
  60. * @since 9.0.0
  61. */
  62. public const PARAM_INT_ARRAY = Connection::PARAM_INT_ARRAY;
  63. /**
  64. * @since 9.0.0
  65. */
  66. public const PARAM_STR_ARRAY = Connection::PARAM_STR_ARRAY;
  67. /**
  68. * Enable/disable automatic prefixing of table names with the oc_ prefix
  69. *
  70. * @param bool $enabled If set to true table names will be prefixed with the
  71. * owncloud database prefix automatically.
  72. * @since 8.2.0
  73. */
  74. public function automaticTablePrefix($enabled);
  75. /**
  76. * Gets an ExpressionBuilder used for object-oriented construction of query expressions.
  77. * This producer method is intended for convenient inline usage. Example:
  78. *
  79. * <code>
  80. * $qb = $conn->getQueryBuilder()
  81. * ->select('u')
  82. * ->from('users', 'u')
  83. * ->where($qb->expr()->eq('u.id', 1));
  84. * </code>
  85. *
  86. * For more complex expression construction, consider storing the expression
  87. * builder object in a local variable.
  88. *
  89. * @return \OCP\DB\QueryBuilder\IExpressionBuilder
  90. * @since 8.2.0
  91. */
  92. public function expr();
  93. /**
  94. * Gets an FunctionBuilder used for object-oriented construction of query functions.
  95. * This producer method is intended for convenient inline usage. Example:
  96. *
  97. * <code>
  98. * $qb = $conn->getQueryBuilder()
  99. * ->select('u')
  100. * ->from('users', 'u')
  101. * ->where($qb->fun()->md5('u.id'));
  102. * </code>
  103. *
  104. * For more complex function construction, consider storing the function
  105. * builder object in a local variable.
  106. *
  107. * @return \OCP\DB\QueryBuilder\IFunctionBuilder
  108. * @since 12.0.0
  109. */
  110. public function func();
  111. /**
  112. * Gets the type of the currently built query.
  113. *
  114. * @return integer
  115. * @since 8.2.0
  116. */
  117. public function getType();
  118. /**
  119. * Gets the associated DBAL Connection for this query builder.
  120. *
  121. * @return \OCP\IDBConnection
  122. * @since 8.2.0
  123. */
  124. public function getConnection();
  125. /**
  126. * Gets the state of this query builder instance.
  127. *
  128. * @return integer Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN.
  129. * @since 8.2.0
  130. */
  131. public function getState();
  132. /**
  133. * Executes this query using the bound parameters and their types.
  134. *
  135. * Uses {@see Connection::executeQuery} for select statements and {@see Connection::executeUpdate}
  136. * for insert, update and delete statements.
  137. *
  138. * @return \Doctrine\DBAL\Driver\Statement|int
  139. * @since 8.2.0
  140. */
  141. public function execute();
  142. /**
  143. * Gets the complete SQL string formed by the current specifications of this QueryBuilder.
  144. *
  145. * <code>
  146. * $qb = $conn->getQueryBuilder()
  147. * ->select('u')
  148. * ->from('User', 'u')
  149. * echo $qb->getSQL(); // SELECT u FROM User u
  150. * </code>
  151. *
  152. * @return string The SQL query string.
  153. * @since 8.2.0
  154. */
  155. public function getSQL();
  156. /**
  157. * Sets a query parameter for the query being constructed.
  158. *
  159. * <code>
  160. * $qb = $conn->getQueryBuilder()
  161. * ->select('u')
  162. * ->from('users', 'u')
  163. * ->where('u.id = :user_id')
  164. * ->setParameter(':user_id', 1);
  165. * </code>
  166. *
  167. * @param string|integer $key The parameter position or name.
  168. * @param mixed $value The parameter value.
  169. * @param string|null|int $type One of the IQueryBuilder::PARAM_* constants.
  170. *
  171. * @return $this This QueryBuilder instance.
  172. * @since 8.2.0
  173. */
  174. public function setParameter($key, $value, $type = null);
  175. /**
  176. * Sets a collection of query parameters for the query being constructed.
  177. *
  178. * <code>
  179. * $qb = $conn->getQueryBuilder()
  180. * ->select('u')
  181. * ->from('users', 'u')
  182. * ->where('u.id = :user_id1 OR u.id = :user_id2')
  183. * ->setParameters(array(
  184. * ':user_id1' => 1,
  185. * ':user_id2' => 2
  186. * ));
  187. * </code>
  188. *
  189. * @param array $params The query parameters to set.
  190. * @param array $types The query parameters types to set.
  191. *
  192. * @return $this This QueryBuilder instance.
  193. * @since 8.2.0
  194. */
  195. public function setParameters(array $params, array $types = []);
  196. /**
  197. * Gets all defined query parameters for the query being constructed indexed by parameter index or name.
  198. *
  199. * @return array The currently defined query parameters indexed by parameter index or name.
  200. * @since 8.2.0
  201. */
  202. public function getParameters();
  203. /**
  204. * Gets a (previously set) query parameter of the query being constructed.
  205. *
  206. * @param mixed $key The key (index or name) of the bound parameter.
  207. *
  208. * @return mixed The value of the bound parameter.
  209. * @since 8.2.0
  210. */
  211. public function getParameter($key);
  212. /**
  213. * Gets all defined query parameter types for the query being constructed indexed by parameter index or name.
  214. *
  215. * @return array The currently defined query parameter types indexed by parameter index or name.
  216. * @since 8.2.0
  217. */
  218. public function getParameterTypes();
  219. /**
  220. * Gets a (previously set) query parameter type of the query being constructed.
  221. *
  222. * @param mixed $key The key (index or name) of the bound parameter type.
  223. *
  224. * @return mixed The value of the bound parameter type.
  225. * @since 8.2.0
  226. */
  227. public function getParameterType($key);
  228. /**
  229. * Sets the position of the first result to retrieve (the "offset").
  230. *
  231. * @param integer $firstResult The first result to return.
  232. *
  233. * @return $this This QueryBuilder instance.
  234. * @since 8.2.0
  235. */
  236. public function setFirstResult($firstResult);
  237. /**
  238. * Gets the position of the first result the query object was set to retrieve (the "offset").
  239. * Returns NULL if {@link setFirstResult} was not applied to this QueryBuilder.
  240. *
  241. * @return integer The position of the first result.
  242. * @since 8.2.0
  243. */
  244. public function getFirstResult();
  245. /**
  246. * Sets the maximum number of results to retrieve (the "limit").
  247. *
  248. * @param integer $maxResults The maximum number of results to retrieve.
  249. *
  250. * @return $this This QueryBuilder instance.
  251. * @since 8.2.0
  252. */
  253. public function setMaxResults($maxResults);
  254. /**
  255. * Gets the maximum number of results the query object was set to retrieve (the "limit").
  256. * Returns NULL if {@link setMaxResults} was not applied to this query builder.
  257. *
  258. * @return int|null The maximum number of results.
  259. * @since 8.2.0
  260. */
  261. public function getMaxResults();
  262. /**
  263. * Specifies an item that is to be returned in the query result.
  264. * Replaces any previously specified selections, if any.
  265. *
  266. * <code>
  267. * $qb = $conn->getQueryBuilder()
  268. * ->select('u.id', 'p.id')
  269. * ->from('users', 'u')
  270. * ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id');
  271. * </code>
  272. *
  273. * @param mixed ...$selects The selection expressions.
  274. *
  275. * @return $this This QueryBuilder instance.
  276. * @since 8.2.0
  277. */
  278. public function select(...$selects);
  279. /**
  280. * Specifies an item that is to be returned with a different name in the query result.
  281. *
  282. * <code>
  283. * $qb = $conn->getQueryBuilder()
  284. * ->selectAlias('u.id', 'user_id')
  285. * ->from('users', 'u')
  286. * ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id');
  287. * </code>
  288. *
  289. * @param mixed $select The selection expressions.
  290. * @param string $alias The column alias used in the constructed query.
  291. *
  292. * @return $this This QueryBuilder instance.
  293. * @since 8.2.1
  294. */
  295. public function selectAlias($select, $alias);
  296. /**
  297. * Specifies an item that is to be returned uniquely in the query result.
  298. *
  299. * <code>
  300. * $qb = $conn->getQueryBuilder()
  301. * ->selectDistinct('type')
  302. * ->from('users');
  303. * </code>
  304. *
  305. * @param mixed $select The selection expressions.
  306. *
  307. * @return $this This QueryBuilder instance.
  308. * @since 9.0.0
  309. */
  310. public function selectDistinct($select);
  311. /**
  312. * Adds an item that is to be returned in the query result.
  313. *
  314. * <code>
  315. * $qb = $conn->getQueryBuilder()
  316. * ->select('u.id')
  317. * ->addSelect('p.id')
  318. * ->from('users', 'u')
  319. * ->leftJoin('u', 'phonenumbers', 'u.id = p.user_id');
  320. * </code>
  321. *
  322. * @param mixed ...$select The selection expression.
  323. *
  324. * @return $this This QueryBuilder instance.
  325. * @since 8.2.0
  326. */
  327. public function addSelect(...$select);
  328. /**
  329. * Turns the query being built into a bulk delete query that ranges over
  330. * a certain table.
  331. *
  332. * <code>
  333. * $qb = $conn->getQueryBuilder()
  334. * ->delete('users', 'u')
  335. * ->where('u.id = :user_id');
  336. * ->setParameter(':user_id', 1);
  337. * </code>
  338. *
  339. * @param string $delete The table whose rows are subject to the deletion.
  340. * @param string $alias The table alias used in the constructed query.
  341. *
  342. * @return $this This QueryBuilder instance.
  343. * @since 8.2.0
  344. */
  345. public function delete($delete = null, $alias = null);
  346. /**
  347. * Turns the query being built into a bulk update query that ranges over
  348. * a certain table
  349. *
  350. * <code>
  351. * $qb = $conn->getQueryBuilder()
  352. * ->update('users', 'u')
  353. * ->set('u.password', md5('password'))
  354. * ->where('u.id = ?');
  355. * </code>
  356. *
  357. * @param string $update The table whose rows are subject to the update.
  358. * @param string $alias The table alias used in the constructed query.
  359. *
  360. * @return $this This QueryBuilder instance.
  361. * @since 8.2.0
  362. */
  363. public function update($update = null, $alias = null);
  364. /**
  365. * Turns the query being built into an insert query that inserts into
  366. * a certain table
  367. *
  368. * <code>
  369. * $qb = $conn->getQueryBuilder()
  370. * ->insert('users')
  371. * ->values(
  372. * array(
  373. * 'name' => '?',
  374. * 'password' => '?'
  375. * )
  376. * );
  377. * </code>
  378. *
  379. * @param string $insert The table into which the rows should be inserted.
  380. *
  381. * @return $this This QueryBuilder instance.
  382. * @since 8.2.0
  383. */
  384. public function insert($insert = null);
  385. /**
  386. * Creates and adds a query root corresponding to the table identified by the
  387. * given alias, forming a cartesian product with any existing query roots.
  388. *
  389. * <code>
  390. * $qb = $conn->getQueryBuilder()
  391. * ->select('u.id')
  392. * ->from('users', 'u')
  393. * </code>
  394. *
  395. * @param string $from The table.
  396. * @param string|null $alias The alias of the table.
  397. *
  398. * @return $this This QueryBuilder instance.
  399. * @since 8.2.0
  400. */
  401. public function from($from, $alias = null);
  402. /**
  403. * Creates and adds a join to the query.
  404. *
  405. * <code>
  406. * $qb = $conn->getQueryBuilder()
  407. * ->select('u.name')
  408. * ->from('users', 'u')
  409. * ->join('u', 'phonenumbers', 'p', 'p.is_primary = 1');
  410. * </code>
  411. *
  412. * @param string $fromAlias The alias that points to a from clause.
  413. * @param string $join The table name to join.
  414. * @param string $alias The alias of the join table.
  415. * @param string $condition The condition for the join.
  416. *
  417. * @return $this This QueryBuilder instance.
  418. * @since 8.2.0
  419. */
  420. public function join($fromAlias, $join, $alias, $condition = null);
  421. /**
  422. * Creates and adds a join to the query.
  423. *
  424. * <code>
  425. * $qb = $conn->getQueryBuilder()
  426. * ->select('u.name')
  427. * ->from('users', 'u')
  428. * ->innerJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
  429. * </code>
  430. *
  431. * @param string $fromAlias The alias that points to a from clause.
  432. * @param string $join The table name to join.
  433. * @param string $alias The alias of the join table.
  434. * @param string $condition The condition for the join.
  435. *
  436. * @return $this This QueryBuilder instance.
  437. * @since 8.2.0
  438. */
  439. public function innerJoin($fromAlias, $join, $alias, $condition = null);
  440. /**
  441. * Creates and adds a left join to the query.
  442. *
  443. * <code>
  444. * $qb = $conn->getQueryBuilder()
  445. * ->select('u.name')
  446. * ->from('users', 'u')
  447. * ->leftJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
  448. * </code>
  449. *
  450. * @param string $fromAlias The alias that points to a from clause.
  451. * @param string $join The table name to join.
  452. * @param string $alias The alias of the join table.
  453. * @param string $condition The condition for the join.
  454. *
  455. * @return $this This QueryBuilder instance.
  456. * @since 8.2.0
  457. */
  458. public function leftJoin($fromAlias, $join, $alias, $condition = null);
  459. /**
  460. * Creates and adds a right join to the query.
  461. *
  462. * <code>
  463. * $qb = $conn->getQueryBuilder()
  464. * ->select('u.name')
  465. * ->from('users', 'u')
  466. * ->rightJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
  467. * </code>
  468. *
  469. * @param string $fromAlias The alias that points to a from clause.
  470. * @param string $join The table name to join.
  471. * @param string $alias The alias of the join table.
  472. * @param string $condition The condition for the join.
  473. *
  474. * @return $this This QueryBuilder instance.
  475. * @since 8.2.0
  476. */
  477. public function rightJoin($fromAlias, $join, $alias, $condition = null);
  478. /**
  479. * Sets a new value for a column in a bulk update query.
  480. *
  481. * <code>
  482. * $qb = $conn->getQueryBuilder()
  483. * ->update('users', 'u')
  484. * ->set('u.password', md5('password'))
  485. * ->where('u.id = ?');
  486. * </code>
  487. *
  488. * @param string $key The column to set.
  489. * @param ILiteral|IParameter|IQueryFunction|string $value The value, expression, placeholder, etc.
  490. *
  491. * @return $this This QueryBuilder instance.
  492. * @since 8.2.0
  493. */
  494. public function set($key, $value);
  495. /**
  496. * Specifies one or more restrictions to the query result.
  497. * Replaces any previously specified restrictions, if any.
  498. *
  499. * <code>
  500. * $qb = $conn->getQueryBuilder()
  501. * ->select('u.name')
  502. * ->from('users', 'u')
  503. * ->where('u.id = ?');
  504. *
  505. * // You can optionally programatically build and/or expressions
  506. * $qb = $conn->getQueryBuilder();
  507. *
  508. * $or = $qb->expr()->orx();
  509. * $or->add($qb->expr()->eq('u.id', 1));
  510. * $or->add($qb->expr()->eq('u.id', 2));
  511. *
  512. * $qb->update('users', 'u')
  513. * ->set('u.password', md5('password'))
  514. * ->where($or);
  515. * </code>
  516. *
  517. * @param mixed $predicates The restriction predicates.
  518. *
  519. * @return $this This QueryBuilder instance.
  520. * @since 8.2.0
  521. */
  522. public function where(...$predicates);
  523. /**
  524. * Adds one or more restrictions to the query results, forming a logical
  525. * conjunction with any previously specified restrictions.
  526. *
  527. * <code>
  528. * $qb = $conn->getQueryBuilder()
  529. * ->select('u')
  530. * ->from('users', 'u')
  531. * ->where('u.username LIKE ?')
  532. * ->andWhere('u.is_active = 1');
  533. * </code>
  534. *
  535. * @param mixed ...$where The query restrictions.
  536. *
  537. * @return $this This QueryBuilder instance.
  538. *
  539. * @see where()
  540. * @since 8.2.0
  541. */
  542. public function andWhere(...$where);
  543. /**
  544. * Adds one or more restrictions to the query results, forming a logical
  545. * disjunction with any previously specified restrictions.
  546. *
  547. * <code>
  548. * $qb = $conn->getQueryBuilder()
  549. * ->select('u.name')
  550. * ->from('users', 'u')
  551. * ->where('u.id = 1')
  552. * ->orWhere('u.id = 2');
  553. * </code>
  554. *
  555. * @param mixed ...$where The WHERE statement.
  556. *
  557. * @return $this This QueryBuilder instance.
  558. *
  559. * @see where()
  560. * @since 8.2.0
  561. */
  562. public function orWhere(...$where);
  563. /**
  564. * Specifies a grouping over the results of the query.
  565. * Replaces any previously specified groupings, if any.
  566. *
  567. * <code>
  568. * $qb = $conn->getQueryBuilder()
  569. * ->select('u.name')
  570. * ->from('users', 'u')
  571. * ->groupBy('u.id');
  572. * </code>
  573. *
  574. * @param mixed ...$groupBys The grouping expression.
  575. *
  576. * @return $this This QueryBuilder instance.
  577. * @since 8.2.0
  578. */
  579. public function groupBy(...$groupBys);
  580. /**
  581. * Adds a grouping expression to the query.
  582. *
  583. * <code>
  584. * $qb = $conn->getQueryBuilder()
  585. * ->select('u.name')
  586. * ->from('users', 'u')
  587. * ->groupBy('u.lastLogin');
  588. * ->addGroupBy('u.createdAt')
  589. * </code>
  590. *
  591. * @param mixed ...$groupBy The grouping expression.
  592. *
  593. * @return $this This QueryBuilder instance.
  594. * @since 8.2.0
  595. */
  596. public function addGroupBy(...$groupBy);
  597. /**
  598. * Sets a value for a column in an insert query.
  599. *
  600. * <code>
  601. * $qb = $conn->getQueryBuilder()
  602. * ->insert('users')
  603. * ->values(
  604. * array(
  605. * 'name' => '?'
  606. * )
  607. * )
  608. * ->setValue('password', '?');
  609. * </code>
  610. *
  611. * @param string $column The column into which the value should be inserted.
  612. * @param IParameter|string $value The value that should be inserted into the column.
  613. *
  614. * @return $this This QueryBuilder instance.
  615. * @since 8.2.0
  616. */
  617. public function setValue($column, $value);
  618. /**
  619. * Specifies values for an insert query indexed by column names.
  620. * Replaces any previous values, if any.
  621. *
  622. * <code>
  623. * $qb = $conn->getQueryBuilder()
  624. * ->insert('users')
  625. * ->values(
  626. * array(
  627. * 'name' => '?',
  628. * 'password' => '?'
  629. * )
  630. * );
  631. * </code>
  632. *
  633. * @param array $values The values to specify for the insert query indexed by column names.
  634. *
  635. * @return $this This QueryBuilder instance.
  636. * @since 8.2.0
  637. */
  638. public function values(array $values);
  639. /**
  640. * Specifies a restriction over the groups of the query.
  641. * Replaces any previous having restrictions, if any.
  642. *
  643. * @param mixed ...$having The restriction over the groups.
  644. *
  645. * @return $this This QueryBuilder instance.
  646. * @since 8.2.0
  647. */
  648. public function having(...$having);
  649. /**
  650. * Adds a restriction over the groups of the query, forming a logical
  651. * conjunction with any existing having restrictions.
  652. *
  653. * @param mixed ...$having The restriction to append.
  654. *
  655. * @return $this This QueryBuilder instance.
  656. * @since 8.2.0
  657. */
  658. public function andHaving(...$having);
  659. /**
  660. * Adds a restriction over the groups of the query, forming a logical
  661. * disjunction with any existing having restrictions.
  662. *
  663. * @param mixed ...$having The restriction to add.
  664. *
  665. * @return $this This QueryBuilder instance.
  666. * @since 8.2.0
  667. */
  668. public function orHaving(...$having);
  669. /**
  670. * Specifies an ordering for the query results.
  671. * Replaces any previously specified orderings, if any.
  672. *
  673. * @param string $sort The ordering expression.
  674. * @param string $order The ordering direction.
  675. *
  676. * @return $this This QueryBuilder instance.
  677. * @since 8.2.0
  678. */
  679. public function orderBy($sort, $order = null);
  680. /**
  681. * Adds an ordering to the query results.
  682. *
  683. * @param string $sort The ordering expression.
  684. * @param string $order The ordering direction.
  685. *
  686. * @return $this This QueryBuilder instance.
  687. * @since 8.2.0
  688. */
  689. public function addOrderBy($sort, $order = null);
  690. /**
  691. * Gets a query part by its name.
  692. *
  693. * @param string $queryPartName
  694. *
  695. * @return mixed
  696. * @since 8.2.0
  697. */
  698. public function getQueryPart($queryPartName);
  699. /**
  700. * Gets all query parts.
  701. *
  702. * @return array
  703. * @since 8.2.0
  704. */
  705. public function getQueryParts();
  706. /**
  707. * Resets SQL parts.
  708. *
  709. * @param array|null $queryPartNames
  710. *
  711. * @return $this This QueryBuilder instance.
  712. * @since 8.2.0
  713. */
  714. public function resetQueryParts($queryPartNames = null);
  715. /**
  716. * Resets a single SQL part.
  717. *
  718. * @param string $queryPartName
  719. *
  720. * @return $this This QueryBuilder instance.
  721. * @since 8.2.0
  722. */
  723. public function resetQueryPart($queryPartName);
  724. /**
  725. * Creates a new named parameter and bind the value $value to it.
  726. *
  727. * This method provides a shortcut for PDOStatement::bindValue
  728. * when using prepared statements.
  729. *
  730. * The parameter $value specifies the value that you want to bind. If
  731. * $placeholder is not provided bindValue() will automatically create a
  732. * placeholder for you. An automatic placeholder will be of the name
  733. * ':dcValue1', ':dcValue2' etc.
  734. *
  735. * For more information see {@link https://www.php.net/pdostatement-bindparam}
  736. *
  737. * Example:
  738. * <code>
  739. * $value = 2;
  740. * $q->eq( 'id', $q->bindValue( $value ) );
  741. * $stmt = $q->executeQuery(); // executed with 'id = 2'
  742. * </code>
  743. *
  744. * @license New BSD License
  745. * @link http://www.zetacomponents.org
  746. *
  747. * @param mixed $value
  748. * @param mixed $type
  749. * @param string $placeHolder The name to bind with. The string must start with a colon ':'.
  750. *
  751. * @return IParameter
  752. * @since 8.2.0
  753. */
  754. public function createNamedParameter($value, $type = self::PARAM_STR, $placeHolder = null);
  755. /**
  756. * Creates a new positional parameter and bind the given value to it.
  757. *
  758. * Attention: If you are using positional parameters with the query builder you have
  759. * to be very careful to bind all parameters in the order they appear in the SQL
  760. * statement , otherwise they get bound in the wrong order which can lead to serious
  761. * bugs in your code.
  762. *
  763. * Example:
  764. * <code>
  765. * $qb = $conn->getQueryBuilder();
  766. * $qb->select('u.*')
  767. * ->from('users', 'u')
  768. * ->where('u.username = ' . $qb->createPositionalParameter('Foo', IQueryBuilder::PARAM_STR))
  769. * ->orWhere('u.username = ' . $qb->createPositionalParameter('Bar', IQueryBuilder::PARAM_STR))
  770. * </code>
  771. *
  772. * @param mixed $value
  773. * @param integer $type
  774. *
  775. * @return IParameter
  776. * @since 8.2.0
  777. */
  778. public function createPositionalParameter($value, $type = self::PARAM_STR);
  779. /**
  780. * Creates a new parameter
  781. *
  782. * Example:
  783. * <code>
  784. * $qb = $conn->getQueryBuilder();
  785. * $qb->select('u.*')
  786. * ->from('users', 'u')
  787. * ->where('u.username = ' . $qb->createParameter('name'))
  788. * ->setParameter('name', 'Bar', IQueryBuilder::PARAM_STR))
  789. * </code>
  790. *
  791. * @param string $name
  792. *
  793. * @return IParameter
  794. * @since 8.2.0
  795. */
  796. public function createParameter($name);
  797. /**
  798. * Creates a new function
  799. *
  800. * Attention: Column names inside the call have to be quoted before hand
  801. *
  802. * Example:
  803. * <code>
  804. * $qb = $conn->getQueryBuilder();
  805. * $qb->select($qb->createFunction('COUNT(*)'))
  806. * ->from('users', 'u')
  807. * echo $qb->getSQL(); // SELECT COUNT(*) FROM `users` u
  808. * </code>
  809. * <code>
  810. * $qb = $conn->getQueryBuilder();
  811. * $qb->select($qb->createFunction('COUNT(`column`)'))
  812. * ->from('users', 'u')
  813. * echo $qb->getSQL(); // SELECT COUNT(`column`) FROM `users` u
  814. * </code>
  815. *
  816. * @param string $call
  817. *
  818. * @return IQueryFunction
  819. * @since 8.2.0
  820. */
  821. public function createFunction($call);
  822. /**
  823. * Used to get the id of the last inserted element
  824. * @return int
  825. * @throws \BadMethodCallException When being called before an insert query has been run.
  826. * @since 9.0.0
  827. */
  828. public function getLastInsertId();
  829. /**
  830. * Returns the table name quoted and with database prefix as needed by the implementation
  831. *
  832. * @param string $table
  833. * @return string
  834. * @since 9.0.0
  835. */
  836. public function getTableName($table);
  837. /**
  838. * Returns the column name quoted and with table alias prefix as needed by the implementation
  839. *
  840. * @param string $column
  841. * @param string $tableAlias
  842. * @return string
  843. * @since 9.0.0
  844. */
  845. public function getColumnName($column, $tableAlias = '');
  846. }