Database

An database connection.

This struct is a reference-counted wrapper around a sqlite3* pointer.

Constructors

this
this(string path, int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)

Opens a database connection.

Members

Functions

attachedFilePath
string attachedFilePath(string database = "main")

Gets the path associated with an attached database.

begin
void begin()

Convenience functions equivalent to an SQL statement.

changes
int changes()

Gets the number of database rows that were changed, inserted or deleted by the most recently executed SQL statement.

close
void close()

Explicitly closes the database connection.

commit
void commit()

Convenience functions equivalent to an SQL statement.

config
void config(int code, Args args)

Sets a connection configuration option.

createAggregate
void createAggregate(string name, T agg, Deterministic det = Deterministic.yes)

Creates and registers a new aggregate function in the database.

createCollation
void createCollation(string name, T fun)

Creates and registers a collation function in the database.

createFunction
void createFunction(string name, T fun, Deterministic det = Deterministic.yes)
void createFunction(string name, T fun = null)

Creates and registers a new function in the database.

enableLoadExtensions
void enableLoadExtensions(bool enable = true)

Enables or disables loading extensions.

errorCode
int errorCode()

Gets the SQLite error code of the last operation.

execute
ResultRange execute(string sql, Args args)

Executes a single SQL statement and returns the results directly.

handle
sqlite3* handle()

Gets the SQLite internal handle of the database connection.

interrupt
void interrupt()

Interrupts any pending database operations.

isReadOnly
bool isReadOnly(string database = "main")

Gets the read-only status of an attached database.

lastInsertRowid
long lastInsertRowid()

Returns the rowid of the last INSERT statement.

loadExtension
void loadExtension(string path, string entryPoint = null)

Loads an extension.

prepare
Statement prepare(string sql)

Prepares (compiles) a single SQL statement and returngs it, so that it can be bound to values before execution.

rollback
void rollback()

Convenience functions equivalent to an SQL statement.

run
void run(string script, bool delegate(ResultRange) dg = null)

Runs an SQL script that can contain multiple statements.

setCommitHook
void setCommitHook(CommitHookDelegate commitHook)

Registers a delegate of type CommitHookDelegate as the database's commit hook. Any previously set hook is released.

setProfileCallback
void setProfileCallback(ProfileCallbackDelegate profileCallback)

Registers a delegate of type ProfileCallbackDelegate as the profile callback.

setProgressHandler
void setProgressHandler(int pace, ProgressHandlerDelegate progressHandler)

Registers a delegate of type ProgressHandlerDelegate as the progress handler.

setRollbackHook
void setRollbackHook(RoolbackHookDelegate rollbackHook)

Registers a delegate of type RoolbackHookDelegate as the database's rollback hook.

setTraceCallback
void setTraceCallback(TraceCallbackDelegate traceCallback)

Registers a delegate of type TraceCallbackDelegate as the trace callback.

setUnlockNotifyHandler
void setUnlockNotifyHandler(IUnlockNotifyHandler unlockNotifyHandler)

Registers a IUnlockNotifyHandler used to handle database locks.

setUpdateHook
void setUpdateHook(UpdateHookDelegate updateHook)

Registers a delegate of type UpdateHookDelegate as the database's update hook.

tableColumnMetadata
TableColumnMetadata tableColumnMetadata(string table, string column, string database = "main")

Gets metadata for a specific table column of an attached database.

totalChanges
int totalChanges()

Gets the number of database rows that were changed, inserted or deleted since the database was opened.

waitForUnlockNotify
auto waitForUnlockNotify()

Setup and waits for unlock notify using the provided IUnlockNotifyHandler

Meta