iquerybuilder.php 22 KB

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