A high-level wrapper around sqlite3, with automatic resource management, iteration via fold and/or conversion to lists, and SQL statements as s-expressions.
The fundamental sqlite3 result iterator. Executesstmt-obj
on db, binding vals first if given. Then iterates on
the results, each time calling kons with two arguments,
stmt and the current accumulator, which starts as
knil. stmt-obj can be a prepared statement, a string
to parse into a statement, or an SSQL sexp.Executes stmt on db, binding vals first if
given. Returns all results as a list, where each row is a vector.Executes stmt on db, similar to sqlite3-exec
but binding vals first if given. Returns an unspecified
value.Executes stmt on db, binding vals first if
given. Returns the first column of the first result.Example:
(let ((db (sqlite3-open ":memory:")))
(sqlite3-do db '(create (table animals)
(columns (name (varchar 64))
(color (varchar 64))
(weight int))))
(sqlite3-do db '(insert (into animals)
(columns name color weight)
(values #("cat" "black" 3)
#("dog" "white" 5)
#("pink" "elephant" 3000))))
(sqlite3-select db '(select (columns name color)
(from animals)
(where (< weight 10))
(order name))))
=> (#("cat" "black") #("dog" "white"))(select (columns ...) ...), then the names of the columns
are bound with their corresponding values in body.
Syntax for a procedure of n arguments, to applied to the given
query, which must be of the form (select (columns ...)
...). vars are initialized to their correspnding
inits, and for each result of the query are updated to the
steps, as with the do syntax. Within the
steps, the named columns are bound to the SQL results as in
sqlite3-lambda. When all rows have been processed,
returns result, which defaults to the current values of all
vars.
Example:
(let ((db (sqlite3-open ":memory:")))
(sqlite3-do db '(create (table animals)
(columns (name (varchar 64))
(color (varchar 64))
(weight int))))
(sqlite3-do db '(insert (into animals)
(columns name color weight)
(values #("cat" "black" 3)
#("dog" "white" 5)
#("pink" "elephant" 3000))))
(let ((f (sqlite3-loop db (select (columns name color)
(from animals)
(where (< weight ?))
(order (desc name)))
((res '() (cons (string-append color " " name) res))))))
(f 10)))
=> ("black cat" "white dog")ith argument of stmt to val.Binds the arguments of stmt to vals, in order.Returns the colth column of the current result of stmt.Returns all columns of the current result of stmt as a vector.Sqlite constants.A connection to an sqlite3 database. Closes on gc.A prepared sqlite3 statement. Finalizes on gc.Return the last error message from the db.Open a connection to a new sqlite3 database. Note if string is
":memory:" opens an anonymous in-memory database.Executes a single SQL string on the database.Returns a new prepared SQL statement from the string.Bind an integer value to the given argument of the statement.Bind an real value to the given argument of the statement.Bind a string value to the given argument of the statement.Bind a bytevector value to the given argument of the statement.Resets any bindings and results of the given statement.Advance to the next result of the statement. If a new or reset
statement, executes it with the current bindings and advances to
the first result.Returns the number of columns in the statement results.Returns the SQL type of the ith columns of the statement results.Returns the ith column of the current result as an integer.Returns the ith column of the current result as a real.Returns the ith column of the current result as a string.Returns the ith column of the current result as a bytevector.Returns the size in bytes of the ith column of the current result.