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.

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