Module esqlite3

Erlang API for sqlite3 databases.

Copyright © 2011 - 2017 Maas-Maarten Zeeman

Authors: Maas-Maarten Zeeman (mmzeeman@xs4all.nl).

Description

Erlang API for sqlite3 databases

Data Types

cell_type()

cell_type() = undefined | integer() | binary() | float()

connection()

connection() = {connection, reference(), term()}

row()

row() = tuple()

tuple of cell_type

rowid()

rowid() = integer()

sql()

sql() = iodata()

statement()

statement() = {statement, term(), connection()}

Function Index

bind/2Bind values to prepared statements.
bind/3Bind values to prepared statements.
changes/1Return the number of affected rows of last statement.
changes/2
close/1Close the database.
close/2Close the database.
column_names/1Return the column names of the prepared statement.
column_names/2
column_types/1Return the column types of the prepared statement.
column_types/2
exec/2Execute Sql statement.
exec/3
fetchall/1Fetch all records.
fetchall/2Fetch all records.
fetchall/3Fetch all records.
fetchone/1
flush/0Flush any stale answers left in the mailbox of the current process.
foreach/3Execute statement and call F with each row.
foreach/4Execute statement, bind args and call F with each row.
get_autocommit/1Check if the connection is in auto-commit mode.
get_autocommit/2Like autocommit/1, but with an extra timeout attribute.
insert/2Insert records, returns the last rowid.
map/3Execute statement and return a list with the result of F for each row.
map/4Execute statement, bind args and return a list with the result of F for each row.
open/1Opens a sqlite3 database mentioned in Filename.
open/2Like open/1, but with an additional timeout.
prepare/2Compile a SQL statement.
prepare/3Like prepare/2, but with an extra timeout value.
q/2Execute a sql statement, returns a list with tuples.
q/3Execute statement, bind args and return a list with tuples as result.
q/4Execute statement, bind args and return a list with tuples as result restricted by timeout.
reset/1Reset the prepared statement back to its initial state.
set_update_hook/2Subscribe to database notifications.
set_update_hook/3Same as set_update_hook, but with an additional timeout parameter.
step/1Step.
step/2.

Function Details

bind/2

bind(Stmt::statement(), Args::[cell_type()]) -> ok | {error, term()}

Bind values to prepared statements

bind/3

bind(X1::statement(), Args::[cell_type()], Timeout::timeout()) -> ok | {error, term()}

Bind values to prepared statements

changes/1

changes(Connection::connection()) -> non_neg_integer()

Return the number of affected rows of last statement.

changes/2

changes(X1::connection(), Timeout::timeout()) -> non_neg_integer()

close/1

close(Connection::connection()) -> ok | {error, term()}

Close the database

close/2

close(X1::connection(), Timeout::timeout()) -> ok | {error, term()}

Close the database

column_names/1

column_names(Stmt::statement()) -> {atom()}

Return the column names of the prepared statement.

column_names/2

column_names(X1::statement(), Timeout::timeout()) -> {atom()}

column_types/1

column_types(Stmt::statement()) -> {atom()}

Return the column types of the prepared statement.

column_types/2

column_types(X1::statement(), Timeout::timeout()) -> {atom()}

exec/2

exec(Sql::sql(), Connection::connection()) -> ok | {error, term()}

Execute Sql statement.

exec/3

exec(Sql::sql(), Params::[cell_type()], Connection::connection()) -> ok | {error, term()}

fetchall/1

fetchall(Statement::statement()) -> [tuple()] | {error, term()}

Statement: is prepared sql statement

Fetch all records

fetchall/2

fetchall(Statement::statement(), ChunkSize::pos_integer()) -> [tuple()] | {error, term()}

Statement: is prepared sql statement
ChunkSize: is a count of rows to read from sqlite and send to erlang process in one bulk. Decrease this value if rows are heavy. Default value is 5000 (DEFAULT_CHUNK_SIZE).

Fetch all records

fetchall/3

fetchall(Statement::statement(), ChunkSize::pos_integer(), Timeout::timeout()) -> [tuple()] | {error, term()}

