1
0

Exception.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\DB;
  8. use Exception as BaseException;
  9. /**
  10. * Database exception
  11. *
  12. * Thrown by Nextcloud's database abstraction layer. This is the base class that
  13. * any specific exception will extend. Use this class in your try-catch to catch
  14. * *any* error related to the database. Use any of the subclasses in the same
  15. * namespace if you are only interested in specific errors.
  16. *
  17. * @psalm-immutable
  18. * @since 21.0.0
  19. */
  20. class Exception extends BaseException {
  21. /**
  22. * Nextcloud lost connection to the database
  23. *
  24. * @since 21.0.0
  25. */
  26. public const REASON_CONNECTION_LOST = 1;
  27. /**
  28. * A database constraint was violated
  29. *
  30. * @since 21.0.0
  31. */
  32. public const REASON_CONSTRAINT_VIOLATION = 2;
  33. /**
  34. * A database object (table, column, index) already exists
  35. *
  36. * @since 21.0.0
  37. */
  38. public const REASON_DATABASE_OBJECT_EXISTS = 3;
  39. /**
  40. * A database object (table, column, index) can't be found
  41. *
  42. * @since 21.0.0
  43. */
  44. public const REASON_DATABASE_OBJECT_NOT_FOUND = 4;
  45. /**
  46. * The database ran into a deadlock
  47. *
  48. * @since 21.0.0
  49. */
  50. public const REASON_DEADLOCK = 5;
  51. /**
  52. * The database driver encountered an issue
  53. *
  54. * @since 21.0.0
  55. */
  56. public const REASON_DRIVER = 6;
  57. /**
  58. * A foreign key constraint was violated
  59. *
  60. * @since 21.0.0
  61. */
  62. public const REASON_FOREIGN_KEY_VIOLATION = 7;
  63. /**
  64. * An invalid argument was passed to the database abstraction
  65. *
  66. * @since 21.0.0
  67. */
  68. public const REASON_INVALID_ARGUMENT = 8;
  69. /**
  70. * A field name was invalid
  71. *
  72. * @since 21.0.0
  73. */
  74. public const REASON_INVALID_FIELD_NAME = 9;
  75. /**
  76. * A name in the query was ambiguous
  77. *
  78. * @since 21.0.0
  79. */
  80. public const REASON_NON_UNIQUE_FIELD_NAME = 10;
  81. /**
  82. * A not null constraint was violated
  83. *
  84. * @since 21.0.0
  85. */
  86. public const REASON_NOT_NULL_CONSTRAINT_VIOLATION = 11;
  87. /**
  88. * A generic server error was encountered
  89. *
  90. * @since 21.0.0
  91. */
  92. public const REASON_SERVER = 12;
  93. /**
  94. * A syntax error was reported by the server
  95. *
  96. * @since 21.0.0
  97. */
  98. public const REASON_SYNTAX_ERROR = 13;
  99. /**
  100. * A unique constraint was violated
  101. *
  102. * @since 21.0.0
  103. */
  104. public const REASON_UNIQUE_CONSTRAINT_VIOLATION = 14;
  105. /**
  106. * The lock wait timeout was exceeded
  107. *
  108. * @since 30.0.0
  109. */
  110. public const REASON_LOCK_WAIT_TIMEOUT = 15;
  111. /**
  112. * @return int|null
  113. * @psalm-return Exception::REASON_*
  114. * @since 21.0.0
  115. */
  116. public function getReason(): ?int {
  117. return null;
  118. }
  119. }