DB.php 5.0 KB

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