Skip to content

Commit

Permalink
Export raw SQLite result codes
Browse files Browse the repository at this point in the history
Signed-off-by: Cole Miller <[email protected]>
  • Loading branch information
cole-miller committed Jul 17, 2023
1 parent cb3fab6 commit 7f6386c
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 1 deletion.
114 changes: 113 additions & 1 deletion driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Driver struct {
// Error is returned in case of database errors.
type Error = protocol.Error

// Error codes. Values here mostly overlap with native SQLite codes.
// dqlite-specific error codes, compatible with the SQLite set.
const (
ErrBusy = 5
ErrBusyRecovery = 5 | (1 << 8)
Expand All @@ -61,6 +61,118 @@ const (
errIoErrLeadershipLostLegacy = errIoErr | (33 << 8)
)

// SQLite result codes.
const (
// Basic result codes:
SQLITE_OK = 0
SQLITE_ERROR = 1
SQLITE_INTERNAL = 2
SQLITE_PERM = 3
SQLITE_ABORT = 4
SQLITE_BUSY = 5
SQLITE_LOCKED = 6
SQLITE_NOMEM = 7
SQLITE_READONLY = 8
SQLITE_INTERRUPT = 9
SQLITE_IOERR = 10
SQLITE_CORRUPT = 11
SQLITE_NOTFOUND = 12
SQLITE_FULL = 13
SQLITE_CANTOPEN = 14
SQLITE_PROTOCOL = 15
SQLITE_EMPTY = 16
SQLITE_SCHEMA = 17
SQLITE_TOOBIG = 18
SQLITE_CONSTRAINT = 19
SQLITE_MISMATCH = 20
SQLITE_MISUSE = 21
SQLITE_NOLFS = 22
SQLITE_AUTH = 23
SQLITE_FORMAT = 24
SQLITE_RANGE = 25
SQLITE_NOTADB = 26
SQLITE_NOTICE = 27
SQLITE_WARNING = 28
SQLITE_ROW = 100
SQLITE_DONE = 101

// Extended result codes:
SQLITE_ERROR_MISSING_COLLSEQ = (SQLITE_ERROR | (1<<8))
SQLITE_ERROR_RETRY = (SQLITE_ERROR | (2<<8))
SQLITE_ERROR_SNAPSHOT = (SQLITE_ERROR | (3<<8))
SQLITE_IOERR_READ = (SQLITE_IOERR | (1<<8))
SQLITE_IOERR_SHORT_READ = (SQLITE_IOERR | (2<<8))
SQLITE_IOERR_WRITE = (SQLITE_IOERR | (3<<8))
SQLITE_IOERR_FSYNC = (SQLITE_IOERR | (4<<8))
SQLITE_IOERR_DIR_FSYNC = (SQLITE_IOERR | (5<<8))
SQLITE_IOERR_TRUNCATE = (SQLITE_IOERR | (6<<8))
SQLITE_IOERR_FSTAT = (SQLITE_IOERR | (7<<8))
SQLITE_IOERR_UNLOCK = (SQLITE_IOERR | (8<<8))
SQLITE_IOERR_RDLOCK = (SQLITE_IOERR | (9<<8))
SQLITE_IOERR_DELETE = (SQLITE_IOERR | (10<<8))
SQLITE_IOERR_BLOCKED = (SQLITE_IOERR | (11<<8))
SQLITE_IOERR_NOMEM = (SQLITE_IOERR | (12<<8))
SQLITE_IOERR_ACCESS = (SQLITE_IOERR | (13<<8))
SQLITE_IOERR_CHECKRESERVEDLOCK = (SQLITE_IOERR | (14<<8))
SQLITE_IOERR_LOCK = (SQLITE_IOERR | (15<<8))
SQLITE_IOERR_CLOSE = (SQLITE_IOERR | (16<<8))
SQLITE_IOERR_DIR_CLOSE = (SQLITE_IOERR | (17<<8))
SQLITE_IOERR_SHMOPEN = (SQLITE_IOERR | (18<<8))
SQLITE_IOERR_SHMSIZE = (SQLITE_IOERR | (19<<8))
SQLITE_IOERR_SHMLOCK = (SQLITE_IOERR | (20<<8))
SQLITE_IOERR_SHMMAP = (SQLITE_IOERR | (21<<8))
SQLITE_IOERR_SEEK = (SQLITE_IOERR | (22<<8))
SQLITE_IOERR_DELETE_NOENT = (SQLITE_IOERR | (23<<8))
SQLITE_IOERR_MMAP = (SQLITE_IOERR | (24<<8))
SQLITE_IOERR_GETTEMPPATH = (SQLITE_IOERR | (25<<8))
SQLITE_IOERR_CONVPATH = (SQLITE_IOERR | (26<<8))
SQLITE_IOERR_VNODE = (SQLITE_IOERR | (27<<8))
SQLITE_IOERR_AUTH = (SQLITE_IOERR | (28<<8))
SQLITE_IOERR_BEGIN_ATOMIC = (SQLITE_IOERR | (29<<8))
SQLITE_IOERR_COMMIT_ATOMIC = (SQLITE_IOERR | (30<<8))
SQLITE_IOERR_ROLLBACK_ATOMIC = (SQLITE_IOERR | (31<<8))
SQLITE_IOERR_DATA = (SQLITE_IOERR | (32<<8))
SQLITE_IOERR_CORRUPTFS = (SQLITE_IOERR | (33<<8))
SQLITE_LOCKED_SHAREDCACHE = (SQLITE_LOCKED | (1<<8))
SQLITE_LOCKED_VTAB = (SQLITE_LOCKED | (2<<8))
SQLITE_BUSY_RECOVERY = (SQLITE_BUSY | (1<<8))
SQLITE_BUSY_SNAPSHOT = (SQLITE_BUSY | (2<<8))
SQLITE_BUSY_TIMEOUT = (SQLITE_BUSY | (3<<8))
SQLITE_CANTOPEN_NOTEMPDIR = (SQLITE_CANTOPEN | (1<<8))
SQLITE_CANTOPEN_ISDIR = (SQLITE_CANTOPEN | (2<<8))
SQLITE_CANTOPEN_FULLPATH = (SQLITE_CANTOPEN | (3<<8))
SQLITE_CANTOPEN_CONVPATH = (SQLITE_CANTOPEN | (4<<8))
SQLITE_CANTOPEN_SYMLINK = (SQLITE_CANTOPEN | (6<<8))
SQLITE_CORRUPT_VTAB = (SQLITE_CORRUPT | (1<<8))
SQLITE_CORRUPT_SEQUENCE = (SQLITE_CORRUPT | (2<<8))
SQLITE_CORRUPT_INDEX = (SQLITE_CORRUPT | (3<<8))
SQLITE_READONLY_RECOVERY = (SQLITE_READONLY | (1<<8))
SQLITE_READONLY_CANTLOCK = (SQLITE_READONLY | (2<<8))
SQLITE_READONLY_ROLLBACK = (SQLITE_READONLY | (3<<8))
SQLITE_READONLY_DBMOVED = (SQLITE_READONLY | (4<<8))
SQLITE_READONLY_CANTINIT = (SQLITE_READONLY | (5<<8))
SQLITE_READONLY_DIRECTORY = (SQLITE_READONLY | (6<<8))
SQLITE_ABORT_ROLLBACK = (SQLITE_ABORT | (2<<8))
SQLITE_CONSTRAINT_CHECK = (SQLITE_CONSTRAINT | (1<<8))
SQLITE_CONSTRAINT_COMMITHOOK = (SQLITE_CONSTRAINT | (2<<8))
SQLITE_CONSTRAINT_FOREIGNKEY = (SQLITE_CONSTRAINT | (3<<8))
SQLITE_CONSTRAINT_FUNCTION = (SQLITE_CONSTRAINT | (4<<8))
SQLITE_CONSTRAINT_NOTNULL = (SQLITE_CONSTRAINT | (5<<8))
SQLITE_CONSTRAINT_PRIMARYKEY = (SQLITE_CONSTRAINT | (6<<8))
SQLITE_CONSTRAINT_TRIGGER = (SQLITE_CONSTRAINT | (7<<8))
SQLITE_CONSTRAINT_UNIQUE = (SQLITE_CONSTRAINT | (8<<8))
SQLITE_CONSTRAINT_VTAB = (SQLITE_CONSTRAINT | (9<<8))
SQLITE_CONSTRAINT_ROWID = (SQLITE_CONSTRAINT |(10<<8))
SQLITE_CONSTRAINT_PINNED = (SQLITE_CONSTRAINT |(11<<8))
SQLITE_CONSTRAINT_DATATYPE = (SQLITE_CONSTRAINT |(12<<8))
SQLITE_NOTICE_RECOVER_WAL = (SQLITE_NOTICE | (1<<8))
SQLITE_NOTICE_RECOVER_ROLLBACK = (SQLITE_NOTICE | (2<<8))
SQLITE_NOTICE_RBU = (SQLITE_NOTICE | (3<<8))
SQLITE_WARNING_AUTOINDEX = (SQLITE_WARNING | (1<<8))
SQLITE_AUTH_USER = (SQLITE_AUTH | (1<<8))
SQLITE_OK_LOAD_PERMANENTLY = (SQLITE_OK | (1<<8))
)

// Option can be used to tweak driver parameters.
type Option func(*options)

Expand Down
2 changes: 2 additions & 0 deletions internal/protocol/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ var (

// ErrRequest is returned in case of request failure.
type ErrRequest struct {
// A SQLite-compatible error code.
Code uint64
// A description of the error condition.
Description string
}

Expand Down

0 comments on commit 7f6386c

Please sign in to comment.