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 6.0KB

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