sqlite3_prepare_v2
Compiles a SQL statement into a bytecode program ready for execution.
Open database connection.
The SQL statement to compile (UTF-8).
Length of
sql in bytes, or -1 to read until the first NUL byte.Output pointer that receives the prepared statement handle. Set to
NULL if the input is an empty or whitespace-only string.If not
NULL, set to the first byte past the end of the first parsed statement. Useful for parsing multiple statements from a single string.SQLITE_OK on success.
sqlite3_step
Evaluates the prepared statement one step. Call repeatedly to iterate through result rows.
A prepared statement.
SQLITE_ROW— a new result row is available; read it withsqlite3_column_*.SQLITE_DONE— the statement has finished executing successfully.- Any other code — an error occurred.
sqlite3_finalize
Destroys a prepared statement and releases all resources. Must be called for every statement created by sqlite3_prepare_v2.
The statement to destroy. Passing
NULL is a no-op.SQLITE_OK, or the error code from the last evaluation if the statement encountered an error.
Column count and names
sqlite3_column_count
Returns the number of columns in the result set.
int — number of columns. Returns 0 for statements that do not return rows (e.g. INSERT).
sqlite3_column_name
Returns the name of the column at zero-based index idx.
const char * — UTF-8 column name. Valid until the next call to this function or until the statement is finalized.
sqlite3_column_decltype
Returns the declared type of the column (as written in the CREATE TABLE statement).
const char * or NULL if the column is an expression without a declared type.
sqlite3_column_type
Returns the storage class of the value in the current row for column idx.
SQLITE_INTEGER (1), SQLITE_FLOAT (2), SQLITE_TEXT (3), SQLITE_BLOB (4), SQLITE_NULL (5).
Reading column values
Call these aftersqlite3_step() returns SQLITE_ROW. All functions take a zero-based column index.
sqlite3_column_int64
sqlite3_column_double
sqlite3_column_text
sqlite3_column_blob
sqlite3_column_bytes
Binding parameters
Bind values to? placeholders using 1-based index. Always call sqlite3_reset() before rebinding a statement for re-use.
sqlite3_bind_int64
sqlite3_bind_double
sqlite3_bind_text
SQLITE_STATIC if the string will outlive the statement, or SQLITE_TRANSIENT for Turso to make a copy.
sqlite3_bind_blob
sqlite3_bind_null
SQLITE_OK on success.