1package sqlite3
2
3import (
4 "strconv"
5
6 "github.com/ncruces/go-sqlite3/internal/util"
7)
8
9const (
10 _OK = 0 /* Successful result */
11 _ROW = 100 /* sqlite3_step() has another row ready */
12 _DONE = 101 /* sqlite3_step() has finished executing */
13
14 _MAX_NAME = 1e6 // Self-imposed limit for most NUL terminated strings.
15 _MAX_LENGTH = 1e9
16 _MAX_SQL_LENGTH = 1e9
17
18 ptrlen = util.PtrLen
19 intlen = util.IntLen
20)
21
22type (
23 stk_t = util.Stk_t
24 ptr_t = util.Ptr_t
25 res_t = util.Res_t
26)
27
28// ErrorCode is a result code that [Error.Code] might return.
29//
30// https://sqlite.org/rescode.html
31type ErrorCode uint8
32
33const (
34 ERROR ErrorCode = 1 /* Generic error */
35 INTERNAL ErrorCode = 2 /* Internal logic error in SQLite */
36 PERM ErrorCode = 3 /* Access permission denied */
37 ABORT ErrorCode = 4 /* Callback routine requested an abort */
38 BUSY ErrorCode = 5 /* The database file is locked */
39 LOCKED ErrorCode = 6 /* A table in the database is locked */
40 NOMEM ErrorCode = 7 /* A malloc() failed */
41 READONLY ErrorCode = 8 /* Attempt to write a readonly database */
42 INTERRUPT ErrorCode = 9 /* Operation terminated by sqlite3_interrupt() */
43 IOERR ErrorCode = 10 /* Some kind of disk I/O error occurred */
44 CORRUPT ErrorCode = 11 /* The database disk image is malformed */
45 NOTFOUND ErrorCode = 12 /* Unknown opcode in sqlite3_file_control() */
46 FULL ErrorCode = 13 /* Insertion failed because database is full */
47 CANTOPEN ErrorCode = 14 /* Unable to open the database file */
48 PROTOCOL ErrorCode = 15 /* Database lock protocol error */
49 EMPTY ErrorCode = 16 /* Internal use only */
50 SCHEMA ErrorCode = 17 /* The database schema changed */
51 TOOBIG ErrorCode = 18 /* String or BLOB exceeds size limit */
52 CONSTRAINT ErrorCode = 19 /* Abort due to constraint violation */
53 MISMATCH ErrorCode = 20 /* Data type mismatch */
54 MISUSE ErrorCode = 21 /* Library used incorrectly */
55 NOLFS ErrorCode = 22 /* Uses OS features not supported on host */
56 AUTH ErrorCode = 23 /* Authorization denied */
57 FORMAT ErrorCode = 24 /* Not used */
58 RANGE ErrorCode = 25 /* 2nd parameter to sqlite3_bind out of range */
59 NOTADB ErrorCode = 26 /* File opened that is not a database file */
60 NOTICE ErrorCode = 27 /* Notifications from sqlite3_log() */
61 WARNING ErrorCode = 28 /* Warnings from sqlite3_log() */
62)
63
64// ExtendedErrorCode is a result code that [Error.ExtendedCode] might return.
65//
66// https://sqlite.org/rescode.html
67type (
68 ExtendedErrorCode uint16
69 xErrorCode = ExtendedErrorCode
70)
71
72const (
73 ERROR_MISSING_COLLSEQ ExtendedErrorCode = xErrorCode(ERROR) | (1 << 8)
74 ERROR_RETRY ExtendedErrorCode = xErrorCode(ERROR) | (2 << 8)
75 ERROR_SNAPSHOT ExtendedErrorCode = xErrorCode(ERROR) | (3 << 8)
76 IOERR_READ ExtendedErrorCode = xErrorCode(IOERR) | (1 << 8)
77 IOERR_SHORT_READ ExtendedErrorCode = xErrorCode(IOERR) | (2 << 8)
78 IOERR_WRITE ExtendedErrorCode = xErrorCode(IOERR) | (3 << 8)
79 IOERR_FSYNC ExtendedErrorCode = xErrorCode(IOERR) | (4 << 8)
80 IOERR_DIR_FSYNC ExtendedErrorCode = xErrorCode(IOERR) | (5 << 8)
81 IOERR_TRUNCATE ExtendedErrorCode = xErrorCode(IOERR) | (6 << 8)
82 IOERR_FSTAT ExtendedErrorCode = xErrorCode(IOERR) | (7 << 8)
83 IOERR_UNLOCK ExtendedErrorCode = xErrorCode(IOERR) | (8 << 8)
84 IOERR_RDLOCK ExtendedErrorCode = xErrorCode(IOERR) | (9 << 8)
85 IOERR_DELETE ExtendedErrorCode = xErrorCode(IOERR) | (10 << 8)
86 IOERR_BLOCKED ExtendedErrorCode = xErrorCode(IOERR) | (11 << 8)
87 IOERR_NOMEM ExtendedErrorCode = xErrorCode(IOERR) | (12 << 8)
88 IOERR_ACCESS ExtendedErrorCode = xErrorCode(IOERR) | (13 << 8)
89 IOERR_CHECKRESERVEDLOCK ExtendedErrorCode = xErrorCode(IOERR) | (14 << 8)
90 IOERR_LOCK ExtendedErrorCode = xErrorCode(IOERR) | (15 << 8)
91 IOERR_CLOSE ExtendedErrorCode = xErrorCode(IOERR) | (16 << 8)
92 IOERR_DIR_CLOSE ExtendedErrorCode = xErrorCode(IOERR) | (17 << 8)
93 IOERR_SHMOPEN ExtendedErrorCode = xErrorCode(IOERR) | (18 << 8)
94 IOERR_SHMSIZE ExtendedErrorCode = xErrorCode(IOERR) | (19 << 8)
95 IOERR_SHMLOCK ExtendedErrorCode = xErrorCode(IOERR) | (20 << 8)
96 IOERR_SHMMAP ExtendedErrorCode = xErrorCode(IOERR) | (21 << 8)
97 IOERR_SEEK ExtendedErrorCode = xErrorCode(IOERR) | (22 << 8)
98 IOERR_DELETE_NOENT ExtendedErrorCode = xErrorCode(IOERR) | (23 << 8)
99 IOERR_MMAP ExtendedErrorCode = xErrorCode(IOERR) | (24 << 8)
100 IOERR_GETTEMPPATH ExtendedErrorCode = xErrorCode(IOERR) | (25 << 8)
101 IOERR_CONVPATH ExtendedErrorCode = xErrorCode(IOERR) | (26 << 8)
102 IOERR_VNODE ExtendedErrorCode = xErrorCode(IOERR) | (27 << 8)
103 IOERR_AUTH ExtendedErrorCode = xErrorCode(IOERR) | (28 << 8)
104 IOERR_BEGIN_ATOMIC ExtendedErrorCode = xErrorCode(IOERR) | (29 << 8)
105 IOERR_COMMIT_ATOMIC ExtendedErrorCode = xErrorCode(IOERR) | (30 << 8)
106 IOERR_ROLLBACK_ATOMIC ExtendedErrorCode = xErrorCode(IOERR) | (31 << 8)
107 IOERR_DATA ExtendedErrorCode = xErrorCode(IOERR) | (32 << 8)
108 IOERR_CORRUPTFS ExtendedErrorCode = xErrorCode(IOERR) | (33 << 8)
109 IOERR_IN_PAGE ExtendedErrorCode = xErrorCode(IOERR) | (34 << 8)
110 LOCKED_SHAREDCACHE ExtendedErrorCode = xErrorCode(LOCKED) | (1 << 8)
111 LOCKED_VTAB ExtendedErrorCode = xErrorCode(LOCKED) | (2 << 8)
112 BUSY_RECOVERY ExtendedErrorCode = xErrorCode(BUSY) | (1 << 8)
113 BUSY_SNAPSHOT ExtendedErrorCode = xErrorCode(BUSY) | (2 << 8)
114 BUSY_TIMEOUT ExtendedErrorCode = xErrorCode(BUSY) | (3 << 8)
115 CANTOPEN_NOTEMPDIR ExtendedErrorCode = xErrorCode(CANTOPEN) | (1 << 8)
116 CANTOPEN_ISDIR ExtendedErrorCode = xErrorCode(CANTOPEN) | (2 << 8)
117 CANTOPEN_FULLPATH ExtendedErrorCode = xErrorCode(CANTOPEN) | (3 << 8)
118 CANTOPEN_CONVPATH ExtendedErrorCode = xErrorCode(CANTOPEN) | (4 << 8)
119 // CANTOPEN_DIRTYWAL ExtendedErrorCode = xErrorCode(CANTOPEN) | (5 << 8) /* Not Used */
120 CANTOPEN_SYMLINK ExtendedErrorCode = xErrorCode(CANTOPEN) | (6 << 8)
121 CORRUPT_VTAB ExtendedErrorCode = xErrorCode(CORRUPT) | (1 << 8)
122 CORRUPT_SEQUENCE ExtendedErrorCode = xErrorCode(CORRUPT) | (2 << 8)
123 CORRUPT_INDEX ExtendedErrorCode = xErrorCode(CORRUPT) | (3 << 8)
124 READONLY_RECOVERY ExtendedErrorCode = xErrorCode(READONLY) | (1 << 8)
125 READONLY_CANTLOCK ExtendedErrorCode = xErrorCode(READONLY) | (2 << 8)
126 READONLY_ROLLBACK ExtendedErrorCode = xErrorCode(READONLY) | (3 << 8)
127 READONLY_DBMOVED ExtendedErrorCode = xErrorCode(READONLY) | (4 << 8)
128 READONLY_CANTINIT ExtendedErrorCode = xErrorCode(READONLY) | (5 << 8)
129 READONLY_DIRECTORY ExtendedErrorCode = xErrorCode(READONLY) | (6 << 8)
130 ABORT_ROLLBACK ExtendedErrorCode = xErrorCode(ABORT) | (2 << 8)
131 CONSTRAINT_CHECK ExtendedErrorCode = xErrorCode(CONSTRAINT) | (1 << 8)
132 CONSTRAINT_COMMITHOOK ExtendedErrorCode = xErrorCode(CONSTRAINT) | (2 << 8)
133 CONSTRAINT_FOREIGNKEY ExtendedErrorCode = xErrorCode(CONSTRAINT) | (3 << 8)
134 CONSTRAINT_FUNCTION ExtendedErrorCode = xErrorCode(CONSTRAINT) | (4 << 8)
135 CONSTRAINT_NOTNULL ExtendedErrorCode = xErrorCode(CONSTRAINT) | (5 << 8)
136 CONSTRAINT_PRIMARYKEY ExtendedErrorCode = xErrorCode(CONSTRAINT) | (6 << 8)
137 CONSTRAINT_TRIGGER ExtendedErrorCode = xErrorCode(CONSTRAINT) | (7 << 8)
138 CONSTRAINT_UNIQUE ExtendedErrorCode = xErrorCode(CONSTRAINT) | (8 << 8)
139 CONSTRAINT_VTAB ExtendedErrorCode = xErrorCode(CONSTRAINT) | (9 << 8)
140 CONSTRAINT_ROWID ExtendedErrorCode = xErrorCode(CONSTRAINT) | (10 << 8)
141 CONSTRAINT_PINNED ExtendedErrorCode = xErrorCode(CONSTRAINT) | (11 << 8)
142 CONSTRAINT_DATATYPE ExtendedErrorCode = xErrorCode(CONSTRAINT) | (12 << 8)
143 NOTICE_RECOVER_WAL ExtendedErrorCode = xErrorCode(NOTICE) | (1 << 8)
144 NOTICE_RECOVER_ROLLBACK ExtendedErrorCode = xErrorCode(NOTICE) | (2 << 8)
145 NOTICE_RBU ExtendedErrorCode = xErrorCode(NOTICE) | (3 << 8)
146 WARNING_AUTOINDEX ExtendedErrorCode = xErrorCode(WARNING) | (1 << 8)
147 AUTH_USER ExtendedErrorCode = xErrorCode(AUTH) | (1 << 8)
148)
149
150// OpenFlag is a flag for the [OpenFlags] function.
151//
152// https://sqlite.org/c3ref/c_open_autoproxy.html
153type OpenFlag uint32
154
155const (
156 OPEN_READONLY OpenFlag = 0x00000001 /* Ok for sqlite3_open_v2() */
157 OPEN_READWRITE OpenFlag = 0x00000002 /* Ok for sqlite3_open_v2() */
158 OPEN_CREATE OpenFlag = 0x00000004 /* Ok for sqlite3_open_v2() */
159 OPEN_URI OpenFlag = 0x00000040 /* Ok for sqlite3_open_v2() */
160 OPEN_MEMORY OpenFlag = 0x00000080 /* Ok for sqlite3_open_v2() */
161 OPEN_NOMUTEX OpenFlag = 0x00008000 /* Ok for sqlite3_open_v2() */
162 OPEN_FULLMUTEX OpenFlag = 0x00010000 /* Ok for sqlite3_open_v2() */
163 OPEN_SHAREDCACHE OpenFlag = 0x00020000 /* Ok for sqlite3_open_v2() */
164 OPEN_PRIVATECACHE OpenFlag = 0x00040000 /* Ok for sqlite3_open_v2() */
165 OPEN_NOFOLLOW OpenFlag = 0x01000000 /* Ok for sqlite3_open_v2() */
166 OPEN_EXRESCODE OpenFlag = 0x02000000 /* Extended result codes */
167)
168
169// PrepareFlag is a flag that can be passed to [Conn.PrepareFlags].
170//
171// https://sqlite.org/c3ref/c_prepare_normalize.html
172type PrepareFlag uint32
173
174const (
175 PREPARE_PERSISTENT PrepareFlag = 0x01
176 PREPARE_NORMALIZE PrepareFlag = 0x02
177 PREPARE_NO_VTAB PrepareFlag = 0x04
178 PREPARE_DONT_LOG PrepareFlag = 0x10
179)
180
181// FunctionFlag is a flag that can be passed to
182// [Conn.CreateFunction] and [Conn.CreateWindowFunction].
183//
184// https://sqlite.org/c3ref/c_deterministic.html
185type FunctionFlag uint32
186
187const (
188 DETERMINISTIC FunctionFlag = 0x000000800
189 DIRECTONLY FunctionFlag = 0x000080000
190 INNOCUOUS FunctionFlag = 0x000200000
191 SELFORDER1 FunctionFlag = 0x002000000
192 // SUBTYPE FunctionFlag = 0x000100000
193 // RESULT_SUBTYPE FunctionFlag = 0x001000000
194)
195
196// StmtStatus name counter values associated with the [Stmt.Status] method.
197//
198// https://sqlite.org/c3ref/c_stmtstatus_counter.html
199type StmtStatus uint32
200
201const (
202 STMTSTATUS_FULLSCAN_STEP StmtStatus = 1
203 STMTSTATUS_SORT StmtStatus = 2
204 STMTSTATUS_AUTOINDEX StmtStatus = 3
205 STMTSTATUS_VM_STEP StmtStatus = 4
206 STMTSTATUS_REPREPARE StmtStatus = 5
207 STMTSTATUS_RUN StmtStatus = 6
208 STMTSTATUS_FILTER_MISS StmtStatus = 7
209 STMTSTATUS_FILTER_HIT StmtStatus = 8
210 STMTSTATUS_MEMUSED StmtStatus = 99
211)
212
213// DBStatus are the available "verbs" that can be passed to the [Conn.Status] method.
214//
215// https://sqlite.org/c3ref/c_dbstatus_options.html
216type DBStatus uint32
217
218const (
219 DBSTATUS_LOOKASIDE_USED DBStatus = 0
220 DBSTATUS_CACHE_USED DBStatus = 1
221 DBSTATUS_SCHEMA_USED DBStatus = 2
222 DBSTATUS_STMT_USED DBStatus = 3
223 DBSTATUS_LOOKASIDE_HIT DBStatus = 4
224 DBSTATUS_LOOKASIDE_MISS_SIZE DBStatus = 5
225 DBSTATUS_LOOKASIDE_MISS_FULL DBStatus = 6
226 DBSTATUS_CACHE_HIT DBStatus = 7
227 DBSTATUS_CACHE_MISS DBStatus = 8
228 DBSTATUS_CACHE_WRITE DBStatus = 9
229 DBSTATUS_DEFERRED_FKS DBStatus = 10
230 DBSTATUS_CACHE_USED_SHARED DBStatus = 11
231 DBSTATUS_CACHE_SPILL DBStatus = 12
232 // DBSTATUS_MAX DBStatus = 12
233)
234
235// DBConfig are the available database connection configuration options.
236//
237// https://sqlite.org/c3ref/c_dbconfig_defensive.html
238type DBConfig uint32
239
240const (
241 // DBCONFIG_MAINDBNAME DBConfig = 1000
242 // DBCONFIG_LOOKASIDE DBConfig = 1001
243 DBCONFIG_ENABLE_FKEY DBConfig = 1002
244 DBCONFIG_ENABLE_TRIGGER DBConfig = 1003
245 DBCONFIG_ENABLE_FTS3_TOKENIZER DBConfig = 1004
246 DBCONFIG_ENABLE_LOAD_EXTENSION DBConfig = 1005
247 DBCONFIG_NO_CKPT_ON_CLOSE DBConfig = 1006
248 DBCONFIG_ENABLE_QPSG DBConfig = 1007
249 DBCONFIG_TRIGGER_EQP DBConfig = 1008
250 DBCONFIG_RESET_DATABASE DBConfig = 1009
251 DBCONFIG_DEFENSIVE DBConfig = 1010
252 DBCONFIG_WRITABLE_SCHEMA DBConfig = 1011
253 DBCONFIG_LEGACY_ALTER_TABLE DBConfig = 1012
254 DBCONFIG_DQS_DML DBConfig = 1013
255 DBCONFIG_DQS_DDL DBConfig = 1014
256 DBCONFIG_ENABLE_VIEW DBConfig = 1015
257 DBCONFIG_LEGACY_FILE_FORMAT DBConfig = 1016
258 DBCONFIG_TRUSTED_SCHEMA DBConfig = 1017
259 DBCONFIG_STMT_SCANSTATUS DBConfig = 1018
260 DBCONFIG_REVERSE_SCANORDER DBConfig = 1019
261 DBCONFIG_ENABLE_ATTACH_CREATE DBConfig = 1020
262 DBCONFIG_ENABLE_ATTACH_WRITE DBConfig = 1021
263 DBCONFIG_ENABLE_COMMENTS DBConfig = 1022
264 // DBCONFIG_MAX DBConfig = 1022
265)
266
267// FcntlOpcode are the available opcodes for [Conn.FileControl].
268//
269// https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html
270type FcntlOpcode uint32
271
272const (
273 FCNTL_LOCKSTATE FcntlOpcode = 1
274 FCNTL_CHUNK_SIZE FcntlOpcode = 6
275 FCNTL_FILE_POINTER FcntlOpcode = 7
276 FCNTL_PERSIST_WAL FcntlOpcode = 10
277 FCNTL_POWERSAFE_OVERWRITE FcntlOpcode = 13
278 FCNTL_VFS_POINTER FcntlOpcode = 27
279 FCNTL_JOURNAL_POINTER FcntlOpcode = 28
280 FCNTL_DATA_VERSION FcntlOpcode = 35
281 FCNTL_RESERVE_BYTES FcntlOpcode = 38
282 FCNTL_RESET_CACHE FcntlOpcode = 42
283)
284
285// LimitCategory are the available run-time limit categories.
286//
287// https://sqlite.org/c3ref/c_limit_attached.html
288type LimitCategory uint32
289
290const (
291 LIMIT_LENGTH LimitCategory = 0
292 LIMIT_SQL_LENGTH LimitCategory = 1
293 LIMIT_COLUMN LimitCategory = 2
294 LIMIT_EXPR_DEPTH LimitCategory = 3
295 LIMIT_COMPOUND_SELECT LimitCategory = 4
296 LIMIT_VDBE_OP LimitCategory = 5
297 LIMIT_FUNCTION_ARG LimitCategory = 6
298 LIMIT_ATTACHED LimitCategory = 7
299 LIMIT_LIKE_PATTERN_LENGTH LimitCategory = 8
300 LIMIT_VARIABLE_NUMBER LimitCategory = 9
301 LIMIT_TRIGGER_DEPTH LimitCategory = 10
302 LIMIT_WORKER_THREADS LimitCategory = 11
303)
304
305// AuthorizerActionCode are the integer action codes
306// that the authorizer callback may be passed.
307//
308// https://sqlite.org/c3ref/c_alter_table.html
309type AuthorizerActionCode uint32
310
311const (
312 /***************************************************** 3rd ************ 4th ***********/
313 AUTH_CREATE_INDEX AuthorizerActionCode = 1 /* Index Name Table Name */
314 AUTH_CREATE_TABLE AuthorizerActionCode = 2 /* Table Name NULL */
315 AUTH_CREATE_TEMP_INDEX AuthorizerActionCode = 3 /* Index Name Table Name */
316 AUTH_CREATE_TEMP_TABLE AuthorizerActionCode = 4 /* Table Name NULL */
317 AUTH_CREATE_TEMP_TRIGGER AuthorizerActionCode = 5 /* Trigger Name Table Name */
318 AUTH_CREATE_TEMP_VIEW AuthorizerActionCode = 6 /* View Name NULL */
319 AUTH_CREATE_TRIGGER AuthorizerActionCode = 7 /* Trigger Name Table Name */
320 AUTH_CREATE_VIEW AuthorizerActionCode = 8 /* View Name NULL */
321 AUTH_DELETE AuthorizerActionCode = 9 /* Table Name NULL */
322 AUTH_DROP_INDEX AuthorizerActionCode = 10 /* Index Name Table Name */
323 AUTH_DROP_TABLE AuthorizerActionCode = 11 /* Table Name NULL */
324 AUTH_DROP_TEMP_INDEX AuthorizerActionCode = 12 /* Index Name Table Name */
325 AUTH_DROP_TEMP_TABLE AuthorizerActionCode = 13 /* Table Name NULL */
326 AUTH_DROP_TEMP_TRIGGER AuthorizerActionCode = 14 /* Trigger Name Table Name */
327 AUTH_DROP_TEMP_VIEW AuthorizerActionCode = 15 /* View Name NULL */
328 AUTH_DROP_TRIGGER AuthorizerActionCode = 16 /* Trigger Name Table Name */
329 AUTH_DROP_VIEW AuthorizerActionCode = 17 /* View Name NULL */
330 AUTH_INSERT AuthorizerActionCode = 18 /* Table Name NULL */
331 AUTH_PRAGMA AuthorizerActionCode = 19 /* Pragma Name 1st arg or NULL */
332 AUTH_READ AuthorizerActionCode = 20 /* Table Name Column Name */
333 AUTH_SELECT AuthorizerActionCode = 21 /* NULL NULL */
334 AUTH_TRANSACTION AuthorizerActionCode = 22 /* Operation NULL */
335 AUTH_UPDATE AuthorizerActionCode = 23 /* Table Name Column Name */
336 AUTH_ATTACH AuthorizerActionCode = 24 /* Filename NULL */
337 AUTH_DETACH AuthorizerActionCode = 25 /* Database Name NULL */
338 AUTH_ALTER_TABLE AuthorizerActionCode = 26 /* Database Name Table Name */
339 AUTH_REINDEX AuthorizerActionCode = 27 /* Index Name NULL */
340 AUTH_ANALYZE AuthorizerActionCode = 28 /* Table Name NULL */
341 AUTH_CREATE_VTABLE AuthorizerActionCode = 29 /* Table Name Module Name */
342 AUTH_DROP_VTABLE AuthorizerActionCode = 30 /* Table Name Module Name */
343 AUTH_FUNCTION AuthorizerActionCode = 31 /* NULL Function Name */
344 AUTH_SAVEPOINT AuthorizerActionCode = 32 /* Operation Savepoint Name */
345 AUTH_RECURSIVE AuthorizerActionCode = 33 /* NULL NULL */
346 // AUTH_COPY AuthorizerActionCode = 0 /* No longer used */
347)
348
349// AuthorizerReturnCode are the integer codes
350// that the authorizer callback may return.
351//
352// https://sqlite.org/c3ref/c_deny.html
353type AuthorizerReturnCode uint32
354
355const (
356 AUTH_OK AuthorizerReturnCode = 0
357 AUTH_DENY AuthorizerReturnCode = 1 /* Abort the SQL statement with an error */
358 AUTH_IGNORE AuthorizerReturnCode = 2 /* Don't allow access, but don't generate an error */
359)
360
361// CheckpointMode are all the checkpoint mode values.
362//
363// https://sqlite.org/c3ref/c_checkpoint_full.html
364type CheckpointMode uint32
365
366const (
367 CHECKPOINT_PASSIVE CheckpointMode = 0 /* Do as much as possible w/o blocking */
368 CHECKPOINT_FULL CheckpointMode = 1 /* Wait for writers, then checkpoint */
369 CHECKPOINT_RESTART CheckpointMode = 2 /* Like FULL but wait for readers */
370 CHECKPOINT_TRUNCATE CheckpointMode = 3 /* Like RESTART but also truncate WAL */
371)
372
373// TxnState are the allowed return values from [Conn.TxnState].
374//
375// https://sqlite.org/c3ref/c_txn_none.html
376type TxnState uint32
377
378const (
379 TXN_NONE TxnState = 0
380 TXN_READ TxnState = 1
381 TXN_WRITE TxnState = 2
382)
383
384// TraceEvent identify classes of events that can be monitored with [Conn.Trace].
385//
386// https://sqlite.org/c3ref/c_trace.html
387type TraceEvent uint32
388
389const (
390 TRACE_STMT TraceEvent = 0x01
391 TRACE_PROFILE TraceEvent = 0x02
392 TRACE_ROW TraceEvent = 0x04
393 TRACE_CLOSE TraceEvent = 0x08
394)
395
396// Datatype is a fundamental datatype of SQLite.
397//
398// https://sqlite.org/c3ref/c_blob.html
399type Datatype uint32
400
401const (
402 INTEGER Datatype = 1
403 FLOAT Datatype = 2
404 TEXT Datatype = 3
405 BLOB Datatype = 4
406 NULL Datatype = 5
407)
408
409// String implements the [fmt.Stringer] interface.
410func (t Datatype) String() string {
411 const name = "INTEGERFLOATEXTBLOBNULL"
412 switch t {
413 case INTEGER:
414 return name[0:7]
415 case FLOAT:
416 return name[7:12]
417 case TEXT:
418 return name[11:15]
419 case BLOB:
420 return name[15:19]
421 case NULL:
422 return name[19:23]
423 }
424 return strconv.FormatUint(uint64(t), 10)
425}