Capy-Bearer Documentation

sqlite_query

host call

Capy

function sqlite_query(handle : u64, query : string) any
function sqlite_query(handle : u64, query : string, params : any) any

Description

Use sqlite_query to run one SQL statement. Use :name placeholders with a map of string values. Convert numeric arguments to strings before you put them in the map. Non-string parameter values can trap before the query runs, without a query status.

The runtime binds supplied values as SQL text. A missing named parameter binds SQL NULL. Positional ? placeholders and additional SQL statements fail.

Read sqlite_info(db, "error") immediately after the call. Success reports ok, not an empty string. A later query replaces this status.

Each selected column remains present. SQL NULL becomes none. Use has(row, key) to distinguish a selected NULL from a missing column. SQLite INTEGER values use exact s64 values. REAL values use f64. TEXT and BLOB values use byte-preserving strings, including embedded NUL bytes.

Return Values

Rows indexed from zero, with a map of named columns per row. A result without rows does not by itself indicate failure.

Example

Capy

var db := sqlite_connect(":memory:").value ?? u64(0)
var rows := sqlite_query(db, "select :name as name", {"name": "Ada"})
var status := string(sqlite_info(db, "error"))
if status == "ok"
{
	print(rows[0].name, "\n")
}
else
{
	print("query failed: ", status, "\n")
}
sqlite_disconnect(db)

Output

Ada