API referencestd/db

std/db/sqlite

Public declarations, types, methods, and source contracts for std/db/sqlite.

On this page

Library guide · API index and notation

This page is generated from the bundled library in this checkout. Signatures and adjacent source comments are reproduced below; the linked guide explains usage, storage, failures, and platform support.

import "std/db/sqlite"

Names used in signatures

Unqualified names denote this package’s types (including other source files in the same package), language built-ins, or generic parameters such as T. Qualified names use the import aliases below. These aliases belong to the library source; import a dependency yourself to use its alias in your program.

Alias Package Source file
db std/db api.dodo, btree.dodo, datetime.dodo, dbs.dodo, ddl.dodo, dml.dodo, engine.dodo, expr.dodo, func.dodo, open.dodo, pager.dodo, parse.dodo, pragma.dodo, schema.dodo, select.dodo, select_exec.dodo, stmt.dodo, trigger.dodo, utf16.dodo, value.dodo, wal.dodo, window.dodo, wr.dodo
error std/platform/error dbs.dodo, pager.dodo, wal.dodo
fs std/fs dbs.dodo, engine.dodo, open.dodo, pager.dodo, wal.dodo
hosted std/time/hosted datetime.dodo
math std/math engine.dodo
mem core/mem api.dodo, dbs.dodo, engine.dodo, open.dodo, pager.dodo, stmt.dodo, wal.dodo
platform std/platform dbs.dodo, open.dodo, pager.dodo, wal.dodo
ptr core/ptr engine.dodo
sql std/db/sql api.dodo
text std/text api.dodo
thread std/thread pager.dodo, wal.dodo

Options

Struct · Source

pub struct Options {
    pub read_only: bool
    pub create: bool
    // How long to wait for another process's conflicting lock before
    // failing with ErrorKind.Busy (0 = fail immediately).
    pub busy_timeout_ms: u32
    // Page size for a newly created database file.
    pub page_size: u32
}

Options.new

Function · Source

pub fn new() -> Options

Statement

Struct · Source

A prepared statement handle. It stays valid until finalized or until the connection reuses its slot (prepared statements are cached in a fixed number of slots; preparing more evicts the least recently used one).

pub struct Statement {
    // Private implementation fields omitted.
}

STATEMENT_SLOTS

Constant · Source

pub const STATEMENT_SLOTS: usize = 7

Connection

Struct · Source

pub struct Connection {
    // Private implementation fields omitted.
}

Connection.open

Function · Source

pub fn open(path: &str, workspace: &mut[u8]) -> Connection!db.Error from(workspace)

Connection.open_memory

Function · Source

pub fn open_memory(workspace: &mut[u8]) -> Connection!db.Error from(workspace)

Connection.open_with

Function · Source

pub fn open_with(path: &str, workspace: &mut[u8], options: &Options) -> Connection!db.Error from(workspace)

Connection.close

Function · Source

Closes the database. Uncommitted work is rolled back.

pub fn close(&mut self) -> void!db.Error

Connection.message

Function · Source

Text of the most recent error, in SQLite’s wording.

pub fn message(&self) -> &str

Connection.changes

Function · Source

pub fn changes(&self) -> u64

Connection.total_changes

Function · Source

pub fn total_changes(&self) -> u64

Connection.last_insert_rowid

Function · Source

pub fn last_insert_rowid(&self) -> i64

Connection.in_transaction

Function · Source

True inside BEGIN … COMMIT/ROLLBACK.

pub fn in_transaction(&self) -> bool

Connection.set_crash_point_for_testing

Function · Source

Test hook for crash-recovery tests: the process aborts at point of the next multi-file commit (1: super-journal written, 2: first database file written, 3: all files written, 4: super-journal deleted). 0 disables it.

pub fn set_crash_point_for_testing(&mut self, point: u32)

Connection.set_busy_timeout

Function · Source

Waits up to milliseconds for other processes’ locks (like sqlite3_busy_timeout).

pub fn set_busy_timeout(&mut self, milliseconds: u32)

Connection.exec

Function · Source

Runs every statement in sql, discarding result rows.

pub fn exec(&mut self, sql: &str) -> void!db.Error

Connection.statement_length

Function · Source

Length in bytes of the first statement of sql, including its terminating semicolon and trailing whitespace (like the tail pointer of sqlite3_prepare). Zero when sql holds no statement.

pub fn statement_length(&mut self, sql: &str) -> usize!db.Error

Connection.execute

Function · Source

Runs one statement and returns the number of rows it changed.

