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.

128 lines
5.4 KiB

  1. // Copyright (C) 2014 Yasuhiro Matsumoto <mattn.jp@gmail.com>.
  2. //
  3. // Use of this source code is governed by an MIT-style
  4. // license that can be found in the LICENSE file.
  5. package sqlite3
  6. import "C"
  7. type ErrNo int
  8. const ErrNoMask C.int = 0xff
  9. type ErrNoExtended int
  10. type Error struct {
  11. Code ErrNo /* The error code returned by SQLite */
  12. ExtendedCode ErrNoExtended /* The extended error code returned by SQLite */
  13. err string /* The error string returned by sqlite3_errmsg(),
  14. this usually contains more specific details. */
  15. }
  16. // result codes from http://www.sqlite.org/c3ref/c_abort.html
  17. var (
  18. ErrError = ErrNo(1) /* SQL error or missing database */
  19. ErrInternal = ErrNo(2) /* Internal logic error in SQLite */
  20. ErrPerm = ErrNo(3) /* Access permission denied */
  21. ErrAbort = ErrNo(4) /* Callback routine requested an abort */
  22. ErrBusy = ErrNo(5) /* The database file is locked */
  23. ErrLocked = ErrNo(6) /* A table in the database is locked */
  24. ErrNomem = ErrNo(7) /* A malloc() failed */
  25. ErrReadonly = ErrNo(8) /* Attempt to write a readonly database */
  26. ErrInterrupt = ErrNo(9) /* Operation terminated by sqlite3_interrupt() */
  27. ErrIoErr = ErrNo(10) /* Some kind of disk I/O error occurred */
  28. ErrCorrupt = ErrNo(11) /* The database disk image is malformed */
  29. ErrNotFound = ErrNo(12) /* Unknown opcode in sqlite3_file_control() */
  30. ErrFull = ErrNo(13) /* Insertion failed because database is full */
  31. ErrCantOpen = ErrNo(14) /* Unable to open the database file */
  32. ErrProtocol = ErrNo(15) /* Database lock protocol error */
  33. ErrEmpty = ErrNo(16) /* Database is empty */
  34. ErrSchema = ErrNo(17) /* The database schema changed */
  35. ErrTooBig = ErrNo(18) /* String or BLOB exceeds size limit */
  36. ErrConstraint = ErrNo(19) /* Abort due to constraint violation */
  37. ErrMismatch = ErrNo(20) /* Data type mismatch */
  38. ErrMisuse = ErrNo(21) /* Library used incorrectly */
  39. ErrNoLFS = ErrNo(22) /* Uses OS features not supported on host */
  40. ErrAuth = ErrNo(23) /* Authorization denied */
  41. ErrFormat = ErrNo(24) /* Auxiliary database format error */
  42. ErrRange = ErrNo(25) /* 2nd parameter to sqlite3_bind out of range */
  43. ErrNotADB = ErrNo(26) /* File opened that is not a database file */
  44. ErrNotice = ErrNo(27) /* Notifications from sqlite3_log() */
  45. ErrWarning = ErrNo(28) /* Warnings from sqlite3_log() */
  46. )
  47. func (err ErrNo) Error() string {
  48. return Error{Code: err}.Error()
  49. }
  50. func (err ErrNo) Extend(by int) ErrNoExtended {
  51. return ErrNoExtended(int(err) | (by << 8))
  52. }
  53. func (err ErrNoExtended) Error() string {
  54. return Error{Code: ErrNo(C.int(err) & ErrNoMask), ExtendedCode: err}.Error()
  55. }
  56. func (err Error) Error() string {
  57. if err.err != "" {
  58. return err.err
  59. }
  60. return errorString(err)
  61. }
  62. // result codes from http://www.sqlite.org/c3ref/c_abort_rollback.html
  63. var (
  64. ErrIoErrRead = ErrIoErr.Extend(1)
  65. ErrIoErrShortRead = ErrIoErr.Extend(2)
  66. ErrIoErrWrite = ErrIoErr.Extend(3)
  67. ErrIoErrFsync = ErrIoErr.Extend(4)
  68. ErrIoErrDirFsync = ErrIoErr.Extend(5)
  69. ErrIoErrTruncate = ErrIoErr.Extend(6)
  70. ErrIoErrFstat = ErrIoErr.Extend(7)
  71. ErrIoErrUnlock = ErrIoErr.Extend(8)
  72. ErrIoErrRDlock = ErrIoErr.Extend(9)
  73. ErrIoErrDelete = ErrIoErr.Extend(10)
  74. ErrIoErrBlocked = ErrIoErr.Extend(11)
  75. ErrIoErrNoMem = ErrIoErr.Extend(12)
  76. ErrIoErrAccess = ErrIoErr.Extend(13)
  77. ErrIoErrCheckReservedLock = ErrIoErr.Extend(14)
  78. ErrIoErrLock = ErrIoErr.Extend(15)
  79. ErrIoErrClose = ErrIoErr.Extend(16)
  80. ErrIoErrDirClose = ErrIoErr.Extend(17)
  81. ErrIoErrSHMOpen = ErrIoErr.Extend(18)
  82. ErrIoErrSHMSize = ErrIoErr.Extend(19)
  83. ErrIoErrSHMLock = ErrIoErr.Extend(20)
  84. ErrIoErrSHMMap = ErrIoErr.Extend(21)
  85. ErrIoErrSeek = ErrIoErr.Extend(22)
  86. ErrIoErrDeleteNoent = ErrIoErr.Extend(23)
  87. ErrIoErrMMap = ErrIoErr.Extend(24)
  88. ErrIoErrGetTempPath = ErrIoErr.Extend(25)
  89. ErrIoErrConvPath = ErrIoErr.Extend(26)
  90. ErrLockedSharedCache = ErrLocked.Extend(1)
  91. ErrBusyRecovery = ErrBusy.Extend(1)
  92. ErrBusySnapshot = ErrBusy.Extend(2)
  93. ErrCantOpenNoTempDir = ErrCantOpen.Extend(1)
  94. ErrCantOpenIsDir = ErrCantOpen.Extend(2)
  95. ErrCantOpenFullPath = ErrCantOpen.Extend(3)
  96. ErrCantOpenConvPath = ErrCantOpen.Extend(4)
  97. ErrCorruptVTab = ErrCorrupt.Extend(1)
  98. ErrReadonlyRecovery = ErrReadonly.Extend(1)
  99. ErrReadonlyCantLock = ErrReadonly.Extend(2)
  100. ErrReadonlyRollback = ErrReadonly.Extend(3)
  101. ErrReadonlyDbMoved = ErrReadonly.Extend(4)
  102. ErrAbortRollback = ErrAbort.Extend(2)
  103. ErrConstraintCheck = ErrConstraint.Extend(1)
  104. ErrConstraintCommitHook = ErrConstraint.Extend(2)
  105. ErrConstraintForeignKey = ErrConstraint.Extend(3)
  106. ErrConstraintFunction = ErrConstraint.Extend(4)
  107. ErrConstraintNotNull = ErrConstraint.Extend(5)
  108. ErrConstraintPrimaryKey = ErrConstraint.Extend(6)
  109. ErrConstraintTrigger = ErrConstraint.Extend(7)
  110. ErrConstraintUnique = ErrConstraint.Extend(8)
  111. ErrConstraintVTab = ErrConstraint.Extend(9)
  112. ErrConstraintRowId = ErrConstraint.Extend(10)
  113. ErrNoticeRecoverWAL = ErrNotice.Extend(1)
  114. ErrNoticeRecoverRollback = ErrNotice.Extend(2)
  115. ErrWarningAutoIndex = ErrWarning.Extend(1)
  116. )