Statement: is prepared sql statement
ChunkSize: is a count of rows to read from sqlite and send to erlang process in one bulk. Decrease this value if rows are heavy. Default value is 5000 (DEFAULT_CHUNK_SIZE).
Timeout: is timeout per each request of the one bulk

Fetch all records

fetchone/1

fetchone(Statement::statement()) -> tuple()

flush/0

flush() -> ok

Flush any stale answers left in the mailbox of the current process. This can happen if there has been a timeout. Normally the nif functions are called with the default 'infinite' timeout, so calling this is not needed.

foreach/3

foreach(F, Sql::sql(), Connection::connection()) -> ok

Execute statement and call F with each row.

foreach/4

foreach(F, Sql::sql(), Args::list(), Connection::connection()) -> ok

Execute statement, bind args and call F with each row.

get_autocommit/1

get_autocommit(Connection::connection()) -> true | false

Check if the connection is in auto-commit mode. See: https://sqlite.org/c3ref/get_autocommit.html for more details.

get_autocommit/2

get_autocommit(X1::connection(), Timeout::timeout()) -> true | false

Like autocommit/1, but with an extra timeout attribute.

insert/2

insert(Sql::sql(), Connection::connection()) -> {ok, rowid()} | {error, term()}

Insert records, returns the last rowid.

map/3

map(F, Sql::sql(), Connection::connection()) -> [Type]

Execute statement and return a list with the result of F for each row.

map/4

map(F, Sql::sql(), Args::list(), Connection::connection()) -> [Type]

Execute statement, bind args and return a list with the result of F for each row.

open/1

open(Filename::string()) -> {ok, connection()} | {error, term()}

Opens a sqlite3 database mentioned in Filename.

The standard supplied sqlite3 library supports uri filenames, which makes it possible to open the connection to the database in read-only mode. More information about this can be found here: https://sqlite.org/uri.html

Example:

     open("file:data.db")
Opens "data.db" in the current working directory
     open("file:data.db?mode=ro&cache=private")
Opens "data.db" in read only mode with a private cache
     open("file:memdb1?mode=memory&cache=shared")
Opens a shared memory database named memdb1 with a shared cache.

open/2

open(Filename::string(), Timeout::timeout()) -> {ok, connection()} | {error, term()}

Like open/1, but with an additional timeout.

prepare/2

prepare(Sql::sql(), Connection::connection()) -> {ok, statement()} | {error, term()}

Compile a SQL statement. Returns a cached compiled statement which can be used in queries.

prepare/3

prepare(Sql::sql(), C::connection(), Timeout::timeout()) -> {ok, statement()} | {error, term()}

Like prepare/2, but with an extra timeout value.

q/2

q(Sql::sql(), Connection::connection()) -> [tuple()] | {error, term()}

Execute a sql statement, returns a list with tuples.

q/3

q(Sql::sql(), Args::list(), Connection::connection()) -> [tuple()] | {error, term()}

Execute statement, bind args and return a list with tuples as result.

q/4

q(Sql::sql(), Args::list(), Connection::connection(), Timeout::timeout()) -> [row()] | {error, term()}

Execute statement, bind args and return a list with tuples as result restricted by timeout.

reset/1

reset(X1::statement()) -> ok | {error, term()}

Reset the prepared statement back to its initial state.

set_update_hook/2

set_update_hook(Pid::pid(), Connection::connection()) -> ok | {error, term()}

Subscribe to database notifications. When rows are inserted deleted or updates, the process will receive messages:

     {insert, string(), rowid()}
When a new row has been inserted.
     {delete, string(), rowid()}
When a new row has been deleted.
     {update, string(), rowid()}
When a row has been updated.

set_update_hook/3

set_update_hook(Pid::pid(), X2::connection(), Timeout::timeout()) -> ok | {error, term()}

Same as set_update_hook, but with an additional timeout parameter.

step/1

step(Stmt::statement()) -> tuple() | '$busy' | '$done'

Step

step/2

step(X1::statement(), Timeout::timeout()) -> tuple() | '$busy' | '$done'


Generated by EDoc