idbconnection.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. * Used to abstract the ownCloud database access away
  42. * @param string $sql the sql query with ? placeholder for params
  43. * @param int $limit the maximum number of rows
  44. * @param int $offset from which row we want to start
  45. * @return \Doctrine\DBAL\Driver\Statement The prepared statement.
  46. * @since 6.0.0
  47. */
  48. public function prepare($sql, $limit=null, $offset=null);
  49. /**
  50. * Executes an, optionally parameterized, SQL query.
  51. *
  52. * If the query is parameterized, a prepared statement is used.
  53. * If an SQLLogger is configured, the execution is logged.
  54. *
  55. * @param string $query The SQL query to execute.
  56. * @param string[] $params The parameters to bind to the query, if any.
  57. * @param array $types The types the previous parameters are in.
  58. * @return \Doctrine\DBAL\Driver\Statement The executed statement.
  59. * @since 8.0.0
  60. */
  61. public function executeQuery($query, array $params = array(), $types = array());
  62. /**
  63. * Executes an SQL INSERT/UPDATE/DELETE query with the given parameters
  64. * and returns the number of affected rows.
  65. *
  66. * This method supports PDO binding types as well as DBAL mapping types.
  67. *
  68. * @param string $query The SQL query.
  69. * @param array $params The query parameters.
  70. * @param array $types The parameter types.
  71. * @return integer The number of affected rows.
  72. * @since 8.0.0
  73. */
  74. public function executeUpdate($query, array $params = array(), array $types = array());
  75. /**
  76. * Used to get the id of the just inserted element
  77. * @param string $table the name of the table where we inserted the item
  78. * @return int the id of the inserted element
  79. * @since 6.0.0
  80. */
  81. public function lastInsertId($table = null);
  82. /**
  83. * Insert a row if the matching row does not exists.
  84. *
  85. * @param string $table The table name (will replace *PREFIX* with the actual prefix)
  86. * @param array $input data that should be inserted into the table (column name => value)
  87. * @param array|null $compare List of values that should be checked for "if not exists"
  88. * If this is null or an empty array, all keys of $input will be compared
  89. * Please note: text fields (clob) must not be used in the compare array
  90. * @return int number of inserted rows
  91. * @throws \Doctrine\DBAL\DBALException
  92. * @since 6.0.0 - parameter $compare was added in 8.1.0, return type changed from boolean in 8.1.0
  93. */
  94. public function insertIfNotExist($table, $input, array $compare = null);
  95. /**
  96. * Start a transaction
  97. * @since 6.0.0
  98. */
  99. public function beginTransaction();
  100. /**
  101. * Commit the database changes done during a transaction that is in progress
  102. * @since 6.0.0
  103. */
  104. public function commit();
  105. /**
  106. * Rollback the database changes done during a transaction that is in progress
  107. * @since 6.0.0
  108. */
  109. public function rollBack();
  110. /**
  111. * Gets the error code and message as a string for logging
  112. * @return string
  113. * @since 6.0.0
  114. */
  115. public function getError();
  116. /**
  117. * Fetch the SQLSTATE associated with the last database operation.
  118. *
  119. * @return integer The last error code.
  120. * @since 8.0.0
  121. */
  122. public function errorCode();
  123. /**
  124. * Fetch extended error information associated with the last database operation.
  125. *
  126. * @return array The last error information.
  127. * @since 8.0.0
  128. */
  129. public function errorInfo();
  130. /**
  131. * Establishes the connection with the database.
  132. *
  133. * @return bool
  134. * @since 8.0.0
  135. */
  136. public function connect();
  137. /**
  138. * Close the database connection
  139. * @since 8.0.0
  140. */
  141. public function close();
  142. /**
  143. * Quotes a given input parameter.
  144. *
  145. * @param mixed $input Parameter to be quoted.
  146. * @param int $type Type of the parameter.
  147. * @return string The quoted parameter.
  148. * @since 8.0.0
  149. */
  150. public function quote($input, $type = \PDO::PARAM_STR);
  151. /**
  152. * Gets the DatabasePlatform instance that provides all the metadata about
  153. * the platform this driver connects to.
  154. *
  155. * @return \Doctrine\DBAL\Platforms\AbstractPlatform The database platform.
  156. * @since 8.0.0
  157. */
  158. public function getDatabasePlatform();
  159. /**
  160. * Drop a table from the database if it exists
  161. *
  162. * @param string $table table name without the prefix
  163. * @since 8.0.0
  164. */
  165. public function dropTable($table);
  166. /**
  167. * Check if a table exists
  168. *
  169. * @param string $table table name without the prefix
  170. * @return bool
  171. * @since 8.0.0
  172. */
  173. public function tableExists($table);
  174. }