error.go 5.7 KB

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