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.

135 lines
5.6 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. // 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. func (err Error) Error() string {
  64. if err.err != "" {
  65. return err.err
  66. }
  67. return errorString(err)
  68. }
  69. // result codes from http://www.sqlite.org/c3ref/c_abort_rollback.html
  70. var (
  71. ErrIoErrRead = ErrIoErr.Extend(1)
  72. ErrIoErrShortRead = ErrIoErr.Extend(2)
  73. ErrIoErrWrite = ErrIoErr.Extend(3)
  74. ErrIoErrFsync = ErrIoErr.Extend(4)
  75. ErrIoErrDirFsync = ErrIoErr.Extend(5)
  76. ErrIoErrTruncate = ErrIoErr.Extend(6)
  77. ErrIoErrFstat = ErrIoErr.Extend(7)
  78. ErrIoErrUnlock = ErrIoErr.Extend(8)
  79. ErrIoErrRDlock = ErrIoErr.Extend(9)
  80. ErrIoErrDelete = ErrIoErr.Extend(10)
  81. ErrIoErrBlocked = ErrIoErr.Extend(11)
  82. ErrIoErrNoMem = ErrIoErr.Extend(12)
  83. ErrIoErrAccess = ErrIoErr.Extend(13)
  84. ErrIoErrCheckReservedLock = ErrIoErr.Extend(14)
  85. ErrIoErrLock = ErrIoErr.Extend(15)
  86. ErrIoErrClose = ErrIoErr.Extend(16)
  87. ErrIoErrDirClose = ErrIoErr.Extend(17)
  88. ErrIoErrSHMOpen = ErrIoErr.Extend(18)
  89. ErrIoErrSHMSize = ErrIoErr.Extend(19)
  90. ErrIoErrSHMLock = ErrIoErr.Extend(20)
  91. ErrIoErrSHMMap = ErrIoErr.Extend(21)
  92. ErrIoErrSeek = ErrIoErr.Extend(22)
  93. ErrIoErrDeleteNoent = ErrIoErr.Extend(23)
  94. ErrIoErrMMap = ErrIoErr.Extend(24)
  95. ErrIoErrGetTempPath = ErrIoErr.Extend(25)
  96. ErrIoErrConvPath = ErrIoErr.Extend(26)
  97. ErrLockedSharedCache = ErrLocked.Extend(1)
  98. ErrBusyRecovery = ErrBusy.Extend(1)
  99. ErrBusySnapshot = ErrBusy.Extend(2)
  100. ErrCantOpenNoTempDir = ErrCantOpen.Extend(1)
  101. ErrCantOpenIsDir = ErrCantOpen.Extend(2)
  102. ErrCantOpenFullPath = ErrCantOpen.Extend(3)
  103. ErrCantOpenConvPath = ErrCantOpen.Extend(4)
  104. ErrCorruptVTab = ErrCorrupt.Extend(1)
  105. ErrReadonlyRecovery = ErrReadonly.Extend(1)
  106. ErrReadonlyCantLock = ErrReadonly.Extend(2)
  107. ErrReadonlyRollback = ErrReadonly.Extend(3)
  108. ErrReadonlyDbMoved = ErrReadonly.Extend(4)
  109. ErrAbortRollback = ErrAbort.Extend(2)
  110. ErrConstraintCheck = ErrConstraint.Extend(1)
  111. ErrConstraintCommitHook = ErrConstraint.Extend(2)
  112. ErrConstraintForeignKey = ErrConstraint.Extend(3)
  113. ErrConstraintFunction = ErrConstraint.Extend(4)
  114. ErrConstraintNotNull = ErrConstraint.Extend(5)
  115. ErrConstraintPrimaryKey = ErrConstraint.Extend(6)
  116. ErrConstraintTrigger = ErrConstraint.Extend(7)
  117. ErrConstraintUnique = ErrConstraint.Extend(8)
  118. ErrConstraintVTab = ErrConstraint.Extend(9)
  119. ErrConstraintRowID = ErrConstraint.Extend(10)
  120. ErrNoticeRecoverWAL = ErrNotice.Extend(1)
  121. ErrNoticeRecoverRollback = ErrNotice.Extend(2)
  122. ErrWarningAutoIndex = ErrWarning.Extend(1)
  123. )