IQueryBuilder.php 24 KB

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