const.go 19 KB

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