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