idbconnection.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Robin Appelman <robin@icewind.nl>
  9. * @author Robin McCorkell <robin@mccorkell.me.uk>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  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. /**
  28. * Public interface of ownCloud for apps to use.
  29. * DBConnection interface
  30. *
  31. */
  32. // use OCP namespace for all classes that are considered public.
  33. // This means that they should be used by apps instead of the internal ownCloud classes
  34. namespace OCP;
  35. use OCP\DB\QueryBuilder\IQueryBuilder;
  36. /**
  37. * Interface IDBConnection
  38. *
  39. * @package OCP
  40. * @since 6.0.0
  41. */
  42. interface IDBConnection {
  43. /**
  44. * Gets the QueryBuilder for the connection.
  45. *
  46. * @return \OCP\DB\QueryBuilder\IQueryBuilder
  47. * @since 8.2.0
  48. */
  49. public function getQueryBuilder();
  50. /**
  51. * Used to abstract the ownCloud database access away
  52. * @param string $sql the sql query with ? placeholder for params
  53. * @param int $limit the maximum number of rows
  54. * @param int $offset from which row we want to start
  55. * @return \Doctrine\DBAL\Driver\Statement The prepared statement.
  56. * @since 6.0.0
  57. */
  58. public function prepare($sql, $limit=null, $offset=null);
  59. /**
  60. * Executes an, optionally parameterized, SQL query.
  61. *
  62. * If the query is parameterized, a prepared statement is used.
  63. * If an SQLLogger is configured, the execution is logged.
  64. *
  65. * @param string $query The SQL query to execute.
  66. * @param string[] $params The parameters to bind to the query, if any.
  67. * @param array $types The types the previous parameters are in.
  68. * @return \Doctrine\DBAL\Driver\Statement The executed statement.
  69. * @since 8.0.0
  70. */
  71. public function executeQuery($query, array $params = array(), $types = array());
  72. /**
  73. * Executes an SQL INSERT/UPDATE/DELETE query with the given parameters
  74. * and returns the number of affected rows.
  75. *
  76. * This method supports PDO binding types as well as DBAL mapping types.
  77. *
  78. * @param string $query The SQL query.
  79. * @param array $params The query parameters.
  80. * @param array $types The parameter types.
  81. * @return integer The number of affected rows.
  82. * @since 8.0.0
  83. */
  84. public function executeUpdate($query, array $params = array(), array $types = array());
  85. /**
  86. * Used to get the id of the just inserted element
  87. * @param string $table the name of the table where we inserted the item
  88. * @return int the id of the inserted element
  89. * @since 6.0.0
  90. */
  91. public function lastInsertId($table = null);
  92. /**
  93. * Insert a row if the matching row does not exists.
  94. *
  95. * @param string $table The table name (will replace *PREFIX* with the actual prefix)
  96. * @param array $input data that should be inserted into the table (column name => value)
  97. * @param array|null $compare List of values that should be checked for "if not exists"
  98. * If this is null or an empty array, all keys of $input will be compared
  99. * Please note: text fields (clob) must not be used in the compare array
  100. * @return int number of inserted rows
  101. * @throws \Doctrine\DBAL\DBALException
  102. * @since 6.0.0 - parameter $compare was added in 8.1.0, return type changed from boolean in 8.1.0
  103. */
  104. public function insertIfNotExist($table, $input, array $compare = null);
  105. /**
  106. * Insert or update a row value
  107. *
  108. * @param string $table
  109. * @param array $keys (column name => value)
  110. * @param array $values (column name => value)
  111. * @param array $updatePreconditionValues ensure values match preconditions (column name => value)
  112. * @return int number of new rows
  113. * @throws \Doctrine\DBAL\DBALException
  114. * @throws PreconditionNotMetException
  115. * @since 9.0.0
  116. */
  117. public function setValues($table, array $keys, array $values, array $updatePreconditionValues = []);
  118. /**
  119. * Start a transaction
  120. * @since 6.0.0
  121. */
  122. public function beginTransaction();
  123. /**
  124. * Check if a transaction is active
  125. *
  126. * @return bool
  127. * @since 8.2.0
  128. */
  129. public function inTransaction();
  130. /**
  131. * Commit the database changes done during a transaction that is in progress
  132. * @since 6.0.0
  133. */
  134. public function commit();
  135. /**
  136. * Rollback the database changes done during a transaction that is in progress
  137. * @since 6.0.0
  138. */
  139. public function rollBack();
  140. /**
  141. * Gets the error code and message as a string for logging
  142. * @return string
  143. * @since 6.0.0
  144. */
  145. public function getError();
  146. /**
  147. * Fetch the SQLSTATE associated with the last database operation.
  148. *
  149. * @return integer The last error code.
  150. * @since 8.0.0
  151. */
  152. public function errorCode();
  153. /**
  154. * Fetch extended error information associated with the last database operation.
  155. *
  156. * @return array The last error information.
  157. * @since 8.0.0
  158. */
  159. public function errorInfo();
  160. /**
  161. * Establishes the connection with the database.
  162. *
  163. * @return bool
  164. * @since 8.0.0
  165. */
  166. public function connect();
  167. /**
  168. * Close the database connection
  169. * @since 8.0.0
  170. */
  171. public function close();
  172. /**
  173. * Quotes a given input parameter.
  174. *
  175. * @param mixed $input Parameter to be quoted.
  176. * @param int $type Type of the parameter.
  177. * @return string The quoted parameter.
  178. * @since 8.0.0
  179. */
  180. public function quote($input, $type = IQueryBuilder::PARAM_STR);
  181. /**
  182. * Gets the DatabasePlatform instance that provides all the metadata about
  183. * the platform this driver connects to.
  184. *
  185. * @return \Doctrine\DBAL\Platforms\AbstractPlatform The database platform.
  186. * @since 8.0.0
  187. */
  188. public function getDatabasePlatform();
  189. /**
  190. * Drop a table from the database if it exists
  191. *
  192. * @param string $table table name without the prefix
  193. * @since 8.0.0
  194. */
  195. public function dropTable($table);
  196. /**
  197. * Check if a table exists
  198. *
  199. * @param string $table table name without the prefix
  200. * @return bool
  201. * @since 8.0.0
  202. */
  203. public function tableExists($table);
  204. /**
  205. * Escape a parameter to be used in a LIKE query
  206. *
  207. * @param string $param
  208. * @return string
  209. * @since 9.0.0
  210. */
  211. public function escapeLikeParameter($param);
  212. }