Module raw_sqlite3

Convenience and utility functions for the raw_sqlite3 library.

Description

Convenience and utility functions for the raw_sqlite3 library.

Data Types

query_parameter()

query_parameter() = number() | true | false | nil | undefined | {text, utf8str()} | {blob, iodata()}

sqlite3()

abstract datatype: sqlite3()

A database connection handle.

sqlite3_error_code()

abstract datatype: sqlite3_error_code()

sqlite3 error codes as atoms.

sqlite3_stmt()

abstract datatype: sqlite3_stmt()

A prepared SQL statement.

utf8str()

abstract datatype: utf8str()

A iodata() term which, when serialised, should form a valid UTF8-encoded character string.

Function Index

atom_to_int_flag/1Convert an atom into an integer flag.
bind/2Bind parameters to a prepared statement.
bool_to_int/1Convert boolean values into integers (SQlite uses 0 and 1 for boolean values).
close/1Close database connection.
err_to_atom/1Convert an integer error value into the corresponding error atom.
exec/2Evaluate DDL/DML SQL statement(s).
exec/3Evaluate a DDL/DML SQL statement, binding query parameters.
expand_error/1Convert a sqlite3_nif error, if present, into an error atom.
expand_error/2Convert a sqlite3_nif error, if present, into an error atom and error description.
fetchall/1Evaluate a prepared statement and fetch all results.
fold/4Calls Fun(Elem, Acc) on successive elements of the list formed by evaluating a SQL statement.
fold/5Same as fold/4 but accepts a parameter list.
insert_many/3Insert many values.
int_to_bool/1Convert integer values into booleans (SQlite uses 0 and 1 for boolean values).
make_flags/1Convert a list of atoms into an integer flag.
map/3Transform the result of evaluating a SQL query by applying Fun(Elem).
map/4Same as map/4 but accepts a parameter list.
open/1Open a new database connection.
open/2Open a new database connection with the specified open flags.
open/3Open a new database connection with the specified open flags and the VFS engine.
prepare/2Prepare a statement to use with bind/2, step/1, fetchall/1, fetchall2.
q/2Evaluate an SQL expression and fetch all results.
q/3Evaluate an SQL expression, binding the parameters, and fetch all results.
reset/1Reset a prepared statement.
step/1Evaluate a prepared statement and fetch one result.
with_trxn/2Evaluate F in a transaction.
with_trxn/2

Function Details

atom_to_int_flag/1

atom_to_int_flag(X1::atom) -> integer()

Convert an atom into an integer flag.

bind/2

bind(Stmt, Params) -> Result

Bind parameters to a prepared statement.

bool_to_int/1

bool_to_int(X1::boolean()) -> 0 | 1

Convert boolean values into integers (SQlite uses 0 and 1 for boolean values).

close/1

close(Db) -> Result

Close database connection. NOTE: Usually, it is not necessary to call the function because a garbage collection will destroy the connection object. However, it may be useful to have the explicit control over a connection handle in some situations.

err_to_atom/1

err_to_atom(X1::integer()) -> atom()

Convert an integer error value into the corresponding error atom.

exec/2

exec(Db, Sql) -> Result

Evaluate DDL/DML SQL statement(s).

exec/3

exec(Db, Sql, Params) -> Result

Evaluate a DDL/DML SQL statement, binding query parameters. NOTE: Using more than one SQL statement with non-empty parameter list will most likely result in an error because the function will try to bind the supplied parameter list to every statement.

expand_error/1

expand_error(OK) -> any()

Convert a sqlite3_nif error, if present, into an error atom.

expand_error/2

expand_error(Db, OK) -> any()

Convert a sqlite3_nif error, if present, into an error atom and error description.

fetchall/1

fetchall(Stmt) -> Result

Evaluate a prepared statement and fetch all results.

fold/4

fold(Db, Sql, Fun, Acc0) -> Result

Calls Fun(Elem, Acc) on successive elements of the list formed by evaluating a SQL statement. Fun/2 must return a new accumulator, which is passed to the next call. The function returns the final value of the accumulator or error.

fold/5

fold(Db, Sql, Params, Fun, Acc0) -> Result

Same as fold/4 but accepts a parameter list.

insert_many/3

insert_many(Db, Sql, ParameterList::[Params]) -> Result

Insert many values. The function prepares an DML SQL statement and binds/evaluates it to every element in ParameterList.

int_to_bool/1

int_to_bool(X::integer()) -> boolean()

Convert integer values into booleans (SQlite uses 0 and 1 for boolean values).

make_flags/1

make_flags(Atoms::[atom()]) -> integer()

Convert a list of atoms into an integer flag.

map/3

map(Db, Sql, Fun) -> Result

Transform the result of evaluating a SQL query by applying Fun(Elem). Returns the transformed list or an error.

map/4

map(Db, Sql, Params, Fun) -> Result

Same as map/4 but accepts a parameter list.

open/1

open(DbFile) -> Result

Open a new database connection.

open/2

open(DbFile, Flags) -> Result

Flags: is a combination of open flags OR-ed together. For example ?SQLITE_OPEN_READWRITE bor ?SQLITE_OPEN_CREATE.

Open a new database connection with the specified open flags.

See also: The list of possible flag values.

open/3

open(DbFile, Flags, Vfs) -> Result

Open a new database connection with the specified open flags and the VFS engine. See sqlite3 documentation for details.

prepare/2

prepare(Db, Sql) -> Result

Prepare a statement to use with bind/2, step/1, fetchall/1, fetchall2. NOTE: Only the first statement contained in the query Sql will be prepared. Use sqlite3_nif:sqlite3_prepare_v2/2 if you want to have the remaining statements returned.

q/2

q(Db, Sql) -> Result

Evaluate an SQL expression and fetch all results.

q/3

q(Db, Sql, Params) -> Result

Evaluate an SQL expression, binding the parameters, and fetch all results.

reset/1

reset(Stmt::sqlite3_stmt()) -> ok | {error, sqlite3_error_code()}

Reset a prepared statement.

step/1

step(Stmt) -> Result

Evaluate a prepared statement and fetch one result. A statement should be run till ok is returned. NOTE: a fully evaluated statement is automatically reset if sqlite3_step is called using the statement after it returns ok.

with_trxn/2

with_trxn(Db, F) -> Result

Evaluate F in a transaction. The function automatically rolls back if F throws an error.

with_trxn/2

with_trxn(Db, F) -> any()


Generated by EDoc