DB.php 5.1 KB

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