package sqlite3_bindings
import "core:c"
foreign import sqlite3 "system:sqlite3"
@(default_calling_convention = "c", link_prefix = "sqlite3_")
foreign sqlite3 {
/*
Opens a new database connection to the UTF-8 encoded filename, creating the
database if it does not exist. The connection handle is stored in *db; the
caller must close it with close() or close_v2() even if this returns an error.
*/
open :: proc(filename: cstring, db: ^Connection) -> c.int ---
/*
Extended form of open() that accepts flags (OpenFlags) controlling access mode
and an optional VFS module name. flags must include at least one of Readonly,
Readwrite, or Readwrite|Create.
*/
open_v2 :: proc(filename: cstring, db: ^Connection, flags: OpenFlags, vfs: cstring) -> c.int ---
/*
Destroys a database connection and releases all associated memory. Returns Busy
if any prepared statements, open BLOBs, or unfinished backups still reference
the connection; in that case the connection is not closed.
*/
close :: proc(db: Connection) -> c.int ---
/*
Like close() but designed for garbage-collected host languages where destructor
order is non-deterministic. Always returns Ok; any remaining resources are freed
automatically once the last referencing object is destroyed.
*/
close_v2 :: proc(db: Connection) -> c.int ---
/*
Compiles the first SQL statement in sql into a prepared statement stored in *stmt.
n_byte is the byte length of sql (-1 for NUL-terminated). tail, if non-nil,
receives a pointer to the first byte past the parsed statement.
*/
prepare_v2 :: proc(db: Connection, sql: cstring, n_byte: c.int, stmt: ^Statement, tail: ^cstring) -> c.int ---
/*
Like prepare_v2() but accepts additional PrepareFlags (e.g. Persistent, No_Vtab)
that control caching behavior and virtual-table access.
*/
prepare_v3 :: proc(db: Connection, sql: cstring, n_byte: c.int, flags: PrepareFlags, stmt: ^Statement, tail: ^cstring) -> c.int ---
/*
Advances a prepared statement one step. Returns Row when a result row is available
(call column_* to read it), or Done when execution is complete. Call reset()
before stepping again after Done.
*/
step :: proc(stmt: Statement) -> c.int ---
/*
Resets a prepared statement back to its initial state so it can be re-executed.
Existing parameter bindings are preserved. Returns the error code from the most
recent step() call.
*/
reset :: proc(stmt: Statement) -> c.int ---
/* Destroys a prepared statement and releases all associated resources. Must be called on every prepared statement to avoid memory leaks. */
finalize :: proc(stmt: Statement) -> c.int ---
/*
Convenience wrapper that compiles and executes one or more semicolon-separated
SQL statements. cbfun is called for each result row; errmsg, if non-nil, receives
a malloc-allocated error string on failure that the caller must free with free().
*/
exec :: proc(db: Connection, sql: cstring, cbfun: ExecProc, user_arg: rawptr, errmsg: ^cstring) -> c.int ---
/*
Binds a BLOB of size bytes to parameter idx (1-based; leftmost = 1).
Unbound parameters default to NULL; bindings persist across reset() calls.
destruct controls memory lifetime: STATIC borrows the caller's buffer (must
remain valid until rebound or finalized); TRANSIENT copies immediately; a
function pointer is called when SQLite no longer needs the buffer.
*/
bind_blob :: proc(stmt: Statement, idx: c.int, val: rawptr, size: c.int, destruct: rawptr) -> c.int ---
/* Like bind_blob() but accepts a 64-bit size. */
bind_blob64 :: proc(stmt: Statement, idx: c.int, val: rawptr, size: c.uint64_t, destruct: rawptr) -> c.int ---
/* Bind a double-precision float to parameter idx (1-based). */
bind_double :: proc(stmt: Statement, idx: c.int, val: c.double) -> c.int ---
/* Bind a 32-bit signed integer to parameter idx (1-based). */
bind_int :: proc(stmt: Statement, idx: c.int, val: c.int) -> c.int ---
/* Bind a 64-bit signed integer to parameter idx (1-based). */
bind_int64 :: proc(stmt: Statement, idx: c.int, val: c.int64_t) -> c.int ---
/* Bind SQL NULL to parameter idx (1-based). */
bind_null :: proc(stmt: Statement, idx: c.int) -> c.int ---
/*
Bind UTF-8 text to parameter idx (1-based). size is the byte count; -1 means
NUL-terminated. destruct controls memory ownership (see bind_blob for details).
*/
bind_text :: proc(stmt: Statement, idx: c.int, val: cstring, size: c.int, destruct: rawptr) -> c.int ---
/* Like bind_text() but interprets val as UTF-16 text. */
bind_text16 :: proc(stmt: Statement, idx: c.int, val: rawptr, size: c.int, destruct: rawptr) -> c.int ---
/* Like bind_text() but accepts a 64-bit size and an explicit TextEncoding. */
bind_text64 :: proc(stmt: Statement, idx: c.int, val: cstring, size: c.uint64_t, encoding: TextEncoding, destruct: rawptr) -> c.int ---
/* Bind a copy of an sqlite3_value to parameter idx (1-based). */
bind_value :: proc(stmt: Statement, idx: c.int, val: Value) -> c.int ---
/*
Bind an application-level pointer tagged with type_name as SQL NULL to parameter
idx (1-based). The pointer can later be retrieved via value_pointer() inside a
custom SQL function.
*/
bind_pointer :: proc(stmt: Statement, idx: c.int, val: rawptr, type_name: cstring, destruct: rawptr) -> c.int ---
/*
Bind a zero-filled BLOB of size bytes to parameter idx (1-based). Efficient
placeholder for incremental BLOB I/O with blob_write().
*/
bind_zeroblob :: proc(stmt: Statement, idx: c.int, size: c.int) -> c.int ---
/* Like bind_zeroblob() but accepts a 64-bit size. */
bind_zeroblob64 :: proc(stmt: Statement, idx: c.int, size: c.uint64_t) -> c.int ---
/* Reset all parameter bindings on stmt back to NULL. */
clear_bindings :: proc(stmt: Statement) -> c.int ---
/* Returns the number of bindable SQL parameters in stmt. */
bind_parameter_count :: proc(stmt: Statement) -> c.int ---
/* Returns the 1-based index of the named parameter (:VVV, @VVV, or $VVV), or 0 if no such parameter exists. */
bind_parameter_index :: proc(stmt: Statement, name: cstring) -> c.int ---
/* Returns the name of the parameter at 1-based idx, or nil for unnamed parameters. */
bind_parameter_name :: proc(stmt: Statement, idx: c.int) -> cstring ---
/*
Returns the column value as a raw BLOB pointer. col is 0-based (leftmost = 0).
SQLite applies type coercion automatically. The pointer is valid until the next
type conversion on that column, or until step(), reset(), or finalize() is called.
*/
column_blob :: proc(stmt: Statement, col: c.int) -> rawptr ---
/* Returns the column value as a double. col is 0-based. */
column_double :: proc(stmt: Statement, col: c.int) -> c.double ---
/* Returns the column value as a 32-bit integer. col is 0-based. */
column_int :: proc(stmt: Statement, col: c.int) -> c.int ---
/* Returns the column value as a 64-bit integer. col is 0-based. */
column_int64 :: proc(stmt: Statement, col: c.int) -> c.int64_t ---
/* Returns the column value as a NUL-terminated UTF-8 string, or nil for SQL NULL. col is 0-based. */
column_text :: proc(stmt: Statement, col: c.int) -> cstring ---
/* Returns the column value as a NUL-terminated UTF-16 string (native byte order), or nil for SQL NULL. col is 0-based. */
column_text16 :: proc(stmt: Statement, col: c.int) -> rawptr ---
/*
Returns the column value as an unprotected sqlite3_value. Only safe to pass
directly to bind_value() or result_value() — do not read its contents directly.
col is 0-based.
*/
column_value :: proc(stmt: Statement, col: c.int) -> Value ---
/*
Returns the byte count of a BLOB or UTF-8 TEXT column, excluding the NUL
terminator. Must be called after column_blob() or column_text(), not before.
col is 0-based.
*/
column_bytes :: proc(stmt: Statement, col: c.int) -> c.int ---
/*
Returns the byte count of a UTF-16 TEXT column, excluding the NUL terminator.
Must be called after column_text16(), not before. col is 0-based.
*/
column_bytes16 :: proc(stmt: Statement, col: c.int) -> c.int ---
/* Returns the storage type of the value in col (0-based): Integer, Float, Text, Blob, or Null. */
column_type :: proc(stmt: Statement, col: c.int) -> Datatype ---
/* Returns the number of columns in the result set. Returns 0 for statements that produce no output (INSERT, UPDATE, DELETE, etc.). */
column_count :: proc(stmt: Statement) -> c.int ---
/*
Returns the name assigned to result column col (0-based) as a UTF-8 string.
The pointer is valid until the statement is finalized or reprepared.
*/
column_name :: proc(stmt: Statement, col: c.int) -> cstring ---
/* Like column_name() but returns the name as a UTF-16 string. */
column_name16 :: proc(stmt: Statement, col: c.int) -> rawptr ---
/*
Returns the declared type of the table column underlying result column col
(0-based) as a UTF-8 string (e.g. "INTEGER", "TEXT"), or nil if the column is
an expression.
*/
column_decltype :: proc(stmt: Statement, col: c.int) -> cstring ---
/* Like column_decltype() but returns a UTF-16 string. */
column_decltype16 :: proc(stmt: Statement, col: c.int) -> rawptr ---
/*
Returns the database name (e.g. "main") that result column col (0-based)
originates from, or nil if it is an expression.
Requires SQLITE_ENABLE_COLUMN_METADATA at compile time.
*/
column_database_name :: proc(stmt: Statement, col: c.int) -> cstring ---
/*
Returns the table name that result column col (0-based) originates from, or nil
for expressions. Requires SQLITE_ENABLE_COLUMN_METADATA at compile time.
*/
column_table_name :: proc(stmt: Statement, col: c.int) -> cstring ---
/*
Returns the original un-aliased column name that result column col (0-based) was
drawn from, or nil for expressions.
Requires SQLITE_ENABLE_COLUMN_METADATA at compile time.
*/
column_origin_name :: proc(stmt: Statement, col: c.int) -> cstring ---
/* Returns the number of columns in the current result row. Returns 0 before the first step() or after step() returns Done. */
data_count :: proc(stmt: Statement) -> c.int ---
/*
Returns a pointer to the original UTF-8 SQL text used to create the statement.
The string is managed by SQLite and freed when the statement is finalized.
*/
sql :: proc(stmt: Statement) -> cstring ---
/*
Returns the SQL text of the statement with bound parameters expanded to their
current values. The returned string must be freed by the caller with free().
Returns nil if memory is insufficient or the result exceeds SQLITE_LIMIT_LENGTH.
*/
expanded_sql :: proc(stmt: Statement) -> cstring ---
/* Returns the database connection that owns this prepared statement. */
db_handle :: proc(stmt: Statement) -> Connection ---
/* Returns non-zero if the statement has been stepped at least once but has not yet returned Done and has not been reset(). */
stmt_busy :: proc(stmt: Statement) -> c.int ---
/* Returns 1 for EXPLAIN statements, 2 for EXPLAIN QUERY PLAN, and 0 for ordinary statements. */
stmt_isexplain :: proc(stmt: Statement) -> c.int ---
/* Returns non-zero if the statement makes no direct changes to the database. Note: side effects from application-defined functions are not detected. */
stmt_readonly :: proc(stmt: Statement) -> c.int ---
/*
Returns the current value of the performance counter identified by op.
If reset is non-zero, the counter is set to zero after the value is read.
*/
stmt_status :: proc(stmt: Statement, op: StmtStatusOp, reset: c.int) -> c.int ---
/* Returns the primary result code from the most recent failed API call on db. */
errcode :: proc(db: Connection) -> c.int ---
/* Like errcode() but always returns the extended result code even when extended codes are disabled on the connection. */
extended_errcode :: proc(db: Connection) -> c.int ---
/* Returns an English UTF-8 string describing the most recent error on db. The pointer is managed by SQLite and may be overwritten by the next API call. */
errmsg :: proc(db: Connection) -> cstring ---
/* Like errmsg() but returns the error message as a UTF-16 string. */
errmsg16 :: proc(db: Connection) -> rawptr ---
/* Returns a static English description of result code `code`. Must not be freed. */
errstr :: proc(code: c.int) -> cstring ---
/* Enables (onoff=1) or disables (onoff=0) extended result codes for the connection. */
extended_result_codes :: proc(db: Connection, onoff: c.int) -> c.int ---
/*
Returns the number of rows modified by the most recently completed INSERT, UPDATE,
or DELETE statement on db. Changes via triggers or cascades are excluded.
*/
changes :: proc(db: Connection) -> c.int ---
/* Like changes() but returns a 64-bit value, useful when the row count may exceed INT_MAX. */
changes64 :: proc(db: Connection) -> c.int64_t ---
/* Returns the total number of rows modified by all INSERT, UPDATE, and DELETE statements on db since the connection was opened. */
total_changes :: proc(db: Connection) -> c.int ---
/* Like total_changes() but returns a 64-bit value. */
total_changes64 :: proc(db: Connection) -> c.int64_t ---
/*
Returns the rowid of the most recently inserted row on db. Returns 0 if no
successful INSERT has occurred. Does not track WITHOUT ROWID table inserts.
*/
last_insert_rowid :: proc(db: Connection) -> c.int64_t ---
/*
Explicitly sets the value that last_insert_rowid() will return. Useful inside
virtual table xUpdate methods to restore the rowid after internal inserts.
*/
set_last_insert_rowid :: proc(db: Connection, rowid: c.int64_t) ---
/* Returns non-zero if db is in autocommit mode (no active BEGIN transaction). */
get_autocommit :: proc(db: Connection) -> c.int ---
/* Returns 1 if db_name is read-only, 0 if read-write, or -1 if db_name is not a valid attached database name on db. */
db_readonly :: proc(db: Connection, db_name: cstring) -> c.int ---
/* Returns the filename of the database named db_name on db, or nil/empty string for in-memory and temporary databases. */
db_filename :: proc(db: Connection, db_name: cstring) -> cstring ---
/*
Queries or changes the run-time limit identified by id. Returns the prior limit
value. Pass -1 as new_val to query without changing. Limits are per-connection
and cannot exceed the compile-time SQLITE_MAX_* upper bounds.
*/
limit :: proc(db: Connection, id: LimitId, new_val: c.int) -> c.int ---
/*
Returns metadata for a named column in a table: declared type, collation name,
and flags for NOT NULL, PRIMARY KEY, and AUTOINCREMENT. Output pointers are
valid only until the next SQLite API call on db.
*/
table_column_metadata :: proc(db: Connection, db_name: cstring, table_name: cstring, column_name: cstring, data_type: ^cstring, coll_seq: ^cstring, not_null: ^c.int, primary_key: ^c.int, auto_inc: ^c.int) -> c.int ---
/*
Registers a callback invoked whenever a database table is locked by another
connection. count is the retry number; return non-zero to retry, zero to return
Busy. Pass nil to clear the handler.
*/
busy_handler :: proc(db: Connection, handler: BusyHandler, user_arg: rawptr) -> c.int ---
/* Configures a built-in busy handler that retries for up to ms milliseconds before returning Busy. Replaces any previously registered busy handler. */
busy_timeout :: proc(db: Connection, ms: c.int) -> c.int ---
/*
Causes any pending operation on db to abort at the earliest opportunity, returning
Interrupt. Safe to call from a different thread than the one running the SQL operation.
*/
interrupt :: proc(db: Connection) ---
/*
Registers a callback invoked approximately every n_ops VDBE instructions during
step() and prepare() calls. Return non-zero from the callback to abort the
operation.
*/
progress_handler :: proc(db: Connection, n_ops: c.int, handler: ProgressHandler, user_arg: rawptr) ---
/*
Registers a trace callback selected by the event bitmask. Only one callback may
be active per connection; calling again replaces the previous one. Pass mask=0 or
callback=nil to disable tracing.
*/
trace_v2 :: proc(db: Connection, mask: TraceFlags, callback: TraceCallback, user_arg: rawptr) -> c.int ---
/*
Registers an authorizer callback invoked for each SQL action during statement
compilation. Return Ok/Deny/Ignore to allow, reject, or silently skip the action.
Pass nil to remove the authorizer.
*/
set_authorizer :: proc(db: Connection, auth: AuthorizerCallback, user_arg: rawptr) -> c.int ---
/*
Registers a callback invoked just before each transaction commits. Returning
non-zero converts the commit into a rollback. Returns the previous hook pointer.
*/
commit_hook :: proc(db: Connection, hook: CommitHook, user_arg: rawptr) -> rawptr ---
/* Registers a callback invoked whenever a transaction is rolled back. Returns the previous hook. Pass nil to unregister. */
rollback_hook :: proc(db: Connection, hook: RollbackHook, user_arg: rawptr) -> rawptr ---
/*
Registers a callback invoked after each INSERT, UPDATE, or DELETE.
op is SQLITE_INSERT (18), SQLITE_UPDATE (23), or SQLITE_DELETE (9).
Returns the previous hook.
*/
update_hook :: proc(db: Connection, hook: UpdateHook, user_arg: rawptr) -> rawptr ---
/* Registers a callback invoked after each WAL-mode commit once the write lock is released. Returns the previous hook. */
wal_hook :: proc(db: Connection, hook: WalHook, user_arg: rawptr) -> rawptr ---
/* Installs a built-in WAL hook that triggers a checkpoint whenever the WAL file reaches n pages. Pass n=0 to disable automatic checkpointing. */
wal_autocheckpoint :: proc(db: Connection, n: c.int) -> c.int ---
/*
Runs a WAL checkpoint on db_name using the given mode. log_size and ckpt_count
receive the WAL frame count and checkpointed frame count respectively; pass nil
to ignore them.
*/
wal_checkpoint_v2 :: proc(db: Connection, db_name: cstring, mode: CheckpointMode, log_size: ^c.int, ckpt_count: ^c.int) -> c.int ---
/*
Registers a scalar (func non-nil) or aggregate (step + final_fn non-nil) SQL
function. encoding selects the preferred text encoding and may include
TextEncoding.Deterministic / Directonly / Innocuous flags. destroy is called
with user_arg when the function is deleted or the connection closes.
*/
create_function_v2 :: proc(db: Connection, name: cstring, n_arg: c.int, encoding: TextEncoding, user_arg: rawptr, func: ScalarFunc, step: StepFunc, final_fn: FinalFunc, destroy: Destructor) -> c.int ---
/*
Registers an aggregate window function. step and final_fn are required; value
and inverse must both be non-nil for window semantics (or both nil for a plain
aggregate). destroy is called with user_arg on removal.
*/
create_window_function :: proc(db: Connection, name: cstring, n_arg: c.int, encoding: TextEncoding, user_arg: rawptr, step: StepFunc, final_fn: FinalFunc, value: ValueFunc, inverse: InverseFunc, destroy: Destructor) -> c.int ---
/*
Returns a zeroed n_bytes buffer tied to the current aggregate invocation.
Subsequent calls for the same invocation return the same pointer. The buffer is
freed automatically when the aggregate query concludes.
*/
aggregate_context :: proc(ctx: Context, n_bytes: c.int) -> rawptr ---
/* Returns the user_arg pointer supplied when the SQL function was registered via create_function_v2(). */
user_data :: proc(ctx: Context) -> rawptr ---
/* Returns the database connection associated with this function invocation context. */
context_db_handle :: proc(ctx: Context) -> Connection ---
/*
Associates auxiliary data with the n-th argument of the current SQL function
call. destroy is invoked when SQLite discards the data (which may be immediately).
*/
set_auxdata :: proc(ctx: Context, n: c.int, data: rawptr, destroy: Destructor) ---
/* Returns auxiliary data previously stored for the n-th argument via set_auxdata(), or nil if none exists or the data was discarded. */
get_auxdata :: proc(ctx: Context, n: c.int) -> rawptr ---
/*
Sets the return value of an application-defined SQL function to a BLOB of size
bytes. destruct follows the same STATIC/TRANSIENT convention as bind_blob().
*/
result_blob :: proc(ctx: Context, val: rawptr, size: c.int, destruct: rawptr) ---
/* Like result_blob() but accepts a 64-bit size. */
result_blob64 :: proc(ctx: Context, val: rawptr, size: c.uint64_t, destruct: rawptr) ---
/* Set the function result to a double. */
result_double :: proc(ctx: Context, val: c.double) ---
/* Cause the function to raise an error with a UTF-8 message. size=-1 means NUL-terminated. */
result_error :: proc(ctx: Context, msg: cstring, size: c.int) ---
/* Like result_error() but the message is in UTF-16. */
result_error16 :: proc(ctx: Context, msg: rawptr, size: c.int) ---
/* Override the error code SQLite reports alongside a result_error() call. The default error code is SQLITE_ERROR. */
result_error_code :: proc(ctx: Context, code: c.int) ---
/* Cause the function to return SQLITE_NOMEM. */
result_error_nomem :: proc(ctx: Context) ---
/* Cause the function to return SQLITE_TOOBIG. */
result_error_toobig :: proc(ctx: Context) ---
/* Set the function result to a 32-bit integer. */
result_int :: proc(ctx: Context, val: c.int) ---
/* Set the function result to a 64-bit integer. */
result_int64 :: proc(ctx: Context, val: c.int64_t) ---
/* Set the function result to SQL NULL. */
result_null :: proc(ctx: Context) ---
/* Set the function result to a UTF-8 text string. size=-1 means NUL-terminated. destruct controls memory ownership (see bind_blob). */
result_text :: proc(ctx: Context, val: cstring, size: c.int, destruct: rawptr) ---
/* Like result_text() but the value is UTF-16 in native byte order. */
result_text16 :: proc(ctx: Context, val: rawptr, size: c.int, destruct: rawptr) ---
/* Like result_text() but accepts a 64-bit size and an explicit TextEncoding. */
result_text64 :: proc(ctx: Context, val: cstring, size: c.uint64_t, encoding: TextEncoding, destruct: rawptr) ---
/* Set the function result to a copy of the given sqlite3_value. */
result_value :: proc(ctx: Context, val: Value) ---
/* Set the function result to an all-zero BLOB of size bytes. */
result_zeroblob :: proc(ctx: Context, size: c.int) ---
/* Like result_zeroblob() but accepts a 64-bit size. Returns an error code on overflow. */
result_zeroblob64 :: proc(ctx: Context, size: c.uint64_t) -> c.int ---
/* Attach an application-defined subtype tag to the result; retrievable via value_subtype() in the calling SQL function. */
result_subtype :: proc(ctx: Context, subtype: c.uint) ---
/*
Returns the value as a raw BLOB pointer. The pointer is valid until the next type
conversion on the same value object.
*/
value_blob :: proc(val: Value) -> rawptr ---
/* Returns the value as a double. */
value_double :: proc(val: Value) -> c.double ---
/* Returns the value as a 32-bit integer. */
value_int :: proc(val: Value) -> c.int ---
/* Returns the value as a 64-bit integer. */
value_int64 :: proc(val: Value) -> c.int64_t ---
/* Returns the value as a NUL-terminated UTF-8 string, or nil for SQL NULL. */
value_text :: proc(val: Value) -> cstring ---
/* Returns the value as a NUL-terminated UTF-16 string (native byte order). */
value_text16 :: proc(val: Value) -> rawptr ---
/* Returns the byte count of a BLOB or UTF-8 TEXT value, excluding the NUL terminator. Call after value_blob() or value_text(), not before. */
value_bytes :: proc(val: Value) -> c.int ---
/* Returns the byte count of a UTF-16 TEXT value, excluding the NUL terminator. Call after value_text16(), not before. */
value_bytes16 :: proc(val: Value) -> c.int ---
/* Returns the native storage type of the value: Integer, Float, Text, Blob, or Null. */
value_type :: proc(val: Value) -> Datatype ---
/* Like value_type() but first attempts to convert text that looks like a number, returning Integer or Float when the conversion succeeds. */
value_numeric_type :: proc(val: Value) -> Datatype ---
/* Returns non-zero if this value is an unchanged column in a virtual table UPDATE. Meaningful only inside an xUpdate method; appears as NULL elsewhere. */
value_nochange :: proc(val: Value) -> c.int ---
/* Returns the application-defined subtype previously attached via result_subtype(). */
value_subtype :: proc(val: Value) -> c.uint ---
/* Creates an independent protected copy of val. Returns nil on allocation failure. Must be freed with value_free() when no longer needed. */
value_dup :: proc(val: Value) -> Value ---
/* Frees a Value obtained from value_dup(). No-op if val is nil. */
value_free :: proc(val: Value) ---
/* Registers a named collation sequence on db with a destructor. destroy is called with user_arg when the collation is removed or the connection closes. */
create_collation_v2 :: proc(db: Connection, name: cstring, encoding: TextEncoding, user_arg: rawptr, cmp: CompareFunc, destroy: Destructor) -> c.int ---
/* Registers a callback invoked whenever an unknown collation sequence is required. The callback should register the collation via create_collation_v2() before returning. */
collation_needed :: proc(db: Connection, user_arg: rawptr, callback: CollationNeeded) -> c.int ---
/*
Initializes an online backup from source database source_name to dest database
dest_name. The source and destination connections must be distinct. Returns nil
if dest already has an open read-write transaction.
*/
backup_init :: proc(dest: Connection, dest_name: cstring, source: Connection, source_name: cstring) -> Backup ---
/*
Copies up to n_page pages from source to destination. Returns Ok if more pages
remain, Done when all pages are copied, or Busy/Locked if the source is temporarily
unavailable (safe to retry). If the source is modified during backup, the next
call automatically restarts the copy.
*/
backup_step :: proc(backup: Backup, n_page: c.int) -> c.int ---
/*
Finalizes the backup and releases all resources. If the backup did not complete,
any partial changes to dest are rolled back. Returns Ok if all prior step calls
succeeded, or the first error code otherwise.
*/
backup_finish :: proc(backup: Backup) -> c.int ---
/* Returns the number of pages not yet copied after the most recent backup_step() call. */
backup_remaining :: proc(backup: Backup) -> c.int ---
/* Returns the total number of pages in the source database as of the most recent backup_step() call. */
backup_pagecount :: proc(backup: Backup) -> c.int ---
/*
Opens an incremental BLOB I/O handle on the specified row. flags=0 opens for
read-only access; any non-zero value opens for read-write. The handle is stored
in *blob and must be closed with blob_close().
*/
blob_open :: proc(db: Connection, db_name: cstring, table: cstring, column: cstring, rowid: c.int64_t, flags: c.int, blob: ^Blob) -> c.int ---
/* Closes a BLOB handle and releases all associated resources. */
blob_close :: proc(blob: Blob) -> c.int ---
/* Returns the size in bytes of the open BLOB. The size cannot be changed via this interface; use an UPDATE statement to resize a BLOB column. */
blob_bytes :: proc(blob: Blob) -> c.int ---
/* Reads n bytes starting at offset from the BLOB into buf. Returns Abort if the underlying row has been modified since blob_open(). */
blob_read :: proc(blob: Blob, buf: rawptr, n: c.int, offset: c.int) -> c.int ---
/* Writes n bytes from buf into the BLOB at offset. Returns Abort if the underlying row has been modified since blob_open(). */
blob_write :: proc(blob: Blob, buf: rawptr, n: c.int, offset: c.int) -> c.int ---
/* Moves the BLOB handle to point at a different row in the same table and column. Faster than closing and reopening the handle. */
blob_reopen :: proc(blob: Blob, rowid: c.int64_t) -> c.int ---
/* Allocates at least size bytes and returns a pointer, or nil if size <= 0 or the allocation fails. Memory must be freed with free(). */
malloc :: proc(size: c.int) -> rawptr ---
/* Like malloc() but accepts a 64-bit size. */
malloc64 :: proc(size: c.uint64_t) -> rawptr ---
/* Resizes a prior allocation to at least size bytes, preserving existing content. Behaves like malloc() if ptr is nil; behaves like free() if size <= 0. */
realloc :: proc(ptr: rawptr, size: c.int) -> rawptr ---
/* Like realloc() but accepts a 64-bit size. */
realloc64 :: proc(ptr: rawptr, size: c.uint64_t) -> rawptr ---
/* Releases memory obtained from malloc() or realloc(). No-op if ptr is nil. */
free :: proc(ptr: rawptr) ---
/* Returns the byte size of a live allocation obtained from malloc() or realloc(). */
msize :: proc(ptr: rawptr) -> c.uint64_t ---
/* Returns the number of bytes of heap memory currently allocated by SQLite. */
memory_used :: proc() -> c.int64_t ---
/* Returns the peak heap usage since the high-water mark was last reset. Pass reset=1 to reset the mark to the current usage and return the prior peak. */
memory_highwater :: proc(reset: c.int) -> c.int64_t ---
/*
Sets an advisory soft heap limit. SQLite tries to stay below this threshold by
shrinking page caches, but will exceed it rather than return Nomem.
Returns the prior limit; pass n < 0 to query without changing.
*/
soft_heap_limit64 :: proc(n: c.int64_t) -> c.int64_t ---
/* Sets a hard upper bound on heap allocations. Requests exceeding this limit fail with Nomem. Returns the prior limit; pass n < 0 to query. */
hard_heap_limit64 :: proc(n: c.int64_t) -> c.int64_t ---
/* Attempts to free up to n bytes from SQLite's page caches. Returns bytes actually freed. Requires SQLITE_ENABLE_MEMORY_MANAGEMENT at compile time. */
release_memory :: proc(n: c.int) -> c.int ---
/*
Retrieves a global SQLite runtime statistic identified by op. current receives
the present value; highwater receives the peak value. Pass reset=1 to reset the
highwater mark to the current value after reading.
*/
status :: proc(op: StatusOp, current: ^c.int, highwater: ^c.int, reset: c.int) -> c.int ---
/* Like status() but writes 64-bit values to avoid overflow for large counters. */
status64 :: proc(op: StatusOp, current: ^c.int64_t, highwater: ^c.int64_t, reset: c.int) -> c.int ---
/* Retrieves a per-connection statistic for db identified by op. current and highwater receive the values. Pass reset=1 to reset the highwater mark. */
db_status :: proc(db: Connection, op: DbStatusOp, current: ^c.int, highwater: ^c.int, reset: c.int) -> c.int ---
/* Enables (onoff=1) or disables (onoff=0) the ability to load SQLite extensions at runtime. Extension loading is disabled by default for security. */
enable_load_extension :: proc(db: Connection, onoff: c.int) -> c.int ---
/*
Loads the SQLite extension from file, calling entry_point as the init function
(or the default entry point if nil). On failure, *errmsg receives a malloc-
allocated error string that the caller must free with free().
*/
load_extension :: proc(db: Connection, file: cstring, entry_point: cstring, errmsg: ^cstring) -> c.int ---
/* Registers an entry-point function to be invoked automatically for every new database connection, enabling statically linked extensions to auto-load. */
auto_extension :: proc(entry_point: rawptr) -> c.int ---
/* Removes a previously registered auto-extension entry point. */
cancel_auto_extension :: proc(entry_point: rawptr) -> c.int ---
/* Clears all auto-extension registrations. */
reset_auto_extension :: proc() ---
/* Returns the value of URI query parameter param from the given database filename, or nil if the parameter is not present. */
uri_parameter :: proc(filename: cstring, param: cstring) -> cstring ---
/* Interprets URI query parameter param as a boolean. Returns 1 for "yes"/"true"/"on"/non-zero, 0 for "no"/"false"/"off"/zero, or default_val if absent. */
uri_boolean :: proc(filename: cstring, param: cstring, default_val: c.int) -> c.int ---
/* Converts URI query parameter param to a 64-bit integer, or returns default_val if the parameter is absent or cannot be parsed as an integer. */
uri_int64 :: proc(filename: cstring, param: cstring, default_val: c.int64_t) -> c.int64_t ---
/* Returns the name of the n-th URI query parameter (0-based), or nil if n is out of bounds. Useful for iterating all parameters in a URI filename. */
uri_key :: proc(filename: cstring, n: c.int) -> cstring ---
/* Returns a pointer to the SQLite version string, e.g. "3.45.0". */
libversion :: proc() -> cstring ---
/* Returns the SQLite version as an integer, e.g. 3045000 for version 3.45.0. */
libversion_number :: proc() -> c.int ---
/* Returns the SQLite source ID string identifying the exact source code check-in. */
sourceid :: proc() -> cstring ---
/* Returns 1 if compile-time option name was enabled, 0 otherwise. The "SQLITE_" prefix may be omitted from name. */
compileoption_used :: proc(name: cstring) -> c.int ---
/* Returns the n-th (0-based) compile-time option name string, or nil when n is out of range. Does not include the "SQLITE_" prefix. */
compileoption_get :: proc(n: c.int) -> cstring ---
/* Returns non-zero if SQLite was compiled with mutex support enabled. */
threadsafe :: proc() -> c.int ---
/* Initializes the SQLite library and allocates global resources. Thread-safe and idempotent; subsequent calls after the first are no-ops. */
initialize :: proc() -> c.int ---
/* Deallocates resources allocated by initialize(). Not thread-safe; must only be called from a single thread after all database connections have been closed. */
shutdown :: proc() -> c.int ---
/*
Returns 1 if sql ends with a syntactically complete SQL statement (ends with a
semicolon not inside a string or comment), 0 if incomplete, or Nomem on
allocation failure.
*/
complete :: proc(sql: cstring) -> c.int ---
/* Suspends the current thread for at least ms milliseconds. Returns the actual millisecond count requested from the OS (may be rounded up). */
sleep :: proc(ms: c.int) -> c.int ---
/* Fills buf with n bytes of pseudo-random data from SQLite's internal PRNG, which is also used for the random() and randomblob() SQL functions. */
randomness :: proc(n: c.int, buf: rawptr) ---
/* Attempts to free heap memory associated with db without requiring the SQLITE_ENABLE_MEMORY_MANAGEMENT compile-time option. */
db_release_memory :: proc(db: Connection) -> c.int ---
/* Flushes dirty pages from the in-memory page cache to disk within an open write-transaction, without committing or rolling back the transaction. */
db_cacheflush :: proc(db: Connection) -> c.int ---
}