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.

IDBConnection.php 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. * Create an exclusive read+write lock on a table
  120. *
  121. * Important Note: Due to the nature how locks work on different DBs, it is
  122. * only possible to lock one table at a time. You should also NOT start a
  123. * transaction while holding a lock.
  124. *
  125. * @param string $tableName
  126. * @since 9.1.0
  127. */
  128. public function lockTable($tableName);
  129. /**
  130. * Release a previous acquired lock again
  131. *
  132. * @since 9.1.0
  133. */
  134. public function unlockTable();
  135. /**
  136. * Start a transaction
  137. * @since 6.0.0
  138. */
  139. public function beginTransaction();
  140. /**
  141. * Check if a transaction is active
  142. *
  143. * @return bool
  144. * @since 8.2.0
  145. */
  146. public function inTransaction();
  147. /**
  148. * Commit the database changes done during a transaction that is in progress
  149. * @since 6.0.0
  150. */
  151. public function commit();
  152. /**
  153. * Rollback the database changes done during a transaction that is in progress
  154. * @since 6.0.0
  155. */
  156. public function rollBack();
  157. /**
  158. * Gets the error code and message as a string for logging
  159. * @return string
  160. * @since 6.0.0
  161. */
  162. public function getError();
  163. /**
  164. * Fetch the SQLSTATE associated with the last database operation.
  165. *
  166. * @return integer The last error code.
  167. * @since 8.0.0
  168. */
  169. public function errorCode();
  170. /**
  171. * Fetch extended error information associated with the last database operation.
  172. *
  173. * @return array The last error information.
  174. * @since 8.0.0
  175. */
  176. public function errorInfo();
  177. /**
  178. * Establishes the connection with the database.
  179. *
  180. * @return bool
  181. * @since 8.0.0
  182. */
  183. public function connect();
  184. /**
  185. * Close the database connection
  186. * @since 8.0.0
  187. */
  188. public function close();
  189. /**
  190. * Quotes a given input parameter.
  191. *
  192. * @param mixed $input Parameter to be quoted.
  193. * @param int $type Type of the parameter.
  194. * @return string The quoted parameter.
  195. * @since 8.0.0
  196. */
  197. public function quote($input, $type = IQueryBuilder::PARAM_STR);
  198. /**
  199. * Gets the DatabasePlatform instance that provides all the metadata about
  200. * the platform this driver connects to.
  201. *
  202. * @return \Doctrine\DBAL\Platforms\AbstractPlatform The database platform.
  203. * @since 8.0.0
  204. */
  205. public function getDatabasePlatform();
  206. /**
  207. * Drop a table from the database if it exists
  208. *
  209. * @param string $table table name without the prefix
  210. * @since 8.0.0
  211. */
  212. public function dropTable($table);
  213. /**
  214. * Check if a table exists
  215. *
  216. * @param string $table table name without the prefix
  217. * @return bool
  218. * @since 8.0.0
  219. */
  220. public function tableExists($table);
  221. /**
  222. * Escape a parameter to be used in a LIKE query
  223. *
  224. * @param string $param
  225. * @return string
  226. * @since 9.0.0
  227. */
  228. public function escapeLikeParameter($param);
  229. /**
  230. * Check whether or not the current database support 4byte wide unicode
  231. *
  232. * @return bool
  233. * @since 11.0.0
  234. */
  235. public function supports4ByteText();
  236. }