Module esqlite3

Erlang API for sqlite3 databases.

Copyright © 2011 - 2022 Maas-Maarten Zeeman

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

Description

Erlang API for sqlite3 databases

Data Types

cell()

cell() = esqlite3_nif:cell()

error()

error() = esqlite3_nif:error()

esqlite3()

esqlite3() = #esqlite3{db = esqlite3_nif:esqlite3_ref()}

esqlite3_backup()

esqlite3_backup() = #esqlite3_backup{backup = esqlite3_nif:esqlite3_backup_ref()}

esqlite3_stmt()

esqlite3_stmt() = #esqlite3_stmt{stmt = esqlite3_nif:esqlite3_stmt_ref()}

prepare_flags()

prepare_flags() = persistent | no_vtab

row()

row() = esqlite3_nif:row()

rowid()

rowid() = esqlite3_nif:rowid()

sql()

sql() = esqlite3_nif:sql()

stats()

stats() = #{used := non_neg_integer(), highwater := non_neg_integer()}

status_info()

status_info() = #{memory_used => stats(), pagecache_used => stats(), pagecache_overflow => stats(), malloc_size := stats(), parser_stack := stats(), pagecache_size := stats(), malloc_count := stats()}

Function Index

open/1Opens a sqlite3 database mentioned in Filename.
close/1Close the database.
error_info/1Return a description of the last occurred error.
interrupt/1Interrupt a long running query.
set_update_hook/2Subscribe to database notifications.
q/2Execute a sql statement, returns the result as list rows.
q/3Execute statement, bind args and return a list rows.
fetchall/1Fetch all rows from the prepared statement.
last_insert_rowid/1Get the last inserted rowid.
changes/1Get the number of changes in the most recent INSERT, UPDATE or DELETE.
get_autocommit/1Check if the connection is in auto-commit mode.
exec/2Compile a SQL statement.
prepare/2Compile a SQL statement.
prepare/3Compile a SQL statement.
bind/2Bind an array of values as parameters of a prepared statement.
bind_int/3
bind_int64/3
bind_double/3
bind_text/3
bind_blob/3
bind_null/2
step/1
reset/1Reset the prepared statement.
column_names/1Return the column names of the prepared statement.
column_decltypes/1Return the column types of the prepared statement.
backup_init/4Initialize a backup procedure.
backup_finish/1Release the resources held by the backup.
backup_step/2Do a backup step.
backup_remaining/1Get the remaining number of pages which need to be backed up.
backup_pagecount/1Get the remaining number of pages which need to be backed up.
status/0Get all internal status information from sqlite.
status/1Specify which internal status information you need, when true is passed, the highwater information from the status information will be reset.
status/2

Function Details

open/1

open(Filename) -> OpenResult

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.

close/1

close(Connection) -> CloseResult

Close the database

error_info/1

error_info(Connection) -> ErrorInfo

Return a description of the last occurred error.

interrupt/1

interrupt(Connection) -> Result

Interrupt a long running query. See https://sqlite.org/c3ref/interrupt.html for more details.

set_update_hook/2

set_update_hook(Connection, Pid) -> Result

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

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

q/2

q(Connection, Sql) -> Result

Execute a sql statement, returns the result as list rows.

q/3

q(Connection, Sql, Args) -> Result

Execute statement, bind args and return a list rows.

fetchall/1

fetchall(Statement) -> Result

Fetch all rows from the prepared statement.

last_insert_rowid/1

last_insert_rowid(Connection) -> RowidResult

Get the last inserted rowid. See https://sqlite.org/c3ref/set_last_insert_rowid.html for more details.

changes/1

changes(Connection) -> ChangesResult

Get the number of changes in the most recent INSERT, UPDATE or DELETE. See https://sqlite.org/c3ref/changes.html for more details.

get_autocommit/1

get_autocommit(Connection) -> AutocommitResult

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

exec/2

exec(Connection, Sql) -> ExecResult

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

prepare/2

prepare(Connection, Sql) -> PrepareResult

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

prepare/3

prepare(Connection, Sql, PrepareFlags) -> PrepareResult

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

bind/2

bind(Statement, Args) -> Result

Bind an array of values as parameters of a prepared statement

bind_int/3

bind_int(Statement, Index, Value) -> BindResult

bind_int64/3

bind_int64(Statement, Index, Value) -> BindResult

bind_double/3

bind_double(Statement, Index, Value) -> BindResult

bind_text/3

bind_text(Statement, Index, Value) -> BindResult

bind_blob/3

bind_blob(Statement, Index, Value) -> BindResult

bind_null/2

bind_null(Statement, Index) -> BindResult

step/1

step(Statement) -> StepResult

reset/1

reset(Statement) -> ResetResult

Reset the prepared statement.

column_names/1

column_names(Statement) -> Names

Return the column names of the prepared statement.

column_decltypes/1

column_decltypes(Statement) -> Types

Return the column types of the prepared statement.

backup_init/4

backup_init(Esqlite3::esqlite3(), DestName::iodata(), X3::esqlite3(), SrcName::iodata()) -> {ok, esqlite3_backup()} | {error, term()}

Initialize a backup procedure. See https://sqlite.org/backup.html for more details on the backup api.

backup_finish/1

backup_finish(Backup) -> Result

Release the resources held by the backup.

backup_step/2

backup_step(Esqlite3_backup::esqlite3_backup(), NPage::integer()) -> ok | '$done' | error()

Do a backup step.

backup_remaining/1

backup_remaining(Backup) -> Remaining

Get the remaining number of pages which need to be backed up.

backup_pagecount/1

backup_pagecount(Backup) -> Pagecount

Get the remaining number of pages which need to be backed up.

status/0

status() -> StatusInfo

Get all internal status information from sqlite.

status/1

status(ArgsOrResetHighWater) -> Status

Specify which internal status information you need, when true is passed, the highwater information from the status information will be reset.

status/2

status(Args, ResetHighWater) -> any()


Generated by EDoc