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.

db.php 5.0KB

12 years ago
8 years ago
12 years ago
12 years ago
10 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Dan Bartram <daneybartram@gmail.com>
  5. * @author Felix Moeller <mail@felixmoeller.de>
  6. * @author Frank Karlitschek <frank@owncloud.org>
  7. * @author Joas Schilling <nickvergessen@owncloud.com>
  8. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Robin Appelman <icewind@owncloud.com>
  11. * @author Thomas Müller <thomas.mueller@tmit.eu>
  12. * @author Thomas Tanghus <thomas@tanghus.net>
  13. *
  14. * @copyright Copyright (c) 2016, ownCloud, Inc.
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. /**
  31. * Public interface of ownCloud for apps to use.
  32. * DB Class
  33. *
  34. */
  35. // use OCP namespace for all classes that are considered public.
  36. // This means that they should be used by apps instead of the internal ownCloud classes
  37. namespace OCP;
  38. /**
  39. * This class provides access to the internal database system. Use this class exlusively if you want to access databases
  40. * @deprecated 8.1.0 use methods of \OCP\IDBConnection - \OC::$server->getDatabaseConnection()
  41. * @since 4.5.0
  42. */
  43. class DB {
  44. /**
  45. * Prepare a SQL query
  46. * @param string $query Query string
  47. * @param int $limit Limit of the SQL statement
  48. * @param int $offset Offset of the SQL statement
  49. * @return \OC_DB_StatementWrapper prepared SQL query
  50. *
  51. * SQL query via Doctrine prepare(), needs to be execute()'d!
  52. * @deprecated 8.1.0 use prepare() of \OCP\IDBConnection - \OC::$server->getDatabaseConnection()
  53. * @since 4.5.0
  54. */
  55. static public function prepare( $query, $limit=null, $offset=null ) {
  56. return(\OC_DB::prepare($query, $limit, $offset));
  57. }
  58. /**
  59. * Insert a row if the matching row does not exists.
  60. *
  61. * @param string $table The table name (will replace *PREFIX* with the actual prefix)
  62. * @param array $input data that should be inserted into the table (column name => value)
  63. * @param array|null $compare List of values that should be checked for "if not exists"
  64. * If this is null or an empty array, all keys of $input will be compared
  65. * @return int number of inserted rows
  66. * @throws \Doctrine\DBAL\DBALException
  67. * @deprecated 8.1.0 use insertIfNotExist() of \OCP\IDBConnection - \OC::$server->getDatabaseConnection()
  68. * @since 5.0.0 - parameter $compare was added in 8.1.0
  69. *
  70. */
  71. public static function insertIfNotExist($table, $input, array $compare = null) {
  72. return \OC::$server->getDatabaseConnection()->insertIfNotExist($table, $input, $compare);
  73. }
  74. /**
  75. * Gets last value of autoincrement
  76. * @param string $table The optional table name (will replace *PREFIX*) and add sequence suffix
  77. * @return string
  78. *
  79. * \Doctrine\DBAL\Connection lastInsertID()
  80. *
  81. * Call this method right after the insert command or other functions may
  82. * cause trouble!
  83. * @deprecated 8.1.0 use lastInsertId() of \OCP\IDBConnection - \OC::$server->getDatabaseConnection()
  84. * @since 4.5.0
  85. */
  86. public static function insertid($table=null) {
  87. return \OC::$server->getDatabaseConnection()->lastInsertId($table);
  88. }
  89. /**
  90. * Start a transaction
  91. * @deprecated 8.1.0 use beginTransaction() of \OCP\IDBConnection - \OC::$server->getDatabaseConnection()
  92. * @since 4.5.0
  93. */
  94. public static function beginTransaction() {
  95. \OC::$server->getDatabaseConnection()->beginTransaction();
  96. }
  97. /**
  98. * Commit the database changes done during a transaction that is in progress
  99. * @deprecated 8.1.0 use commit() of \OCP\IDBConnection - \OC::$server->getDatabaseConnection()
  100. * @since 4.5.0
  101. */
  102. public static function commit() {
  103. \OC::$server->getDatabaseConnection()->commit();
  104. }
  105. /**
  106. * Rollback the database changes done during a transaction that is in progress
  107. * @deprecated 8.1.0 use rollback() of \OCP\IDBConnection - \OC::$server->getDatabaseConnection()
  108. * @since 8.0.0
  109. */
  110. public static function rollback() {
  111. \OC::$server->getDatabaseConnection()->rollback();
  112. }
  113. /**
  114. * Check if a result is an error, works with Doctrine
  115. * @param mixed $result
  116. * @return bool
  117. * @deprecated 8.1.0 Doctrine returns false on error (and throws an exception)
  118. * @since 4.5.0
  119. */
  120. public static function isError($result) {
  121. // Doctrine returns false on error (and throws an exception)
  122. return $result === false;
  123. }
  124. /**
  125. * returns the error code and message as a string for logging
  126. * works with DoctrineException
  127. * @return string
  128. * @deprecated 8.1.0 use getError() of \OCP\IDBConnection - \OC::$server->getDatabaseConnection()
  129. * @since 6.0.0
  130. */
  131. public static function getErrorMessage() {
  132. return \OC::$server->getDatabaseConnection()->getError();
  133. }
  134. }