commit - 19e3939cb58be9fc3d590cfe91946c3455a3a6c7
commit + 73419a01ec55ff3eda57c62312d388fe6cffd19d
blob - aae128f2e8a2b83ee5bd1d155da99fd91113fff8
blob + ad6ee451cdf8a0ac43f202053ee12228ca1be30e
--- sqlite3/sqlite3.ha
+++ sqlite3/sqlite3.ha
@symbol("sqlite3_close_v2") fn libsqlite3_close_v2(sqlite3: *opaque) int;
+// Closes a database connection.
export fn close(conn: conn) (void | error) = {
let ret = libsqlite3_close_v2(conn: *opaque);
if (ret != sqlite_ok) {
tail: nullable *opaque,
) int;
+// Prepares a statement that would run the given SQL. Parameters in
+// the query can be specified using ?, ?NNN, :VVV, @VVV or $VVV (with
+// NNN being a integer literal and VVV an alphanumeric identifier) and
+// later set with [[bind]]. The statement can then ran with [[step]].
+// A statement can be reused by calling [[reset]] (and optionally
+// [[clear_bindings]] too). Once a statement is no longer needed it
+// should be destroyed with [[finalize]].
export fn prepare(conn: conn, sql: const str) (statement | error) = {
let s = c::fromstr(sql);
defer free(s);
val: int,
) int;
+// Binds an integer value to the parameter given by name or index.
export fn bind_int(stmt: statement, col: (str | int), v: int) (void | error) = {
let n = bind_parameter_index(stmt, col)?;
let ret = libsqlite3_bind_int(stmt: *opaque, n, v);
col: int,
) int;
+// Binds a NULL value to the parameter given by name or index.
export fn bind_null(stmt: statement, col: (str | int)) (void | error) = {
let n = bind_parameter_index(stmt, col)?;
let ret = libsqlite3_bind_null(stmt: *opaque, n);
freefn: *fn(*opaque) void
) int;
+// Binds a text value to the parameter given by name or index.
export fn bind_text(stmt: statement, col: (str | int), v: str) (void | error) = {
let n = bind_parameter_index(stmt, col)?;
};
};
+// Binds a value to the parameter given by name or index.
export fn bind(
stmt: statement,
col: (str | int),
@symbol("sqlite3_step") fn libsqlite3_step(stmt: *opaque) int;
+// Runs the statement. This function may need to be called more than
+// one time to evaluate a statement. A return value of false means
+// that the statement was completely executed, true that it should be
+// called again, otherwise an error is returned.
export fn step(stmt: statement) (bool | error) = {
let ret = libsqlite3_step(stmt: *opaque);
switch (ret) {
col: int,
) *const c::char;
+// Extracts the value of a column as a string. A NULL value is turned
+// into the empty string "".
export fn column_text(stmt: statement, col: int) const str = {
let s = libsqlite3_column_text(stmt: *opaque, col);
if (s == null) {
col: int,
) int;
+// Extracts the values of a column as an integer.
export fn column_int(stmt: statement, col: int) int = {
return libsqlite3_column_int(stmt: *opaque, col);
};
@symbol("sqlite3_finalize") fn libsqlite3_finalize(stmt: *opaque) int;
+// Deallocates a statement.
export fn finalize(stmt: statement) (void | error) = {
let ret = libsqlite3_finalize(stmt: *opaque);
if (ret != sqlite_ok) {
@symbol("sqlite3_reset") fn libsqlite3_reset(stmt: *opaque) int;
+// Resets a statement so that it can be run again. It doesn't clear
+// the bindings, for that use [[clear_bindings]] too.
export fn reset(stmt: statement) (void | error) = {
let ret = libsqlite3_reset(stmt: *opaque);
if (ret != sqlite_ok) {
@symbol("sqlite3_clear_bindings") fn libsqlite3_clear_bindings(stmt: *opaque) int;
+// Clears the bindings associated with a statement.
export fn clear_bindings(stmt: statement) (void | error) = {
let ret = libsqlite3_clear_bindings(stmt: *opaque);
if (ret != sqlite_ok) {
};
};
+// Helper that runs a statement until it has been fully processed.
export fn runstmt(stmt: statement) (void | error) = {
for (step(stmt)?) {
continue;