idbconnection.php 5.1 KB

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