ffi.odin (3743B)
1 /* 2 The raw C API: the subset of sqlite3.h the wrapper needs, under the C names, 3 exported so a caller that needs an interface the wrapper does not cover can 4 reach for it. The wrapper in sqlite3.odin is what scripts should use. The 5 declarations track the vendored header, sqlite3.h 3.53.4. 6 7 The library is the amalgamation under vendor/, compiled into lib/ by the 8 justfile's `sqlite` recipe, which is also where the compile-time options and 9 the reason for each are written down. The archive path below is relative to 10 this directory, which is what puts lib/ here rather than in build/; the 11 README's SQLite section records that and what `just check` does without it. 12 */ 13 package sqlite3 14 15 import "core:c" 16 17 when ODIN_OS == .Windows { 18 foreign import lib "lib/sqlite3.lib" 19 } else { 20 @(extra_linker_flags = "-lpthread -lm") 21 foreign import lib "lib/sqlite3.a" 22 } 23 24 // Connection is sqlite3, the open database handle. SQLite owns the memory. 25 Connection :: struct {} 26 27 // Statement is sqlite3_stmt, one compiled statement. SQLite owns the memory. 28 Statement :: struct {} 29 30 // TRANSIENT tells a bind call to copy the bytes it was handed, because Odin 31 // owns them and may free or move them before the statement runs. 32 TRANSIENT :: rawptr(~uintptr(0)) 33 34 // Flags for sqlite3_open_v2. 35 OPEN_READONLY :: 0x00000001 36 OPEN_READWRITE :: 0x00000002 37 OPEN_CREATE :: 0x00000004 38 OPEN_URI :: 0x00000040 39 40 // Column storage classes, as sqlite3_column_type reports them. 41 TYPE_INTEGER :: 1 42 TYPE_FLOAT :: 2 43 TYPE_TEXT :: 3 44 TYPE_BLOB :: 4 45 TYPE_NULL :: 5 46 47 @(default_calling_convention = "c") 48 foreign lib { 49 sqlite3_libversion :: proc() -> cstring --- 50 sqlite3_errstr :: proc(code: c.int) -> cstring --- 51 52 sqlite3_open_v2 :: proc(filename: cstring, db: ^^Connection, flags: c.int, vfs: cstring) -> c.int --- 53 sqlite3_close_v2 :: proc(db: ^Connection) -> c.int --- 54 sqlite3_errmsg :: proc(db: ^Connection) -> cstring --- 55 sqlite3_extended_errcode :: proc(db: ^Connection) -> c.int --- 56 sqlite3_busy_timeout :: proc(db: ^Connection, ms: c.int) -> c.int --- 57 sqlite3_interrupt :: proc(db: ^Connection) --- 58 sqlite3_changes64 :: proc(db: ^Connection) -> i64 --- 59 sqlite3_last_insert_rowid :: proc(db: ^Connection) -> i64 --- 60 61 sqlite3_prepare_v2 :: proc(db: ^Connection, sql: [^]u8, n: c.int, stmt: ^^Statement, tail: ^[^]u8) -> c.int --- 62 sqlite3_finalize :: proc(stmt: ^Statement) -> c.int --- 63 sqlite3_step :: proc(stmt: ^Statement) -> c.int --- 64 sqlite3_reset :: proc(stmt: ^Statement) -> c.int --- 65 sqlite3_clear_bindings :: proc(stmt: ^Statement) -> c.int --- 66 sqlite3_bind_parameter_count :: proc(stmt: ^Statement) -> c.int --- 67 68 sqlite3_bind_null :: proc(stmt: ^Statement, i: c.int) -> c.int --- 69 sqlite3_bind_int64 :: proc(stmt: ^Statement, i: c.int, v: i64) -> c.int --- 70 sqlite3_bind_double :: proc(stmt: ^Statement, i: c.int, v: f64) -> c.int --- 71 sqlite3_bind_text :: proc(stmt: ^Statement, i: c.int, v: [^]u8, n: c.int, free: rawptr) -> c.int --- 72 sqlite3_bind_blob :: proc(stmt: ^Statement, i: c.int, v: rawptr, n: c.int, free: rawptr) -> c.int --- 73 74 sqlite3_column_count :: proc(stmt: ^Statement) -> c.int --- 75 sqlite3_column_name :: proc(stmt: ^Statement, col: c.int) -> cstring --- 76 sqlite3_column_type :: proc(stmt: ^Statement, col: c.int) -> c.int --- 77 sqlite3_column_bytes :: proc(stmt: ^Statement, col: c.int) -> c.int --- 78 sqlite3_column_int64 :: proc(stmt: ^Statement, col: c.int) -> i64 --- 79 sqlite3_column_double :: proc(stmt: ^Statement, col: c.int) -> f64 --- 80 sqlite3_column_text :: proc(stmt: ^Statement, col: c.int) -> [^]u8 --- 81 sqlite3_column_blob :: proc(stmt: ^Statement, col: c.int) -> rawptr --- 82 }