1
0

Exception.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCP\DB;
  25. use Exception as BaseException;
  26. /**
  27. * Database exception
  28. *
  29. * Thrown by Nextcloud's database abstraction layer. This is the base class that
  30. * any specific exception will extend. Use this class in your try-catch to catch
  31. * *any* error related to the database. Use any of the subclasses in the same
  32. * namespace if you are only interested in specific errors.
  33. *
  34. * @psalm-immutable
  35. * @since 21.0.0
  36. */
  37. class Exception extends BaseException {
  38. /**
  39. * Nextcloud lost connection to the database
  40. *
  41. * @since 21.0.0
  42. */
  43. public const REASON_CONNECTION_LOST = 1;
  44. /**
  45. * A database constraint was violated
  46. *
  47. * @since 21.0.0
  48. */
  49. public const REASON_CONSTRAINT_VIOLATION = 2;
  50. /**
  51. * A database object (table, column, index) already exists
  52. *
  53. * @since 21.0.0
  54. */
  55. public const REASON_DATABASE_OBJECT_EXISTS = 3;
  56. /**
  57. * A database object (table, column, index) can't be found
  58. *
  59. * @since 21.0.0
  60. */
  61. public const REASON_DATABASE_OBJECT_NOT_FOUND = 4;
  62. /**
  63. * The database ran into a deadlock
  64. *
  65. * @since 21.0.0
  66. */
  67. public const REASON_DEADLOCK = 5;
  68. /**
  69. * The database driver encountered an issue
  70. *
  71. * @since 21.0.0
  72. */
  73. public const REASON_DRIVER = 6;
  74. /**
  75. * A foreign key constraint was violated
  76. *
  77. * @since 21.0.0
  78. */
  79. public const REASON_FOREIGN_KEY_VIOLATION = 7;
  80. /**
  81. * An invalid argument was passed to the database abstraction
  82. *
  83. * @since 21.0.0
  84. */
  85. public const REASON_INVALID_ARGUMENT = 8;
  86. /**
  87. * A field name was invalid
  88. *
  89. * @since 21.0.0
  90. */
  91. public const REASON_INVALID_FIELD_NAME = 9;
  92. /**
  93. * A name in the query was ambiguous
  94. *
  95. * @since 21.0.0
  96. */
  97. public const REASON_NON_UNIQUE_FIELD_NAME = 10;
  98. /**
  99. * A not null constraint was violated
  100. *
  101. * @since 21.0.0
  102. */
  103. public const REASON_NOT_NULL_CONSTRAINT_VIOLATION = 11;
  104. /**
  105. * A generic server error was encountered
  106. *
  107. * @since 21.0.0
  108. */
  109. public const REASON_SERVER = 12;
  110. /**
  111. * A syntax error was reported by the server
  112. *
  113. * @since 21.0.0
  114. */
  115. public const REASON_SYNTAX_ERROR = 13;
  116. /**
  117. * A unique constraint was violated
  118. *
  119. * @since 21.0.0
  120. */
  121. public const REASON_UNIQUE_CONSTRAINT_VIOLATION = 14;
  122. /**
  123. * @return int|null
  124. * @psalm-return Exception::REASON_*
  125. * @since 21.0.0
  126. */
  127. public function getReason(): ?int {
  128. return null;
  129. }
  130. }