pub fn execute(&mut self, sql: &str, params: &[db.Value]) -> u64!db.Error

Connection.query

Function · Source

Runs one statement and passes each row to sink.

pub fn query(&mut self, sql: &str, params: &[db.Value], sink: &mut dyn sql.RowSink) -> void!db.Error

Connection.begin

Function · Source

pub fn begin(&mut self, level: db.IsolationLevel) -> void!db.Error

Connection.commit

Function · Source

pub fn commit(&mut self) -> void!db.Error

Connection.rollback

Function · Source

pub fn rollback(&mut self) -> void!db.Error

Connection.select

Function · Source

Runs a query and returns a cursor over its rows. Rows borrow the connection; the statement completes when the cursor is exhausted or dropped.

pub fn select(&mut self, sql: &str, params: &[db.Value]) -> Rows!db.Error

Connection.prepare

Function · Source

Prepares a statement for repeated execution.

pub fn prepare(&mut self, sql: &str) -> Statement!db.Error

Connection.finalize

Function · Source

Releases a prepared statement’s slot.

pub fn finalize(&mut self, stmt: Statement)

Connection.run

Function · Source

Executes a prepared statement, returning the number of changed rows.

pub fn run(&mut self, stmt: &Statement, params: &[db.Value]) -> u64!db.Error

Connection.rows

Function · Source

Executes a prepared query and returns a cursor over its rows.

pub fn rows(&mut self, stmt: &Statement, params: &[db.Value]) -> Rows!db.Error

Connection.column_count

Function · Source

Number of result columns of a prepared statement.

pub fn column_count(&self, stmt: &Statement) -> usize

Connection.parameter_count

Function · Source

Number of parameters of a prepared statement (the largest index).

pub fn parameter_count(&self, stmt: &Statement) -> usize

Connection.parameter_index

Function · Source

1-based index of a named parameter (“:name”, “@name”, “$name”), or 0.

pub fn parameter_index(&self, stmt: &Statement, name: &str) -> usize

Rows

Struct · Source

A cursor over the rows of a running statement.

pub struct Rows {
    // Private implementation fields omitted.
}

Rows.next

Function · Source

Advances to the next row; none at the end.

pub fn next(&mut self) -> Option<Row>!db.Error

Rows.len

Function · Source

pub fn len(&self) -> usize

Row

Struct · Source

One result row. Text and blob values borrow the workspace and stay valid until the cursor advances.

pub struct Row {
    // Private implementation fields omitted.
}

Row.len

Function · Source

pub fn len(&self) -> usize

Row.name

Function · Source

pub fn name(&self, index: usize) -> &str

Row.get

Function · Source

pub fn get(&self, index: usize) -> db.Value!db.Error

Row.is_null

Function · Source

pub fn is_null(&self, index: usize) -> bool

Row.value_type

Function · Source

pub fn value_type(&self, index: usize) -> db.ValueType

Row.int

Function · Source

Integer value with SQLite’s conversion rules (NULL is 0).

pub fn int(&self, index: usize) -> i64

Row.real

Function · Source

Real value with SQLite’s conversion rules (NULL is 0.0).

pub fn real(&self, index: usize) -> f64

Row.text

Function · Source

Text value: empty for NULL and for numbers (use get or text_into to format numbers) and for bytes that are not valid UTF-8.

pub fn text(&self, index: usize) -> &str

Row.bytes

Function · Source

Raw bytes of a text or blob value (empty otherwise).

pub fn bytes(&self, index: usize) -> &[u8]

Row.text_into

Function · Source

Writes the value as text (numbers formatted as SQLite does) into out; returns the length, or none if it does not fit.

pub fn text_into(&self, index: usize, out: &mut[u8]) -> Option<usize>

MIN_WORKSPACE_BYTES

Constant · Source

The smallest workspace for databases with 4096-byte pages (SQLite’s default); see min_workspace_bytes for other page sizes.

pub const MIN_WORKSPACE_BYTES: usize = 434176

WORKSPACE_BYTES

Constant · Source

pub const WORKSPACE_BYTES: usize = 2097152

min_workspace_bytes

Function · Source

The smallest workspace that can open a database with page_size-byte pages (512 to 65536). Larger workspaces cache more pages and hold larger statements, sorts and transactions.

pub fn min_workspace_bytes(page_size: usize) -> usize

SQLITE_VERSION_TEXT

Constant · Source

pub const SQLITE_VERSION_TEXT: &str = "3.45.0"

Search every guide, reference page, and API declaration.