Skip to main content

squire/error/
reason.rs

1use super::{ErrorCategory, ErrorCode};
2
3/// Extended SQLite result codes that provide more specific information about errors.
4#[derive(PartialEq, Eq, Copy, Clone, Debug)]
5#[non_exhaustive]
6pub enum ErrorReason {
7    /// Specific reasons for an [`ErrorCategory::Aborted`].
8    Aborted(AbortError),
9
10    /// Specific reason for an [`ErrorCategory::Authorization`].
11    Authorization(AuthorizationError),
12
13    /// Specific reason for an [`ErrorCategory::Busy`].
14    Busy(BusyError),
15
16    /// Specific reason for an [`ErrorCategory::CantOpen`].
17    CantOpen(CantOpenError),
18
19    /// Specific reason for an [`ErrorCategory::Constraint`].
20    Constraint(ConstraintError),
21
22    /// Specific reason for an [`ErrorCategory::Corrupt`].
23    Corrupt(CorruptError),
24
25    /// Specific reason for an [`ErrorCategory::Unknown`].
26    Error(GeneralError),
27
28    /// Specific reason for an [`ErrorCategory::Io`].
29    Io(IoError),
30
31    /// Specific reason for an [`ErrorCategory::Locked`].
32    Locked(LockedError),
33
34    /// Specific reason for an [`ErrorCategory::ReadOnly`].
35    ReadOnly(ReadOnlyError),
36
37    /// Specific reason for an [`ErrorCategory::Fetch`].
38    ///
39    /// (This [error code](ErrorReason) is defined by Squire; not SQLite.
40    /// No SQLite [result codes][] correspond to `ErrorReason::Fetch`.)
41    ///
42    /// [result codes]: https://sqlite.org/rescode.html
43    Fetch(FetchError),
44
45    /// Specific reason for an [`ErrorCategory::Parameter`].
46    ///
47    /// (This [error code](ErrorReason) is defined by Squire; not SQLite.
48    /// No SQLite [result codes][] correspond to `ErrorReason::Parameter`.)
49    ///
50    /// [result codes]: https://sqlite.org/rescode.html
51    Parameter(ParameterError),
52
53    /// Specific reason for an [`ErrorCategory::Row`].
54    ///
55    /// (This [error code](ErrorReason) is defined by Squire; not SQLite.
56    /// No SQLite [result codes][] correspond to `ErrorReason::Row`.)
57    ///
58    /// [result codes]: https://sqlite.org/rescode.html
59    Row(RowError),
60}
61
62impl ErrorReason {
63    /// Returns the primary error category for this extended error code.
64    pub const fn category(self) -> ErrorCategory {
65        match self {
66            ErrorReason::Aborted(_) => ErrorCategory::Aborted,
67            ErrorReason::Authorization(_) => ErrorCategory::Authorization,
68            ErrorReason::Busy(_) => ErrorCategory::Busy,
69            ErrorReason::CantOpen(_) => ErrorCategory::CantOpen,
70            ErrorReason::Constraint(_) => ErrorCategory::Constraint,
71            ErrorReason::Corrupt(_) => ErrorCategory::Corrupt,
72            ErrorReason::Error(_) => ErrorCategory::Unknown,
73            ErrorReason::Io(_) => ErrorCategory::Io,
74            ErrorReason::Locked(_) => ErrorCategory::Locked,
75            ErrorReason::ReadOnly(_) => ErrorCategory::ReadOnly,
76
77            ErrorReason::Fetch(_) => ErrorCategory::Fetch,
78            ErrorReason::Parameter(_) => ErrorCategory::Parameter,
79            ErrorReason::Row(_) => ErrorCategory::Parameter,
80        }
81    }
82
83    /// Returns the underlying [`ErrorCode`].
84    pub const fn code(self) -> ErrorCode {
85        let code = match self {
86            Self::Aborted(err) => err as i32,
87            Self::Authorization(err) => err as i32,
88            Self::Busy(err) => err as i32,
89            Self::CantOpen(err) => err as i32,
90            Self::Constraint(err) => err as i32,
91            Self::Corrupt(err) => err as i32,
92            Self::Error(err) => err as i32,
93            Self::Io(err) => err as i32,
94            Self::Locked(err) => err as i32,
95            Self::ReadOnly(err) => err as i32,
96
97            Self::Fetch(err) => err as i32,
98            Self::Parameter(err) => err as i32,
99            Self::Row(err) => err as i32,
100        };
101
102        unsafe { ErrorCode::new_unchecked(code) }
103    }
104
105    /// Find the [`ErrorReason`] for an [`ErrorCode`].
106    pub const fn from_code(code: ErrorCode) -> Option<Self> {
107        Self::from_raw_code(code.raw())
108    }
109
110    /// Find the [`ErrorReason`] for a SQLite [result code][].
111    ///
112    /// [result code]: https://sqlite.org/rescode.html
113    pub const fn from_raw_code(code: i32) -> Option<Self> {
114        #[allow(deprecated)]
115        match code {
116            // Abort errors
117            sqlite::SQLITE_ABORT_ROLLBACK => Some(Self::Aborted(AbortError::Rollback)),
118
119            // Authorization errors
120            sqlite::SQLITE_AUTH_USER => Some(Self::Authorization(AuthorizationError::User)),
121
122            // Busy errors
123            sqlite::SQLITE_BUSY_RECOVERY => Some(Self::Busy(BusyError::Recovery)),
124            sqlite::SQLITE_BUSY_SNAPSHOT => Some(Self::Busy(BusyError::Snapshot)),
125            sqlite::SQLITE_BUSY_TIMEOUT => Some(Self::Busy(BusyError::Timeout)),
126
127            // CantOpen errors
128            sqlite::SQLITE_CANTOPEN_FULLPATH => Some(Self::CantOpen(CantOpenError::FullPath)),
129            sqlite::SQLITE_CANTOPEN_ISDIR => Some(Self::CantOpen(CantOpenError::IsDir)),
130            sqlite::SQLITE_CANTOPEN_NOTEMPDIR => Some(Self::CantOpen(CantOpenError::NoTempDir)),
131            sqlite::SQLITE_CANTOPEN_CONVPATH => Some(Self::CantOpen(CantOpenError::ConvPath)),
132            sqlite::SQLITE_CANTOPEN_DIRTYWAL => Some(Self::CantOpen(CantOpenError::DirtyWal)),
133            sqlite::SQLITE_CANTOPEN_SYMLINK => Some(Self::CantOpen(CantOpenError::Symlink)),
134
135            // Constraint errors
136            sqlite::SQLITE_CONSTRAINT_CHECK => Some(Self::Constraint(ConstraintError::Check)),
137            sqlite::SQLITE_CONSTRAINT_COMMITHOOK => {
138                Some(Self::Constraint(ConstraintError::CommitHook))
139            }
140            sqlite::SQLITE_CONSTRAINT_DATATYPE => Some(Self::Constraint(ConstraintError::DataType)),
141            sqlite::SQLITE_CONSTRAINT_FOREIGNKEY => {
142                Some(Self::Constraint(ConstraintError::ForeignKey))
143            }
144            sqlite::SQLITE_CONSTRAINT_FUNCTION => Some(Self::Constraint(ConstraintError::Function)),
145            sqlite::SQLITE_CONSTRAINT_NOTNULL => Some(Self::Constraint(ConstraintError::NotNull)),
146            sqlite::SQLITE_CONSTRAINT_PINNED => Some(Self::Constraint(ConstraintError::Pinned)),
147            sqlite::SQLITE_CONSTRAINT_PRIMARYKEY => {
148                Some(Self::Constraint(ConstraintError::PrimaryKey))
149            }
150            sqlite::SQLITE_CONSTRAINT_ROWID => Some(Self::Constraint(ConstraintError::RowId)),
151            sqlite::SQLITE_CONSTRAINT_TRIGGER => Some(Self::Constraint(ConstraintError::Trigger)),
152            sqlite::SQLITE_CONSTRAINT_UNIQUE => Some(Self::Constraint(ConstraintError::Unique)),
153            sqlite::SQLITE_CONSTRAINT_VTAB => Some(Self::Constraint(ConstraintError::VTab)),
154
155            // Corrupt errors
156            sqlite::SQLITE_CORRUPT_INDEX => Some(Self::Corrupt(CorruptError::Index)),
157            sqlite::SQLITE_CORRUPT_SEQUENCE => Some(Self::Corrupt(CorruptError::Sequence)),
158            sqlite::SQLITE_CORRUPT_VTAB => Some(Self::Corrupt(CorruptError::VTab)),
159
160            // General errors
161            sqlite::SQLITE_ERROR_MISSING_COLLSEQ => Some(Self::Error(GeneralError::MissingCollSeq)),
162            sqlite::SQLITE_ERROR_RETRY => Some(Self::Error(GeneralError::Retry)),
163            sqlite::SQLITE_ERROR_SNAPSHOT => Some(Self::Error(GeneralError::Snapshot)),
164
165            // IO errors
166            sqlite::SQLITE_IOERR_READ => Some(Self::Io(IoError::Read)),
167            sqlite::SQLITE_IOERR_WRITE => Some(Self::Io(IoError::Write)),
168            sqlite::SQLITE_IOERR_FSYNC => Some(Self::Io(IoError::FSync)),
169            sqlite::SQLITE_IOERR_FSTAT => Some(Self::Io(IoError::FStat)),
170            sqlite::SQLITE_IOERR_TRUNCATE => Some(Self::Io(IoError::Truncate)),
171            sqlite::SQLITE_IOERR_UNLOCK => Some(Self::Io(IoError::Unlock)),
172            sqlite::SQLITE_IOERR_RDLOCK => Some(Self::Io(IoError::ReadLock)),
173            sqlite::SQLITE_IOERR_DELETE => Some(Self::Io(IoError::Delete)),
174            sqlite::SQLITE_IOERR_BLOCKED => Some(Self::Io(IoError::Blocked)),
175            sqlite::SQLITE_IOERR_NOMEM => Some(Self::Io(IoError::NoMem)),
176            sqlite::SQLITE_IOERR_ACCESS => Some(Self::Io(IoError::Access)),
177            sqlite::SQLITE_IOERR_CHECKRESERVEDLOCK => Some(Self::Io(IoError::CheckReservedLock)),
178            sqlite::SQLITE_IOERR_LOCK => Some(Self::Io(IoError::Lock)),
179            sqlite::SQLITE_IOERR_CLOSE => Some(Self::Io(IoError::Close)),
180            sqlite::SQLITE_IOERR_DIR_CLOSE => Some(Self::Io(IoError::DirClose)),
181            sqlite::SQLITE_IOERR_SHMOPEN => Some(Self::Io(IoError::ShmOpen)),
182            sqlite::SQLITE_IOERR_SHMSIZE => Some(Self::Io(IoError::ShmSize)),
183            sqlite::SQLITE_IOERR_SHMLOCK => Some(Self::Io(IoError::ShmLock)),
184            sqlite::SQLITE_IOERR_SHMMAP => Some(Self::Io(IoError::ShmMap)),
185            sqlite::SQLITE_IOERR_SEEK => Some(Self::Io(IoError::Seek)),
186            sqlite::SQLITE_IOERR_DELETE_NOENT => Some(Self::Io(IoError::DeleteNoEnt)),
187            sqlite::SQLITE_IOERR_MMAP => Some(Self::Io(IoError::MMap)),
188            sqlite::SQLITE_IOERR_GETTEMPPATH => Some(Self::Io(IoError::GetTempPath)),
189            sqlite::SQLITE_IOERR_CONVPATH => Some(Self::Io(IoError::ConvPath)),
190            sqlite::SQLITE_IOERR_VNODE => Some(Self::Io(IoError::VNode)),
191            sqlite::SQLITE_IOERR_AUTH => Some(Self::Io(IoError::Auth)),
192            sqlite::SQLITE_IOERR_BEGIN_ATOMIC => Some(Self::Io(IoError::BeginAtomic)),
193            sqlite::SQLITE_IOERR_COMMIT_ATOMIC => Some(Self::Io(IoError::CommitAtomic)),
194            sqlite::SQLITE_IOERR_ROLLBACK_ATOMIC => Some(Self::Io(IoError::RollbackAtomic)),
195            sqlite::SQLITE_IOERR_DATA => Some(Self::Io(IoError::Data)),
196            sqlite::SQLITE_IOERR_CORRUPTFS => Some(Self::Io(IoError::CorruptFS)),
197            sqlite::SQLITE_IOERR_SHORT_READ => Some(Self::Io(IoError::ShortRead)),
198            sqlite::SQLITE_IOERR_DIR_FSYNC => Some(Self::Io(IoError::DirFSync)),
199
200            // Locked errors
201            sqlite::SQLITE_LOCKED_SHAREDCACHE => Some(Self::Locked(LockedError::SharedCache)),
202            sqlite::SQLITE_LOCKED_VTAB => Some(Self::Locked(LockedError::VTab)),
203
204            // ReadOnly errors
205            sqlite::SQLITE_READONLY_RECOVERY => Some(Self::ReadOnly(ReadOnlyError::Recovery)),
206            sqlite::SQLITE_READONLY_CANTLOCK => Some(Self::ReadOnly(ReadOnlyError::CantLock)),
207            sqlite::SQLITE_READONLY_ROLLBACK => Some(Self::ReadOnly(ReadOnlyError::Rollback)),
208            sqlite::SQLITE_READONLY_DBMOVED => Some(Self::ReadOnly(ReadOnlyError::DbMoved)),
209            sqlite::SQLITE_READONLY_CANTINIT => Some(Self::ReadOnly(ReadOnlyError::CantInit)),
210            sqlite::SQLITE_READONLY_DIRECTORY => Some(Self::ReadOnly(ReadOnlyError::Directory)),
211
212            // Squire errors
213            super::code::SQUIRE_ERROR_FETCH_PARSE => Some(Self::Fetch(FetchError::Parse)),
214            super::code::SQUIRE_ERROR_FETCH_RANGE => Some(Self::Fetch(FetchError::Range)),
215            super::code::SQUIRE_ERROR_PARAMETER_BIND => Some(Self::Parameter(ParameterError::Bind)),
216            super::code::SQUIRE_ERROR_PARAMETER_RANGE => {
217                Some(Self::Parameter(ParameterError::Range))
218            }
219            super::code::SQUIRE_ERROR_PARAMETER_RESOLVE => {
220                Some(Self::Parameter(ParameterError::Resolve))
221            }
222            super::code::SQUIRE_ERROR_PARAMETER_INVALID_INDEX => {
223                Some(Self::Parameter(ParameterError::InvalidIndex))
224            }
225            super::code::SQUIRE_ERROR_ROW_NOT_RETURNED => Some(Self::Row(RowError::NotReturned)),
226
227            _ => None,
228        }
229    }
230}
231
232/// Specific reasons for an [`ErrorCategory::Aborted`].
233#[derive(PartialEq, Eq, Copy, Clone, Debug)]
234#[repr(i32)]
235pub enum AbortError {
236    /// A SQL statement aborted because the transaction that was active when
237    /// the SQL statement first started was rolled back.
238    #[doc(alias = "SQLITE_ABORT_ROLLBACK")]
239    Rollback = sqlite::SQLITE_ABORT_ROLLBACK,
240}
241
242/// Specific reasons for an [`ErrorCategory::Aborted`].
243#[derive(PartialEq, Eq, Copy, Clone, Debug)]
244#[repr(i32)]
245pub enum AuthorizationError {
246    /// An operation was attempted on a database for which the logged in user
247    /// lacks sufficient authorization.
248    #[doc(alias = "SQLITE_AUTH_USER")]
249    User = sqlite::SQLITE_AUTH_USER,
250}
251
252/// Specific reason for an [`ErrorCategory::Busy`].
253#[derive(PartialEq, Eq, Copy, Clone, Debug)]
254#[repr(i32)]
255pub enum BusyError {
256    /// An operation could not continue because another process is busy
257    /// recovering a WAL mode database file following a crash.
258    #[doc(alias = "SQLITE_BUSY_RECOVERY")]
259    Recovery = sqlite::SQLITE_BUSY_RECOVERY,
260
261    /// A database connection tries to promote a read transaction into a write
262    /// transaction but finds that another database connection has already
263    /// written to the database.
264    #[doc(alias = "SQLITE_BUSY_SNAPSHOT")]
265    Snapshot = sqlite::SQLITE_BUSY_SNAPSHOT,
266
267    /// A blocking Posix advisory file lock request in the VFS layer failed
268    /// due to a timeout.
269    #[doc(alias = "SQLITE_BUSY_TIMEOUT")]
270    Timeout = sqlite::SQLITE_BUSY_TIMEOUT,
271}
272
273/// Specific reason for an [`ErrorCategory::CantOpen`].
274#[derive(PartialEq, Eq, Copy, Clone, Debug)]
275#[repr(i32)]
276pub enum CantOpenError {
277    /// The operating system was unable to convert the filename into a full pathname.
278    #[doc(alias = "SQLITE_CANTOPEN_FULLPATH")]
279    FullPath = sqlite::SQLITE_CANTOPEN_FULLPATH,
280
281    /// A file open operation failed because the file is really a directory.
282    #[doc(alias = "SQLITE_CANTOPEN_ISDIR")]
283    IsDir = sqlite::SQLITE_CANTOPEN_ISDIR,
284
285    /// No longer used.
286    #[doc(alias = "SQLITE_CANTOPEN_NOTEMPDIR")]
287    #[deprecated]
288    NoTempDir = sqlite::SQLITE_CANTOPEN_NOTEMPDIR,
289
290    /// Used only by Cygwin VFS indicating that the cygwin_conv_path() system
291    /// call failed while trying to open a file.
292    #[doc(alias = "SQLITE_CANTOPEN_CONVPATH")]
293    ConvPath = sqlite::SQLITE_CANTOPEN_CONVPATH,
294
295    /// Not used at this time.
296    #[doc(alias = "SQLITE_CANTOPEN_DIRTYWAL")]
297    #[deprecated]
298    DirtyWal = sqlite::SQLITE_CANTOPEN_DIRTYWAL,
299
300    /// The database file is a symbolic link and SQLITE_OPEN_NOFOLLOW flag was used.
301    #[doc(alias = "SQLITE_CANTOPEN_SYMLINK")]
302    Symlink = sqlite::SQLITE_CANTOPEN_SYMLINK,
303}
304
305/// Specific reason for an [`ErrorCategory::Constraint`].
306#[derive(PartialEq, Eq, Copy, Clone, Debug)]
307#[repr(i32)]
308pub enum ConstraintError {
309    /// A CHECK constraint failed.
310    #[doc(alias = "SQLITE_CONSTRAINT_CHECK")]
311    Check = sqlite::SQLITE_CONSTRAINT_CHECK,
312
313    /// A commit hook callback returned non-zero that thus caused the SQL
314    /// statement to be rolled back.
315    #[doc(alias = "SQLITE_CONSTRAINT_COMMITHOOK")]
316    CommitHook = sqlite::SQLITE_CONSTRAINT_COMMITHOOK,
317
318    /// An insert or update attempted to store a value inconsistent with the
319    /// column's declared type in a table defined as STRICT.
320    #[doc(alias = "SQLITE_CONSTRAINT_DATATYPE")]
321    DataType = sqlite::SQLITE_CONSTRAINT_DATATYPE,
322
323    /// A foreign key constraint failed.
324    #[doc(alias = "SQLITE_CONSTRAINT_FOREIGNKEY")]
325    ForeignKey = sqlite::SQLITE_CONSTRAINT_FOREIGNKEY,
326
327    /// Available for use by extension functions.
328    #[doc(alias = "SQLITE_CONSTRAINT_FUNCTION")]
329    Function = sqlite::SQLITE_CONSTRAINT_FUNCTION,
330
331    /// A NOT NULL constraint failed.
332    #[doc(alias = "SQLITE_CONSTRAINT_NOTNULL")]
333    NotNull = sqlite::SQLITE_CONSTRAINT_NOTNULL,
334
335    /// An UPDATE trigger attempted to delete the row that was being updated
336    /// in the middle of the update.
337    #[doc(alias = "SQLITE_CONSTRAINT_PINNED")]
338    Pinned = sqlite::SQLITE_CONSTRAINT_PINNED,
339
340    /// A PRIMARY KEY constraint failed.
341    #[doc(alias = "SQLITE_CONSTRAINT_PRIMARYKEY")]
342    PrimaryKey = sqlite::SQLITE_CONSTRAINT_PRIMARYKEY,
343
344    /// A rowid is not unique.
345    #[doc(alias = "SQLITE_CONSTRAINT_ROWID")]
346    RowId = sqlite::SQLITE_CONSTRAINT_ROWID,
347
348    /// A RAISE function within a trigger fired, causing the SQL statement to abort.
349    #[doc(alias = "SQLITE_CONSTRAINT_TRIGGER")]
350    Trigger = sqlite::SQLITE_CONSTRAINT_TRIGGER,
351
352    /// A UNIQUE constraint failed.
353    #[doc(alias = "SQLITE_CONSTRAINT_UNIQUE")]
354    Unique = sqlite::SQLITE_CONSTRAINT_UNIQUE,
355
356    /// Available for use by application-defined virtual tables.
357    #[doc(alias = "SQLITE_CONSTRAINT_VTAB")]
358    VTab = sqlite::SQLITE_CONSTRAINT_VTAB,
359}
360
361/// Specific reason for an [`ErrorCategory::Corrupt`].
362#[derive(PartialEq, Eq, Copy, Clone, Debug)]
363#[repr(i32)]
364pub enum CorruptError {
365    /// SQLite detected an entry is or was missing from an index.
366    #[doc(alias = "SQLITE_CORRUPT_INDEX")]
367    Index = sqlite::SQLITE_CORRUPT_INDEX,
368
369    /// The schema of the sqlite_sequence table is corrupt.
370    #[doc(alias = "SQLITE_CORRUPT_SEQUENCE")]
371    Sequence = sqlite::SQLITE_CORRUPT_SEQUENCE,
372
373    /// Used by virtual tables. A virtual table might return this to indicate
374    /// that content in the virtual table is corrupt.
375    #[doc(alias = "SQLITE_CORRUPT_VTAB")]
376    VTab = sqlite::SQLITE_CORRUPT_VTAB,
377}
378
379/// Specific reason for an [`ErrorCategory::Unknown`].
380#[derive(PartialEq, Eq, Copy, Clone, Debug)]
381#[repr(i32)]
382pub enum GeneralError {
383    /// A SQL statement could not be prepared because a collating sequence
384    /// named in that SQL statement could not be located.
385    #[doc(alias = "SQLITE_ERROR_MISSING_COLLSEQ")]
386    MissingCollSeq = sqlite::SQLITE_ERROR_MISSING_COLLSEQ,
387
388    /// Used internally to provoke sqlite3_prepare_v2() to try again to prepare
389    /// a statement that failed with an error on the previous attempt.
390    #[doc(alias = "SQLITE_ERROR_RETRY")]
391    Retry = sqlite::SQLITE_ERROR_RETRY,
392
393    /// Returned when attempting to start a read transaction on an historical
394    /// version of the database by using sqlite3_snapshot_open() interface.
395    #[doc(alias = "SQLITE_ERROR_SNAPSHOT")]
396    Snapshot = sqlite::SQLITE_ERROR_SNAPSHOT,
397}
398
399/// Specific reason for an [`ErrorCategory::Io`].
400#[derive(PartialEq, Eq, Copy, Clone, Debug)]
401#[repr(i32)]
402pub enum IoError {
403    /// I/O error while trying to read from a file on disk.
404    #[doc(alias = "SQLITE_IOERR_READ")]
405    Read = sqlite::SQLITE_IOERR_READ,
406
407    /// I/O error while trying to write into a file on disk.
408    #[doc(alias = "SQLITE_IOERR_WRITE")]
409    Write = sqlite::SQLITE_IOERR_WRITE,
410
411    /// I/O error while trying to flush previously written content out of OS
412    /// and/or disk-control buffers and into persistent storage.
413    #[doc(alias = "SQLITE_IOERR_FSYNC")]
414    FSync = sqlite::SQLITE_IOERR_FSYNC,
415
416    /// I/O error while trying to invoke fstat() on a file to determine
417    /// information such as the file size or access permissions.
418    #[doc(alias = "SQLITE_IOERR_FSTAT")]
419    FStat = sqlite::SQLITE_IOERR_FSTAT,
420
421    /// I/O error while trying to truncate a file to a smaller size.
422    #[doc(alias = "SQLITE_IOERR_TRUNCATE")]
423    Truncate = sqlite::SQLITE_IOERR_TRUNCATE,
424
425    /// I/O error within the xUnlock method on the sqlite3_io_methods object.
426    #[doc(alias = "SQLITE_IOERR_UNLOCK")]
427    Unlock = sqlite::SQLITE_IOERR_UNLOCK,
428
429    /// I/O error within the xLock method while trying to obtain a read lock.
430    #[doc(alias = "SQLITE_IOERR_RDLOCK")]
431    ReadLock = sqlite::SQLITE_IOERR_RDLOCK,
432
433    /// I/O error within the xDelete method on the sqlite3_vfs object.
434    #[doc(alias = "SQLITE_IOERR_DELETE")]
435    Delete = sqlite::SQLITE_IOERR_DELETE,
436
437    /// No longer used.
438    #[doc(alias = "SQLITE_IOERR_BLOCKED")]
439    #[deprecated]
440    Blocked = sqlite::SQLITE_IOERR_BLOCKED,
441
442    /// Sometimes returned by the VFS layer to indicate that an operation
443    /// could not be completed due to the inability to allocate sufficient memory.
444    #[doc(alias = "SQLITE_IOERR_NOMEM")]
445    NoMem = sqlite::SQLITE_IOERR_NOMEM,
446
447    /// I/O error within the xAccess method on the sqlite3_vfs object.
448    #[doc(alias = "SQLITE_IOERR_ACCESS")]
449    Access = sqlite::SQLITE_IOERR_ACCESS,
450
451    /// I/O error within the xCheckReservedLock method on the sqlite3_io_methods object.
452    #[doc(alias = "SQLITE_IOERR_CHECKRESERVEDLOCK")]
453    CheckReservedLock = sqlite::SQLITE_IOERR_CHECKRESERVEDLOCK,
454
455    /// I/O error in the advisory file locking logic.
456    #[doc(alias = "SQLITE_IOERR_LOCK")]
457    Lock = sqlite::SQLITE_IOERR_LOCK,
458
459    /// I/O error within the xClose method on the sqlite3_io_methods object.
460    #[doc(alias = "SQLITE_IOERR_CLOSE")]
461    Close = sqlite::SQLITE_IOERR_CLOSE,
462
463    /// No longer used.
464    #[doc(alias = "SQLITE_IOERR_DIR_CLOSE")]
465    #[deprecated]
466    DirClose = sqlite::SQLITE_IOERR_DIR_CLOSE,
467
468    /// I/O error within the xShmMap method while trying to open a new shared
469    /// memory segment.
470    #[doc(alias = "SQLITE_IOERR_SHMOPEN")]
471    ShmOpen = sqlite::SQLITE_IOERR_SHMOPEN,
472
473    /// I/O error within the xShmMap method while trying to enlarge a "shm"
474    /// file as part of WAL mode transaction processing.
475    #[doc(alias = "SQLITE_IOERR_SHMSIZE")]
476    ShmSize = sqlite::SQLITE_IOERR_SHMSIZE,
477
478    /// No longer used.
479    #[doc(alias = "SQLITE_IOERR_SHMLOCK")]
480    #[deprecated]
481    ShmLock = sqlite::SQLITE_IOERR_SHMLOCK,
482
483    /// I/O error within the xShmMap method while trying to map a shared memory
484    /// segment into the process address space.
485    #[doc(alias = "SQLITE_IOERR_SHMMAP")]
486    ShmMap = sqlite::SQLITE_IOERR_SHMMAP,
487
488    /// I/O error within the xRead or xWrite methods while trying to seek a
489    /// file descriptor to the beginning point of the file.
490    #[doc(alias = "SQLITE_IOERR_SEEK")]
491    Seek = sqlite::SQLITE_IOERR_SEEK,
492
493    /// I/O error indicating that the xDelete method failed because the file
494    /// being deleted does not exist.
495    #[doc(alias = "SQLITE_IOERR_DELETE_NOENT")]
496    DeleteNoEnt = sqlite::SQLITE_IOERR_DELETE_NOENT,
497
498    /// I/O error within the xFetch or xUnfetch methods while trying to map
499    /// or unmap part of the database file into the process address space.
500    #[doc(alias = "SQLITE_IOERR_MMAP")]
501    MMap = sqlite::SQLITE_IOERR_MMAP,
502
503    /// The VFS is unable to determine a suitable directory in which to place
504    /// temporary files.
505    #[doc(alias = "SQLITE_IOERR_GETTEMPPATH")]
506    GetTempPath = sqlite::SQLITE_IOERR_GETTEMPPATH,
507
508    /// Used only by Cygwin VFS indicating that the cygwin_conv_path() system
509    /// call failed.
510    #[doc(alias = "SQLITE_IOERR_CONVPATH")]
511    ConvPath = sqlite::SQLITE_IOERR_CONVPATH,
512
513    /// Code reserved for use by extensions.
514    #[doc(alias = "SQLITE_IOERR_VNODE")]
515    VNode = sqlite::SQLITE_IOERR_VNODE,
516
517    /// Code reserved for use by extensions.
518    #[doc(alias = "SQLITE_IOERR_AUTH")]
519    Auth = sqlite::SQLITE_IOERR_AUTH,
520
521    /// The underlying operating system reported an error on the
522    /// SQLITE_FCNTL_BEGIN_ATOMIC_WRITE file-control.
523    #[doc(alias = "SQLITE_IOERR_BEGIN_ATOMIC")]
524    BeginAtomic = sqlite::SQLITE_IOERR_BEGIN_ATOMIC,
525
526    /// The underlying operating system reported an error on the
527    /// SQLITE_FCNTL_COMMIT_ATOMIC_WRITE file-control.
528    #[doc(alias = "SQLITE_IOERR_COMMIT_ATOMIC")]
529    CommitAtomic = sqlite::SQLITE_IOERR_COMMIT_ATOMIC,
530
531    /// The underlying operating system reported an error on the
532    /// SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE file-control.
533    #[doc(alias = "SQLITE_IOERR_ROLLBACK_ATOMIC")]
534    RollbackAtomic = sqlite::SQLITE_IOERR_ROLLBACK_ATOMIC,
535
536    /// Used only by the checksum VFS shim to indicate that the checksum on
537    /// a page of the database file is incorrect.
538    #[doc(alias = "SQLITE_IOERR_DATA")]
539    Data = sqlite::SQLITE_IOERR_DATA,
540
541    /// A seek or read failure was due to the request not falling within the
542    /// file's boundary rather than an ordinary device failure.
543    #[doc(alias = "SQLITE_IOERR_CORRUPTFS")]
544    CorruptFS = sqlite::SQLITE_IOERR_CORRUPTFS,
545
546    /// A read attempt in the VFS layer was unable to obtain as many bytes
547    /// as was requested.
548    #[doc(alias = "SQLITE_IOERR_SHORT_READ")]
549    ShortRead = sqlite::SQLITE_IOERR_SHORT_READ,
550
551    /// I/O error while trying to invoke fsync() on a directory.
552    #[doc(alias = "SQLITE_IOERR_DIR_FSYNC")]
553    DirFSync = sqlite::SQLITE_IOERR_DIR_FSYNC,
554}
555
556/// Specific reason for an [`ErrorCategory::Locked`].
557#[derive(PartialEq, Eq, Copy, Clone, Debug)]
558#[repr(i32)]
559pub enum LockedError {
560    /// Access to a SQLite data record is blocked by another database connection
561    /// that is using the same record in shared cache mode.
562    #[doc(alias = "SQLITE_LOCKED_SHAREDCACHE")]
563    SharedCache = sqlite::SQLITE_LOCKED_SHAREDCACHE,
564
565    /// Not used by the SQLite core, but available for use by extensions.
566    #[doc(alias = "SQLITE_LOCKED_VTAB")]
567    VTab = sqlite::SQLITE_LOCKED_VTAB,
568}
569
570/// Specific reason for an [`ErrorCategory::ReadOnly`].
571#[derive(PartialEq, Eq, Copy, Clone, Debug)]
572#[repr(i32)]
573pub enum ReadOnlyError {
574    /// A WAL mode database cannot be opened because the database file needs
575    /// to be recovered and recovery requires write access but only read access
576    /// is available.
577    #[doc(alias = "SQLITE_READONLY_RECOVERY")]
578    Recovery = sqlite::SQLITE_READONLY_RECOVERY,
579
580    /// SQLite is unable to obtain a read lock on a WAL mode database because
581    /// the shared-memory file associated with that database is read-only.
582    #[doc(alias = "SQLITE_READONLY_CANTLOCK")]
583    CantLock = sqlite::SQLITE_READONLY_CANTLOCK,
584
585    /// A database cannot be opened because it has a hot journal that needs to
586    /// be rolled back but cannot because the database is readonly.
587    #[doc(alias = "SQLITE_READONLY_ROLLBACK")]
588    Rollback = sqlite::SQLITE_READONLY_ROLLBACK,
589
590    /// A database cannot be modified because the database file has been moved
591    /// since it was opened.
592    #[doc(alias = "SQLITE_READONLY_DBMOVED")]
593    DbMoved = sqlite::SQLITE_READONLY_DBMOVED,
594
595    /// The shared memory region used by WAL mode exists but its content is
596    /// unreliable and unusable by the current process since the current process
597    /// does not have write permission on the shared memory region.
598    #[doc(alias = "SQLITE_READONLY_CANTINIT")]
599    CantInit = sqlite::SQLITE_READONLY_CANTINIT,
600
601    /// The database is read-only because process does not have permission to
602    /// create a journal file in the same directory as the database.
603    #[doc(alias = "SQLITE_READONLY_DIRECTORY")]
604    Directory = sqlite::SQLITE_READONLY_DIRECTORY,
605}
606
607/// An error reading a SQLite column value into its Rust type.
608///
609/// (This [error category](ErrorCategory) is defined by Squire; not SQLite.
610/// No SQLite [result codes][] correspond to `FetchError`.)
611///
612/// [result codes]: https://sqlite.org/rescode.html
613#[derive(PartialEq, Eq, Copy, Clone, Debug)]
614#[repr(i32)]
615pub enum FetchError {
616    /// [Fetching](crate::Fetch) a column value failed; the value stored in
617    /// SQLite cannot be parsed into the desired type.
618    Parse = super::code::SQUIRE_ERROR_FETCH_PARSE,
619
620    /// [Fetching](crate::Fetch) a column value failed; the value stored in
621    /// SQLite is out of the range the destination Rust type can represent
622    /// (e.g., fetching into a `u8` a value > 255).
623    Range = super::code::SQUIRE_ERROR_FETCH_RANGE,
624}
625
626/// An error passing prepared statement parameter(s) to SQLite.
627///
628/// (This [error category](ErrorCategory) is defined by Squire; not SQLite.
629/// No SQLite [result codes][] correspond to `ParameterError`.)
630///
631/// [result codes]: https://sqlite.org/rescode.html
632#[derive(PartialEq, Eq, Copy, Clone, Debug)]
633#[repr(i32)]
634pub enum ParameterError {
635    /// [Binding](crate::Bind) a parameter failed;
636    /// [`into_bind_value`](crate::Bind::into_bind_value()) returned an error.
637    Bind = super::code::SQUIRE_ERROR_PARAMETER_BIND,
638
639    /// [Binding](crate::Bind) a parameter failed; the value is out of range for
640    /// the SQLite data type it would be bound as. (For example, trying to bind
641    /// a `u64` value that doesn't fit in an `i64`.)
642    Range = super::code::SQUIRE_ERROR_PARAMETER_RANGE,
643
644    /// [Resolving](crate::Parameters) parameter index(es) failed;
645    /// [`resolve`](crate::Parameters::resolve()) returned an error.
646    Resolve = super::code::SQUIRE_ERROR_PARAMETER_RESOLVE,
647
648    /// Creating a [`BindIndex`](crate::BindIndex) failed because the input
649    /// value was zero or negative.
650    InvalidIndex = super::code::SQUIRE_ERROR_PARAMETER_INVALID_INDEX,
651}
652
653/// An error retrieving a row from SQLite.
654///
655/// (This [error category](ErrorCategory) is defined by Squire; not SQLite.
656/// No SQLite [result codes][] correspond to `RowError`.)
657///
658/// [result codes]: https://sqlite.org/rescode.html
659#[derive(PartialEq, Eq, Copy, Clone, Debug)]
660#[repr(i32)]
661pub enum RowError {
662    /// The query didn't return a row.
663    NotReturned = super::code::SQUIRE_ERROR_ROW_NOT_RETURNED,
664}