idbconnection.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Bart Visscher
  6. * @copyright 2013 Bart Visscher bartv@thisnet.nl
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * Public interface of ownCloud for apps to use.
  24. * DBConnection interface
  25. *
  26. */
  27. // use OCP namespace for all classes that are considered public.
  28. // This means that they should be used by apps instead of the internal ownCloud classes
  29. namespace OCP;
  30. /**
  31. * TODO: Description
  32. */
  33. interface IDBConnection {
  34. /**
  35. * Used to abstract the owncloud database access away
  36. * @param string $sql the sql query with ? placeholder for params
  37. * @param int $limit the maximum number of rows
  38. * @param int $offset from which row we want to start
  39. * @return \Doctrine\DBAL\Driver\Statement The prepared statement.
  40. */
  41. public function prepare($sql, $limit=null, $offset=null);
  42. /**
  43. * Executes an, optionally parameterized, SQL query.
  44. *
  45. * If the query is parameterized, a prepared statement is used.
  46. * If an SQLLogger is configured, the execution is logged.
  47. *
  48. * @param string $query The SQL query to execute.
  49. * @param string[] $params The parameters to bind to the query, if any.
  50. * @param array $types The types the previous parameters are in.
  51. * @return \Doctrine\DBAL\Driver\Statement The executed statement.
  52. */
  53. public function executeQuery($query, array $params = array(), $types = array());
  54. /**
  55. * Executes an SQL INSERT/UPDATE/DELETE query with the given parameters
  56. * and returns the number of affected rows.
  57. *
  58. * This method supports PDO binding types as well as DBAL mapping types.
  59. *
  60. * @param string $query The SQL query.
  61. * @param array $params The query parameters.
  62. * @param array $types The parameter types.
  63. * @return integer The number of affected rows.
  64. */
  65. public function executeUpdate($query, array $params = array(), array $types = array());
  66. /**
  67. * Used to get the id of the just inserted element
  68. * @param string $table the name of the table where we inserted the item
  69. * @return int the id of the inserted element
  70. */
  71. public function lastInsertId($table = null);
  72. /**
  73. * Insert a row if a matching row doesn't exists.
  74. * @param string $table The table name (will replace *PREFIX*) to perform the replace on.
  75. * @param array $input
  76. * @throws \OC\HintException
  77. *
  78. * The input array if in the form:
  79. *
  80. * array ( 'id' => array ( 'value' => 6,
  81. * 'key' => true
  82. * ),
  83. * 'name' => array ('value' => 'Stoyan'),
  84. * 'family' => array ('value' => 'Stefanov'),
  85. * 'birth_date' => array ('value' => '1975-06-20')
  86. * );
  87. * @return bool
  88. *
  89. */
  90. public function insertIfNotExist($table, $input);
  91. /**
  92. * Start a transaction
  93. */
  94. public function beginTransaction();
  95. /**
  96. * Commit the database changes done during a transaction that is in progress
  97. */
  98. public function commit();
  99. /**
  100. * Rollback the database changes done during a transaction that is in progress
  101. */
  102. public function rollBack();
  103. /**
  104. * Gets the error code and message as a string for logging
  105. * @return string
  106. */
  107. public function getError();
  108. /**
  109. * Fetch the SQLSTATE associated with the last database operation.
  110. *
  111. * @return integer The last error code.
  112. */
  113. public function errorCode();
  114. /**
  115. * Fetch extended error information associated with the last database operation.
  116. *
  117. * @return array The last error information.
  118. */
  119. public function errorInfo();
  120. /**
  121. * Establishes the connection with the database.
  122. *
  123. * @return bool
  124. */
  125. public function connect();
  126. /**
  127. * Close the database connection
  128. */
  129. public function close();
  130. /**
  131. * Quotes a given input parameter.
  132. *
  133. * @param mixed $input Parameter to be quoted.
  134. * @param int $type Type of the parameter.
  135. * @return string The quoted parameter.
  136. */
  137. public function quote($input, $type = \PDO::PARAM_STR);
  138. /**
  139. * Gets the DatabasePlatform instance that provides all the metadata about
  140. * the platform this driver connects to.
  141. *
  142. * @return \Doctrine\DBAL\Platforms\AbstractPlatform The database platform.
  143. */
  144. public function getDatabasePlatform();
  145. /**
  146. * Drop a table from the database if it exists
  147. *
  148. * @param string $table table name without the prefix
  149. */
  150. public function dropTable($table);
  151. /**
  152. * Check if a table exists
  153. *
  154. * @param string $table table name without the prefix
  155. * @return bool
  156. */
  157. public function tableExists($table);
  158. }