summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--errors.zig14
1 files changed, 9 insertions, 5 deletions
diff --git a/errors.zig b/errors.zig
index 95faa62..39240e0 100644
--- a/errors.zig
+++ b/errors.zig
@@ -128,9 +128,13 @@ pub const Error = SQLiteError ||
128 SQLiteExtendedReadOnlyError || 128 SQLiteExtendedReadOnlyError ||
129 SQLiteExtendedConstraintError; 129 SQLiteExtendedConstraintError;
130 130
131fn greaterThanOrEqualsTo(major: u8, minor: u8, patch: u8) bool {
132 return c.SQLITE_VERSION_NUMBER >= @as(u32, major) * 1000000 + @as(u32, minor) * 1000 + @as(u32, patch);
133}
134
131pub fn errorFromResultCode(code: c_int) Error { 135pub fn errorFromResultCode(code: c_int) Error {
132 // These errors are only available since 3.22.0. 136 // These errors are only available since 3.22.0.
133 if (c.SQLITE_VERSION_NUMBER >= 3022000) { 137 if (comptime greaterThanOrEqualsTo(3, 22, 0)) {
134 switch (code) { 138 switch (code) {
135 c.SQLITE_ERROR_MISSING_COLLSEQ => return error.SQLiteErrorMissingCollSeq, 139 c.SQLITE_ERROR_MISSING_COLLSEQ => return error.SQLiteErrorMissingCollSeq,
136 c.SQLITE_ERROR_RETRY => return error.SQLiteErrorRetry, 140 c.SQLITE_ERROR_RETRY => return error.SQLiteErrorRetry,
@@ -141,7 +145,7 @@ pub fn errorFromResultCode(code: c_int) Error {
141 } 145 }
142 146
143 // These errors are only available since 3.25.0. 147 // These errors are only available since 3.25.0.
144 if (c.SQLITE_VERSION_NUMBER >= 3025000) { 148 if (comptime greaterThanOrEqualsTo(3, 25, 0)) {
145 switch (code) { 149 switch (code) {
146 c.SQLITE_ERROR_SNAPSHOT => return error.SQLiteErrorSnapshot, 150 c.SQLITE_ERROR_SNAPSHOT => return error.SQLiteErrorSnapshot,
147 c.SQLITE_LOCKED_VTAB => return error.SQLiteLockedVTab, 151 c.SQLITE_LOCKED_VTAB => return error.SQLiteLockedVTab,
@@ -151,7 +155,7 @@ pub fn errorFromResultCode(code: c_int) Error {
151 } 155 }
152 } 156 }
153 // These errors are only available since 3.31.0. 157 // These errors are only available since 3.31.0.
154 if (c.SQLITE_VERSION_NUMBER >= 3031000) { 158 if (comptime greaterThanOrEqualsTo(3, 31, 0)) {
155 switch (code) { 159 switch (code) {
156 c.SQLITE_CANTOPEN_SYMLINK => return error.SQLiteCantOpenSymlink, 160 c.SQLITE_CANTOPEN_SYMLINK => return error.SQLiteCantOpenSymlink,
157 c.SQLITE_CONSTRAINT_PINNED => return error.SQLiteConstraintPinned, 161 c.SQLITE_CONSTRAINT_PINNED => return error.SQLiteConstraintPinned,
@@ -159,7 +163,7 @@ pub fn errorFromResultCode(code: c_int) Error {
159 } 163 }
160 } 164 }
161 // These errors are only available since 3.32.0. 165 // These errors are only available since 3.32.0.
162 if (c.SQLITE_VERSION_NUMBER >= 3032000) { 166 if (comptime greaterThanOrEqualsTo(3, 32, 0)) {
163 switch (code) { 167 switch (code) {
164 c.SQLITE_IOERR_DATA => return error.SQLiteIOErrData, // See https://sqlite.org/cksumvfs.html 168 c.SQLITE_IOERR_DATA => return error.SQLiteIOErrData, // See https://sqlite.org/cksumvfs.html
165 c.SQLITE_BUSY_TIMEOUT => return error.SQLiteBusyTimeout, 169 c.SQLITE_BUSY_TIMEOUT => return error.SQLiteBusyTimeout,
@@ -168,7 +172,7 @@ pub fn errorFromResultCode(code: c_int) Error {
168 } 172 }
169 } 173 }
170 // These errors are only available since 3.34.0. 174 // These errors are only available since 3.34.0.
171 if (c.SQLITE_VERSION_NUMBER >= 3034000) { 175 if (comptime greaterThanOrEqualsTo(3, 34, 0)) {
172 switch (code) { 176 switch (code) {
173 c.SQLITE_IOERR_CORRUPTFS => return error.SQLiteIOErrCorruptFS, 177 c.SQLITE_IOERR_CORRUPTFS => return error.SQLiteIOErrCorruptFS,
174 else => {}, 178 else => {},