IDBConnection.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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 Doctrine\DBAL\Schema\Schema;
  36. use OCP\DB\QueryBuilder\IQueryBuilder;
  37. /**
  38. * Interface IDBConnection
  39. *
  40. * @package OCP
  41. * @since 6.0.0
  42. */
  43. interface IDBConnection {
  44. /**
  45. * Gets the QueryBuilder for the connection.
  46. *
  47. * @return \OCP\DB\QueryBuilder\IQueryBuilder
  48. * @since 8.2.0
  49. */
  50. public function getQueryBuilder();
  51. /**
  52. * Used to abstract the ownCloud database access away
  53. * @param string $sql the sql query with ? placeholder for params
  54. * @param int $limit the maximum number of rows
  55. * @param int $offset from which row we want to start
  56. * @return \Doctrine\DBAL\Driver\Statement The prepared statement.
  57. * @since 6.0.0
  58. */
  59. public function prepare($sql, $limit=null, $offset=null);
  60. /**
  61. * Executes an, optionally parameterized, SQL query.
  62. *
  63. * If the query is parameterized, a prepared statement is used.
  64. * If an SQLLogger is configured, the execution is logged.
  65. *
  66. * @param string $query The SQL query to execute.
  67. * @param string[] $params The parameters to bind to the query, if any.
  68. * @param array $types The types the previous parameters are in.
  69. * @return \Doctrine\DBAL\Driver\Statement The executed statement.
  70. * @since 8.0.0
  71. */
  72. public function executeQuery($query, array $params = array(), $types = array());
  73. /**
  74. * Executes an SQL INSERT/UPDATE/DELETE query with the given parameters
  75. * and returns the number of affected rows.
  76. *
  77. * This method supports PDO binding types as well as DBAL mapping types.
  78. *
  79. * @param string $query The SQL query.
  80. * @param array $params The query parameters.
  81. * @param array $types The parameter types.
  82. * @return integer The number of affected rows.
  83. * @since 8.0.0
  84. */
  85. public function executeUpdate($query, array $params = array(), array $types = array());
  86. /**
  87. * Used to get the id of the just inserted element
  88. * @param string $table the name of the table where we inserted the item
  89. * @return int the id of the inserted element
  90. * @since 6.0.0
  91. */
  92. public function lastInsertId($table = null);
  93. /**
  94. * Insert a row if the matching row does not exists.
  95. *
  96. * @param string $table The table name (will replace *PREFIX* with the actual prefix)
  97. * @param array $input data that should be inserted into the table (column name => value)
  98. * @param array|null $compare List of values that should be checked for "if not exists"
  99. * If this is null or an empty array, all keys of $input will be compared
  100. * Please note: text fields (clob) must not be used in the compare array
  101. * @return int number of inserted rows
  102. * @throws \Doctrine\DBAL\DBALException
  103. * @since 6.0.0 - parameter $compare was added in 8.1.0, return type changed from boolean in 8.1.0
  104. */
  105. public function insertIfNotExist($table, $input, array $compare = null);
  106. /**
  107. * Insert or update a row value
  108. *
  109. * @param string $table
  110. * @param array $keys (column name => value)
  111. * @param array $values (column name => value)
  112. * @param array $updatePreconditionValues ensure values match preconditions (column name => value)
  113. * @return int number of new rows
  114. * @throws \Doctrine\DBAL\DBALException
  115. * @throws PreconditionNotMetException
  116. * @since 9.0.0
  117. */
  118. public function setValues($table, array $keys, array $values, array $updatePreconditionValues = []);
  119. /**
  120. * Create an exclusive read+write lock on a table
  121. *
  122. * Important Note: Due to the nature how locks work on different DBs, it is
  123. * only possible to lock one table at a time. You should also NOT start a
  124. * transaction while holding a lock.
  125. *
  126. * @param string $tableName
  127. * @since 9.1.0
  128. */
  129. public function lockTable($tableName);
  130. /**
  131. * Release a previous acquired lock again
  132. *
  133. * @since 9.1.0
  134. */
  135. public function unlockTable();
  136. /**
  137. * Start a transaction
  138. * @since 6.0.0
  139. */
  140. public function beginTransaction();
  141. /**
  142. * Check if a transaction is active
  143. *
  144. * @return bool
  145. * @since 8.2.0
  146. */
  147. public function inTransaction();
  148. /**
  149. * Commit the database changes done during a transaction that is in progress
  150. * @since 6.0.0
  151. */
  152. public function commit();
  153. /**
  154. * Rollback the database changes done during a transaction that is in progress
  155. * @since 6.0.0
  156. */
  157. public function rollBack();
  158. /**
  159. * Gets the error code and message as a string for logging
  160. * @return string
  161. * @since 6.0.0
  162. */
  163. public function getError();
  164. /**
  165. * Fetch the SQLSTATE associated with the last database operation.
  166. *
  167. * @return integer The last error code.
  168. * @since 8.0.0
  169. */
  170. public function errorCode();
  171. /**
  172. * Fetch extended error information associated with the last database operation.
  173. *
  174. * @return array The last error information.
  175. * @since 8.0.0
  176. */
  177. public function errorInfo();
  178. /**
  179. * Establishes the connection with the database.
  180. *
  181. * @return bool
  182. * @since 8.0.0
  183. */
  184. public function connect();
  185. /**
  186. * Close the database connection
  187. * @since 8.0.0
  188. */
  189. public function close();
  190. /**
  191. * Quotes a given input parameter.
  192. *
  193. * @param mixed $input Parameter to be quoted.
  194. * @param int $type Type of the parameter.
  195. * @return string The quoted parameter.
  196. * @since 8.0.0
  197. */
  198. public function quote($input, $type = IQueryBuilder::PARAM_STR);
  199. /**
  200. * Gets the DatabasePlatform instance that provides all the metadata about
  201. * the platform this driver connects to.
  202. *
  203. * @return \Doctrine\DBAL\Platforms\AbstractPlatform The database platform.
  204. * @since 8.0.0
  205. */
  206. public function getDatabasePlatform();
  207. /**
  208. * Drop a table from the database if it exists
  209. *
  210. * @param string $table table name without the prefix
  211. * @since 8.0.0
  212. */
  213. public function dropTable($table);
  214. /**
  215. * Check if a table exists
  216. *
  217. * @param string $table table name without the prefix
  218. * @return bool
  219. * @since 8.0.0
  220. */
  221. public function tableExists($table);
  222. /**
  223. * Escape a parameter to be used in a LIKE query
  224. *
  225. * @param string $param
  226. * @return string
  227. * @since 9.0.0
  228. */
  229. public function escapeLikeParameter($param);
  230. /**
  231. * Check whether or not the current database support 4byte wide unicode
  232. *
  233. * @return bool
  234. * @since 11.0.0
  235. */
  236. public function supports4ByteText();
  237. /**
  238. * Create the schema of the connected database
  239. *
  240. * @return Schema
  241. * @since 13.0.0
  242. */
  243. public function createSchema();
  244. /**
  245. * Migrate the database to the given schema
  246. *
  247. * @param Schema $toSchema
  248. * @since 13.0.0
  249. */
  250. public function migrateToSchema(Schema $toSchema);
  251. }