Lightweight 0.20261105.1
Loading...
Searching...
No Matches
Statement.hpp File Reference
#include "../../Api.hpp"
#include "../../SqlBindingTypes.hpp"
#include "../../SqlError.hpp"
#include "../Concept.hpp"
#include "Connection.hpp"
#include "Handles.hpp"
#include <chrono>
#include <concepts>
#include <cstddef>
#include <cstdint>
#include <expected>
#include <optional>
#include <source_location>
#include <span>
#include <string>
#include <string_view>
#include <type_traits>

Go to the source code of this file.

Typedefs

using Lightweight::Driver::Sqlite3::OutputReader = SqlResult(*)(Statement &stmt, SqlColumnIndex column, void *target, SqlIndicator *indicator)
 A registered reader: reads one column of the current row into the bound target.
 

Enumerations

enum class  Lightweight::Driver::Sqlite3::StorageClass : std::uint8_t {
  Null , Integer , Float , Text ,
  Blob
}
 The storage class of a SQLite value. More...
 

Functions

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::Allocate (Connection const &connection, Statement &stmt) noexcept
 Creates a statement state registered with connection's state.
 
LIGHTWEIGHT_API void Lightweight::Driver::Sqlite3::Free (Statement &stmt) noexcept
 Finalizes the prepared statement, unregisters the state from its connection and destroys it; leaves stmt empty. An orphaned state (its connection closed) is just destroyed; an empty stmt is left alone.
 
LIGHTWEIGHT_API void Lightweight::Driver::Sqlite3::Abandon (Statement &stmt) noexcept
 Gives up a statement whose connection session ended (the connection was closed or connected again), and leaves stmt empty.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::Prepare (Statement &stmt, std::string_view query, bool wideQueryText)
 Prepares query (sqlite3_prepare_v3), finalizing what the statement held before.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::Execute (Statement &stmt) noexcept
 Executes the prepared statement with the bound parameters.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::ExecuteDirect (Statement &stmt, std::string_view query, bool wideQueryText)
 Runs the statements of query in order, each prepared and executed as Prepare and Execute do.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::Fetch (Statement &stmt) noexcept
 Makes the next row the current one and runs the registered readers on it in column order.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::MoreResults (Statement &stmt) noexcept
 Moves to the next result set of an ExecuteDirect text: closes the current one and runs the pending rest of the text as ExecuteDirect runs a text.
 
LIGHTWEIGHT_API void Lightweight::Driver::Sqlite3::CloseCursor (Statement &stmt) noexcept
 Closes the cursor: resets the statement (bindings stay). The pending rest of an ExecuteDirect text stays pending, for MoreResults. Nothing on an orphaned statement.
 
LIGHTWEIGHT_API void Lightweight::Driver::Sqlite3::DiscardResults (Statement &stmt) noexcept
 Discards the pending results: resets the statement (bindings stay) and runs the pending rest of an ExecuteDirect text to its end or its first failing statement, dropping that failure (Diagnose keeps reporting what it reported before). Nothing on an orphaned statement, whose pending text was dropped unrun.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::UnbindColumns (Statement &stmt) noexcept
 Forgets every registered output reader (RegisterOutputReader).
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::ResetParameters (Statement &stmt) noexcept
 Clears the parameter bindings (sqlite3_clear_bindings): every parameter is NULL until bound again.
 
LIGHTWEIGHT_API void Lightweight::Driver::Sqlite3::ResetParameterArrays (Statement &stmt) noexcept
 Nothing: this driver has no parameter arrays.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::NumResultColumns (Statement const &stmt, std::int16_t &count) noexcept
 The number of result columns of the prepared statement (sqlite3_column_count).
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::NumParameters (Statement const &stmt, std::int16_t &count) noexcept
 The number of parameters of the prepared statement (sqlite3_bind_parameter_count).
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::NumRowsAffected (Statement const &stmt, std::ptrdiff_t &count) noexcept
 The number of rows the statement's last execution changed, known once that execution completed.
 
LIGHTWEIGHT_API std::expected< SqlResultColumnType, SqlErrorInfo > Lightweight::Driver::Sqlite3::ColumnType (Statement const &stmt, SqlColumnIndex column)
 The type of result column column.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::SetQueryTimeout (Statement &stmt, std::chrono::seconds timeout) noexcept
 Accepts a query timeout and stores nothing: as on the ODBC SQLite path it is not enforced.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::QueryTimeout (Statement const &stmt, std::chrono::seconds &timeout) noexcept
 The query timeout: always none.
 
LIGHTWEIGHT_API SqlErrorInfo Lightweight::Driver::Sqlite3::Diagnose (Statement const &stmt)
 The diagnostics of the statement's last failure, captured in its state when the failing call returned (never read later from the connection, where another statement may have replaced it).
 
LIGHTWEIGHT_API void Lightweight::Driver::Sqlite3::RequireSuccess (Statement const &stmt, SqlResult result, std::source_location location=std::source_location::current())
 Throws unless result is a success, as Driver::ClassifyResult decides from Diagnose: std::invalid_argument for 07009, SqlException for any other failure.
 
::Lightweight::Driver::CallOutcome Lightweight::Driver::Sqlite3::CheckResult (Statement const &stmt, SqlResult result, std::source_location location) noexcept
 The non-throwing verdict on result; this driver has no fault seam, so nothing is ever injected.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::OpenCatalog (Statement const &stmt, SqlCatalogRequest const &request) noexcept
 Fails: this driver has no catalog functions (SqlSchema reads its catalog with the SQL of SqlQueryFormatter::CatalogQueries()).
 
constexpr SqlResultColumnType Lightweight::Driver::Sqlite3::CatalogColumnType (Statement const &stmt, int dataType) noexcept
 The type a catalog DATA_TYPE code stands for: none, since this driver opens no catalog result set.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::DescribeColumn (Statement const &stmt, SqlColumnIndex column, SqlColumnDescription &description)
 Describes result column column: its type as ColumnType reports it, and no column size (SQLite does not bound a column's values).
 
constexpr std::optional< std::int16_t > Lightweight::Driver::Sqlite3::DescribeResultColumnSqlType (Statement const &stmt, SqlColumnIndex column) noexcept
 The driver's SQL type code of result column column: none, since this driver's leaf binders read the storage class of the value instead and never ask.
 
LIGHTWEIGHT_API std::size_t Lightweight::Driver::Sqlite3::DeclaredBoundColumnSize (Statement const &stmt, SqlColumnIndex column, SqlOutputColumnLength length) noexcept
 The bound buffer size the declared length of result column column asks for: the default, since this driver fills a bound column afresh for every row and so never cuts a value off.
 
LIGHTWEIGHT_API void Lightweight::Driver::Sqlite3::ResetRowArrayAttributes (Statement &stmt) noexcept
 Nothing: this driver has no row arrays.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::BindUtf16TextParameter (Statement &stmt, std::uint16_t parameter, char16_t *text, std::size_t columnSize, SqlIndicator &lengthIndicator) noexcept
 Binds UTF-16 text to parameter (as BindText16), read from text for lengthIndicator bytes.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::Fail (Statement &stmt, std::string_view sqlState, std::string_view message) noexcept
 Records a failure the driver did not produce itself (a leaf binder's conversion error) as the statement's diagnostic, native error code 0.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::BindNull (Statement &stmt, SqlColumnIndex parameter) noexcept
 Binds SQL NULL to parameter; it counts as bound for Execute (bind unused numbered parameters this way).
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::BindInt64 (Statement &stmt, SqlColumnIndex parameter, std::int64_t value) noexcept
 Binds an integer to parameter, by value.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::BindDouble (Statement &stmt, SqlColumnIndex parameter, double value) noexcept
 Binds a floating-point number to parameter, by value.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::BindText (Statement &stmt, SqlColumnIndex parameter, std::string_view utf8) noexcept
 Binds UTF-8 text to parameter; an empty view binds empty text, never NULL.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::BindText16 (Statement &stmt, SqlColumnIndex parameter, std::u16string_view utf16) noexcept
 Binds UTF-16 text (native byte order) to parameter; referenced or copied as by BindText.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::BindBlob (Statement &stmt, SqlColumnIndex parameter, std::span< std::byte const > bytes) noexcept
 Binds bytes to parameter; referenced or copied as by BindText. Empty bytes bind an empty blob, never NULL.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::ReadInt64 (Statement &stmt, SqlColumnIndex column, std::int64_t &value, SqlIndicator *indicator) noexcept
 Reads result column column of the current row as an integer (SQLite converts other storage classes).
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::ReadDouble (Statement &stmt, SqlColumnIndex column, double &value, SqlIndicator *indicator) noexcept
 Reads result column column of the current row as a floating-point number; as ReadInt64.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::ReadText (Statement &stmt, SqlColumnIndex column, std::string_view &utf8, SqlIndicator *indicator) noexcept
 Reads result column column of the current row as UTF-8 text, without copying it.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::ReadText16 (Statement &stmt, SqlColumnIndex column, std::u16string_view &utf16, SqlIndicator *indicator) noexcept
 Reads result column column of the current row as UTF-16 text (native byte order), without copying it.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::ReadBlob (Statement &stmt, SqlColumnIndex column, std::span< std::byte const > &bytes, SqlIndicator *indicator) noexcept
 Reads result column column of the current row as bytes, without copying them.
 
constexpr SqlResultColumnType Lightweight::Driver::Sqlite3::TypeOfStorageClass (StorageClass storageClass) noexcept
 The driver-neutral type of a value of storageClass, as ColumnType reports a column whose declared type does not name one: Integer is BigInt, Float Double, Text VarChar, Blob VarBinary, Null Unknown.
 
LIGHTWEIGHT_API StorageClass Lightweight::Driver::Sqlite3::ColumnStorageClass (Statement const &stmt, SqlColumnIndex column) noexcept
 The storage class of result column column's value in the row at hand (the pending or the current one).
 
LIGHTWEIGHT_API std::string Lightweight::Driver::Sqlite3::ExpandedSql (Statement const &stmt)
 The prepared SQL text with the values currently bound in place of the parameters (sqlite3_expanded_sql); unbound parameters read NULL.
 
LIGHTWEIGHT_API std::string_view Lightweight::Driver::Sqlite3::ColumnDeclaredType (Statement const &stmt, SqlColumnIndex column) noexcept
 The type result column column is declared with (sqlite3_column_decltype).
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::RegisterOutputReader (Statement &stmt, SqlColumnIndex column, OutputReader reader, void *target, SqlIndicator *indicator) noexcept
 Registers reader as the reader of column, run on every row Fetch makes current.
 
LIGHTWEIGHT_API SqlDataBinderCallback const & Lightweight::Driver::Sqlite3::OutputReaderCallback () noexcept
 The binder callback the readers of RegisterOutputColumn hand to SqlDataBinder<T>::GetColumn.
 
template<typename T >
SqlResult Lightweight::Driver::Sqlite3::RegisterOutputColumn (Statement &stmt, SqlColumnIndex column, T *result, SqlIndicator *indicator) noexcept
 Registers SqlDataBinder<T>::GetColumn as the reader of column, filling result on every row (what every leaf binder's OutputColumn calls). A NULL row leaves result holding T{} (for a type that has one: a disengaged optional, a NULL SqlVariant, 0, an empty string), never the previous row's value.
 

Detailed Description

The statement operations of the SQLite3 driver: the statement half of the Lightweight::Driver::SqlDriver concept, and the typed bind and read functions the leaf data binders call instead of SQLite's own.

A Lightweight::Driver::Sqlite3::Statement is one pointer to a driver-owned StatementState (private State.hpp), registered with its connection's state. SQLite yields the first row on the first step; the driver hides that: Lightweight::Driver::Sqlite3::Execute keeps that row pending and the first Lightweight::Driver::Sqlite3::Fetch hands it out.

Every failure is captured in the statement's state when it happens, so Lightweight::Driver::Sqlite3::Diagnose reports the statement's own failure even after another statement of the same connection succeeded. A statement whose connection is closed (or not open yet) answers Error with SQLSTATE 08003 to every operation that returns a Lightweight::SqlResult.

Parameters and columns are 1-based throughout.

Definition in file Statement.hpp.

Typedef Documentation

◆ OutputReader

using Lightweight::Driver::Sqlite3::OutputReader = typedef SqlResult (*)(Statement& stmt, SqlColumnIndex column, void* target, SqlIndicator* indicator)

A registered reader: reads one column of the current row into the bound target.

Called by Fetch with the statement, the column, and the target and indicator it was registered with. It must store no pointer to anything but its target: the statement owning the handle may move.

Definition at line 541 of file Statement.hpp.

Enumeration Type Documentation

◆ StorageClass

enum class Lightweight::Driver::Sqlite3::StorageClass : std::uint8_t
strong

The storage class of a SQLite value.

Enumerator
Null 

SQL NULL.

Integer 

A signed integer of up to 8 bytes.

Float 

An 8-byte IEEE floating-point number.

Text 

Text.

Blob 

Bytes, stored as given.

Definition at line 467 of file Statement.hpp.

Function Documentation

◆ Allocate()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::Allocate ( Connection const &  connection,
Statement &  stmt 
)
noexcept

Creates a statement state registered with connection's state.

Works on a connection that is allocated but not connected yet: the statement then answers Error 08003 to everything until the connection is open. A stmt that already has a state keeps its memory, but is reset to a new statement's state — prepared statement finalized, readers, bindings, error and row forgotten — and registered with connection instead.

Parameters
connectionThe connection; it must be allocated.
stmtReceives the state.
Returns
Success; Error when connection has no state or memory ran out (stmt is then unchanged).

References Lightweight::Driver::Allocate().

◆ Free()

LIGHTWEIGHT_API void Lightweight::Driver::Sqlite3::Free ( Statement &  stmt)
noexcept

Finalizes the prepared statement, unregisters the state from its connection and destroys it; leaves stmt empty. An orphaned state (its connection closed) is just destroyed; an empty stmt is left alone.

Statements of an ExecuteDirect text still pending are run first, as DiscardResults does, so freeing a statement whose text is not exhausted runs the rest of it rather than dropping it. A statement of it that fails stops the text; its diagnostics are reported to the SqlLogger (OnError), since this function returns nothing.

Parameters
stmtThe statement.

References Lightweight::Driver::Free().

◆ Abandon()

LIGHTWEIGHT_API void Lightweight::Driver::Sqlite3::Abandon ( Statement &  stmt)
noexcept

Gives up a statement whose connection session ended (the connection was closed or connected again), and leaves stmt empty.

Usually ending the session finalized the native statement and orphaned the state, which the statement still owns. The state may also still be attached to an open database (that of a moved-from SqlConnection, now owned by another): this is Free without running a pending ExecuteDirect text — the rest is dropped unrun, so nothing of the connection is touched.

Parameters
stmtThe statement; may be empty.

References Lightweight::Driver::Abandon().

◆ Prepare()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::Prepare ( Statement &  stmt,
std::string_view  query,
bool  wideQueryText 
)

Prepares query (sqlite3_prepare_v3), finalizing what the statement held before.

Statements of an earlier ExecuteDirect text still pending are run first, as DiscardResults does. Prepares exactly one statement, since a prepared statement has one parameter set: text holding a further statement after the first is Error 42000 ("Prepare() takes one statement"); blanks, comments and semicolons after it are not one. Text holding no statement at all prepares nothing and succeeds. SQLite stops parsing at a NUL character: text left after one is Error 42000 ("the SQL text holds a NUL character"). A statement with more than 32767 parameters or result columns (what the std::int16_t counts can report) is Error HY000. Registered output-column readers survive it, as SQLBindCol bindings do: the owner unbinds them (UnbindColumns).

Parameters
stmtThe statement.
queryThe SQL text, UTF-8.
wideQueryTextIgnored: SQLite takes UTF-8.
Returns
Success, or Error with the failure captured for Diagnose.

◆ Execute()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::Execute ( Statement &  stmt)
noexcept

Executes the prepared statement with the bound parameters.

Resets a statement that was stepped, then steps once. A statement with result columns keeps the first row pending, for Fetch to hand out first. A statement without result columns runs to completion, records its change count (NumRowsAffected) and is reset.

Every parameter must have been bound since the bindings were last cleared, else Error 07002 naming the first unbound one (an unbound parameter is never a silent NULL; BindNull binds NULL on purpose). The bindings stay across executions, as on ODBC, until ResetParameters or the next prepare: a statement bound once executes again with the same values, and binding one parameter again changes only that one. The text and blob bytes bound to a statement without result columns are referenced, so they must stay alive and unchanged as long as the binding is executed; a statement with result columns copied them. A bind that fails leaves its parameter unbound. With numbered parameters SQLite counts up to the largest index (?5 alone is 5 parameters): every index up to it must be bound, gaps included (to NULL, say).

Parameters
stmtThe statement.
Returns
Success (never NoData), or Error with the failure captured for Diagnose.

◆ ExecuteDirect()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::ExecuteDirect ( Statement &  stmt,
std::string_view  query,
bool  wideQueryText 
)

Runs the statements of query in order, each prepared and executed as Prepare and Execute do.

Statements of an earlier text still pending are run first, as DiscardResults does. A statement without result columns runs to completion at once; the first with result columns becomes the current result set and the rest of the text is kept (a copy the statement owns) for MoreResults. A failing statement stops the text: its error is returned and the statements after it do not run. The text takes no parameters: a statement of it that has some fails with 07002. Text holding no statement succeeds without executing anything. Text holding a NUL character fails with 42000 before any of it runs.

Parameters
stmtThe statement.
queryThe SQL text, UTF-8: any number of statements.
wideQueryTextIgnored: SQLite takes UTF-8.
Returns
Success, or Error with the failure captured for Diagnose.

◆ Fetch()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::Fetch ( Statement &  stmt)
noexcept

Makes the next row the current one and runs the registered readers on it in column order.

The row Execute left pending comes first. A reader that fails stops the row: the result is Error, Diagnose reports the reader's diagnostic, and the row stays current, so its columns can still be read. A reader that throws (a binder running out of memory, a user's binder refusing a value) fails the same way: the exception is caught and kept as the diagnostic — a SqlException's own, HY001 for std::bad_alloc, HY000 with the message of any other exception — and the statement stays usable.

Parameters
stmtThe statement.
Returns
Success on a row; NoData past the last row (and again on every further call); Error with 24000 when the statement has no result set, else with the failure captured for Diagnose.

◆ MoreResults()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::MoreResults ( Statement &  stmt)
noexcept

Moves to the next result set of an ExecuteDirect text: closes the current one and runs the pending rest of the text as ExecuteDirect runs a text.

Parameters
stmtThe statement.
Returns
Success when a further statement with result columns became current; NoData when the text is exhausted; Error when a statement of it failed (the statements after it do not run), and Error 08003 on a statement whose connection is closed.

References Lightweight::Driver::MoreResults().

◆ CloseCursor()

LIGHTWEIGHT_API void Lightweight::Driver::Sqlite3::CloseCursor ( Statement &  stmt)
noexcept

Closes the cursor: resets the statement (bindings stay). The pending rest of an ExecuteDirect text stays pending, for MoreResults. Nothing on an orphaned statement.

Parameters
stmtThe statement.

References Lightweight::Driver::CloseCursor().

◆ DiscardResults()

LIGHTWEIGHT_API void Lightweight::Driver::Sqlite3::DiscardResults ( Statement &  stmt)
noexcept

Discards the pending results: resets the statement (bindings stay) and runs the pending rest of an ExecuteDirect text to its end or its first failing statement, dropping that failure (Diagnose keeps reporting what it reported before). Nothing on an orphaned statement, whose pending text was dropped unrun.

Parameters
stmtThe statement.

References Lightweight::Driver::DiscardResults().

◆ UnbindColumns()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::UnbindColumns ( Statement &  stmt)
noexcept

Forgets every registered output reader (RegisterOutputReader).

Parameters
stmtThe statement.
Returns
Success; Error 08003 on a statement whose connection is closed.

References Lightweight::Driver::UnbindColumns().

◆ ResetParameters()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::ResetParameters ( Statement &  stmt)
noexcept

Clears the parameter bindings (sqlite3_clear_bindings): every parameter is NULL until bound again.

Parameters
stmtThe statement.
Returns
Success; Error 08003 on a statement whose connection is closed.

References Lightweight::Driver::ResetParameters().

◆ ResetParameterArrays()

LIGHTWEIGHT_API void Lightweight::Driver::Sqlite3::ResetParameterArrays ( Statement &  stmt)
noexcept

Nothing: this driver has no parameter arrays.

Parameters
stmtThe statement.

References Lightweight::Driver::ResetParameterArrays().

◆ NumResultColumns()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::NumResultColumns ( Statement const &  stmt,
std::int16_t &  count 
)
noexcept

The number of result columns of the prepared statement (sqlite3_column_count).

Parameters
stmtThe statement.
countReceives the count; 0 when nothing is prepared. SQLite caps it at 32767.
Returns
Success; Error 08003 on a statement whose connection is closed.

References Lightweight::Driver::NumResultColumns().

◆ NumParameters()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::NumParameters ( Statement const &  stmt,
std::int16_t &  count 
)
noexcept

The number of parameters of the prepared statement (sqlite3_bind_parameter_count).

Parameters
stmtThe statement.
countReceives the count (the largest parameter index); 0 when nothing is prepared. Prepare refuses a statement with more than 32767 parameters, so it always fits.
Returns
Success; Error 08003 on a statement whose connection is closed.

References Lightweight::Driver::NumParameters().

◆ NumRowsAffected()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::NumRowsAffected ( Statement const &  stmt,
std::ptrdiff_t &  count 
)
noexcept

The number of rows the statement's last execution changed, known once that execution completed.

A statement without result columns completes inside Execute. A statement with result columns completes when Execute or Fetch steps past its last row: an INSERT / UPDATE / DELETE with RETURNING has written all its rows on the first step, but SQLite reports the count only at completion, so it reads 0 until Fetch returned NoData. The count is sqlite3_changes64 when the connection's total change count moved during the execution, else 0: a DDL statement, transaction control, a PRAGMA or a SELECT reads 0, not the count of an earlier statement. After an ExecuteDirect text of several statements (and after MoreResults) it is the count of the last statement of the text that completed, also when a later statement of it failed.

Parameters
stmtThe statement.
countReceives the count; 0 before the execution completed.
Returns
Success; Error 08003 on a statement whose connection is closed.

References Lightweight::Driver::NumRowsAffected().

◆ ColumnType()

LIGHTWEIGHT_API std::expected< SqlResultColumnType, SqlErrorInfo > Lightweight::Driver::Sqlite3::ColumnType ( Statement const &  stmt,
SqlColumnIndex  column 
)

The type of result column column.

A column declared with a type name the SQLite formatter emits has the type the SQLite ODBC driver reports for that name (the name is matched in any case, without its "(size)"; DECIMAL, GUID and the character types report WVarChar, TEXT WLongVarChar, REAL Double, BLOB Binary). Any other column (an expression, or a type name the table lacks) has the type of the storage class of its value in the row at hand (the pending or the current one): Integer is BigInt, Float Double, Text VarChar, Blob VarBinary, and Null (or no row at hand) Unknown.

Parameters
stmtThe statement.
columnThe column.
Returns
The type; the diagnostics for an out-of-range column (07009) or a closed connection (08003).

References Lightweight::Driver::ColumnType().

◆ SetQueryTimeout()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::SetQueryTimeout ( Statement &  stmt,
std::chrono::seconds  timeout 
)
noexcept

Accepts a query timeout and stores nothing: as on the ODBC SQLite path it is not enforced.

Parameters
stmtThe statement.
timeoutThe timeout.
Returns
Success; Error 08003 on a statement whose connection is closed.

References Lightweight::Driver::SetQueryTimeout().

◆ QueryTimeout()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::QueryTimeout ( Statement const &  stmt,
std::chrono::seconds &  timeout 
)
noexcept

The query timeout: always none.

Parameters
stmtThe statement.
timeoutReceives 0.
Returns
Success; Error 08003 on a statement whose connection is closed.

References Lightweight::Driver::QueryTimeout().

◆ Diagnose()

LIGHTWEIGHT_API SqlErrorInfo Lightweight::Driver::Sqlite3::Diagnose ( Statement const &  stmt)

The diagnostics of the statement's last failure, captured in its state when the failing call returned (never read later from the connection, where another statement may have replaced it).

Parameters
stmtThe statement.
Returns
The diagnostics; value-initialized fields when nothing failed since the last Prepare; 08003 for a statement without state.

References Lightweight::Driver::Diagnose().

◆ RequireSuccess()

LIGHTWEIGHT_API void Lightweight::Driver::Sqlite3::RequireSuccess ( Statement const &  stmt,
SqlResult  result,
std::source_location  location = std::source_location::current() 
)

Throws unless result is a success, as Driver::ClassifyResult decides from Diagnose: std::invalid_argument for 07009, SqlException for any other failure.

Parameters
stmtThe statement result came from.
resultThe result to check.
locationWhere the check originated, for the message of std::invalid_argument.

References Lightweight::Driver::RequireSuccess().

◆ CheckResult()

::Lightweight::Driver::CallOutcome Lightweight::Driver::Sqlite3::CheckResult ( Statement const &  stmt,
SqlResult  result,
std::source_location  location 
)
inlinenoexcept

The non-throwing verdict on result; this driver has no fault seam, so nothing is ever injected.

Parameters
stmtThe statement result came from.
resultThe result to check.
locationWhere the check originated (unused).
Returns
{ Succeeded(result), std::nullopt }.

Definition at line 259 of file Statement.hpp.

References Lightweight::Driver::CheckResult(), and Lightweight::Driver::CallOutcome::succeeded.

◆ OpenCatalog()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::OpenCatalog ( Statement const &  stmt,
SqlCatalogRequest const &  request 
)
noexcept

Fails: this driver has no catalog functions (SqlSchema reads its catalog with the SQL of SqlQueryFormatter::CatalogQueries()).

Parameters
stmtThe statement.
requestThe catalog function asked for (unused).
Returns
Error, with the statement's diagnostics NotSupportedByDriver(SqlDriverId::Sqlite3, "catalog access") (SQLSTATE IM001); Error 08003 on a statement whose connection is closed.

References Lightweight::Driver::OpenCatalog().

◆ CatalogColumnType()

constexpr SqlResultColumnType Lightweight::Driver::Sqlite3::CatalogColumnType ( Statement const &  stmt,
int  dataType 
)
constexprnoexcept

The type a catalog DATA_TYPE code stands for: none, since this driver opens no catalog result set.

Parameters
stmtThe statement (unused).
dataTypeThe code (unused).
Returns
SqlResultColumnType::Unknown.

Definition at line 278 of file Statement.hpp.

References Lightweight::Driver::CatalogColumnType().

◆ DescribeColumn()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::DescribeColumn ( Statement const &  stmt,
SqlColumnIndex  column,
SqlColumnDescription &  description 
)

Describes result column column: its type as ColumnType reports it, and no column size (SQLite does not bound a column's values).

Parameters
stmtThe statement.
columnThe column.
descriptionReceives the description; left unchanged on failure.
Returns
Success; Error with the diagnostics of ColumnType (07009, 08003).

References Lightweight::Driver::DescribeColumn().

◆ DescribeResultColumnSqlType()

constexpr std::optional< std::int16_t > Lightweight::Driver::Sqlite3::DescribeResultColumnSqlType ( Statement const &  stmt,
SqlColumnIndex  column 
)
constexprnoexcept

The driver's SQL type code of result column column: none, since this driver's leaf binders read the storage class of the value instead and never ask.

Parameters
stmtThe statement (unused).
columnThe column (unused).
Returns
std::nullopt.

Definition at line 299 of file Statement.hpp.

References Lightweight::Driver::DescribeResultColumnSqlType().

◆ DeclaredBoundColumnSize()

LIGHTWEIGHT_API std::size_t Lightweight::Driver::Sqlite3::DeclaredBoundColumnSize ( Statement const &  stmt,
SqlColumnIndex  column,
SqlOutputColumnLength  length 
)
noexcept

The bound buffer size the declared length of result column column asks for: the default, since this driver fills a bound column afresh for every row and so never cuts a value off.

Parameters
stmtThe statement (unused).
columnThe column (unused).
lengthWhich declared length (unused).
Returns
detail::DefaultBoundColumnSize.

References Lightweight::Driver::DeclaredBoundColumnSize().

◆ ResetRowArrayAttributes()

LIGHTWEIGHT_API void Lightweight::Driver::Sqlite3::ResetRowArrayAttributes ( Statement &  stmt)
noexcept

Nothing: this driver has no row arrays.

Parameters
stmtThe statement.

References Lightweight::Driver::ResetRowArrayAttributes().

◆ BindUtf16TextParameter()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::BindUtf16TextParameter ( Statement &  stmt,
std::uint16_t  parameter,
char16_t *  text,
std::size_t  columnSize,
SqlIndicator &  lengthIndicator 
)
noexcept

Binds UTF-16 text to parameter (as BindText16), read from text for lengthIndicator bytes.

Parameters
stmtThe statement.
parameterThe parameter.
textThe text; must stay alive and unchanged as long as the binding is executed (see BindText).
columnSizeThe declared column size (unused: SQLite does not bound a parameter's value).
lengthIndicatorThe byte length of text, >= 0 only: ODBC's special lengths (SqlNullData, a NUL-terminated length) mean nothing here.
Returns
As for BindText16; Error with SQLSTATE HY090 for a negative lengthIndicator, nothing bound.

◆ Fail()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::Fail ( Statement &  stmt,
std::string_view  sqlState,
std::string_view  message 
)
noexcept

Records a failure the driver did not produce itself (a leaf binder's conversion error) as the statement's diagnostic, native error code 0.

Parameters
stmtThe statement.
sqlStateThe SQLSTATE.
messageThe message.
Returns
Error, so a binder can return Fail(stmt, "22003", "numeric value out of range");.

References Lightweight::Driver::Sqlite3::Fail().

Referenced by Lightweight::Driver::Sqlite3::Fail().

◆ BindNull()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::BindNull ( Statement &  stmt,
SqlColumnIndex  parameter 
)
noexcept

Binds SQL NULL to parameter; it counts as bound for Execute (bind unused numbered parameters this way).

Parameters
stmtThe statement.
parameterThe parameter.
Returns
Success, or Error (07009 for an out-of-range parameter) with the failure captured.

References Lightweight::Driver::Sqlite3::BindNull().

Referenced by Lightweight::Driver::Sqlite3::BindNull().

◆ BindInt64()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::BindInt64 ( Statement &  stmt,
SqlColumnIndex  parameter,
std::int64_t  value 
)
noexcept

Binds an integer to parameter, by value.

Parameters
stmtThe statement.
parameterThe parameter.
valueThe value.
Returns
Success, or Error (07009 for an out-of-range parameter) with the failure captured.

References Lightweight::Driver::Sqlite3::BindInt64().

Referenced by Lightweight::Driver::Sqlite3::BindInt64().

◆ BindDouble()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::BindDouble ( Statement &  stmt,
SqlColumnIndex  parameter,
double  value 
)
noexcept

Binds a floating-point number to parameter, by value.

Parameters
stmtThe statement.
parameterThe parameter.
valueThe value.
Returns
Success, or Error (07009 for an out-of-range parameter) with the failure captured.

References Lightweight::Driver::Sqlite3::BindDouble().

Referenced by Lightweight::Driver::Sqlite3::BindDouble().

◆ BindText()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::BindText ( Statement &  stmt,
SqlColumnIndex  parameter,
std::string_view  utf8 
)
noexcept

Binds UTF-8 text to parameter; an empty view binds empty text, never NULL.

On a statement without result columns the bytes are referenced, not copied: they must stay alive and unchanged as long as the binding is executed (until the parameter is bound again, ResetParameters or the next prepare). On a statement with result columns they are copied.

Parameters
stmtThe statement.
parameterThe parameter.
utf8The text; embedded NULs are kept.
Returns
Success, or Error (07009 for an out-of-range parameter) with the failure captured.

References Lightweight::Driver::Sqlite3::BindText().

Referenced by Lightweight::Driver::Sqlite3::BindText().

◆ BindText16()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::BindText16 ( Statement &  stmt,
SqlColumnIndex  parameter,
std::u16string_view  utf16 
)
noexcept

Binds UTF-16 text (native byte order) to parameter; referenced or copied as by BindText.

Parameters
stmtThe statement.
parameterThe parameter.
utf16The text; embedded NULs are kept.
Returns
Success, or Error (07009 for an out-of-range parameter) with the failure captured.

References Lightweight::Driver::Sqlite3::BindText16().

Referenced by Lightweight::Driver::Sqlite3::BindText16().

◆ BindBlob()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::BindBlob ( Statement &  stmt,
SqlColumnIndex  parameter,
std::span< std::byte const >  bytes 
)
noexcept

Binds bytes to parameter; referenced or copied as by BindText. Empty bytes bind an empty blob, never NULL.

Parameters
stmtThe statement.
parameterThe parameter.
bytesThe bytes.
Returns
Success, or Error (07009 for an out-of-range parameter) with the failure captured.

References Lightweight::Driver::Sqlite3::BindBlob().

Referenced by Lightweight::Driver::Sqlite3::BindBlob().

◆ ReadInt64()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::ReadInt64 ( Statement &  stmt,
SqlColumnIndex  column,
std::int64_t &  value,
SqlIndicator *  indicator 
)
noexcept

Reads result column column of the current row as an integer (SQLite converts other storage classes).

Parameters
stmtThe statement.
columnThe column.
valueReceives the value; untouched for NULL.
indicatorReceives the byte length of the value, or SqlNullData for NULL; may be null unless the value is NULL.
Returns
Success; Error with 07009 (column out of range), 24000 (no current row) or 22002 (NULL, but indicator is null).

References Lightweight::Driver::Sqlite3::ReadInt64().

Referenced by Lightweight::Driver::Sqlite3::ReadInt64().

◆ ReadDouble()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::ReadDouble ( Statement &  stmt,
SqlColumnIndex  column,
double &  value,
SqlIndicator *  indicator 
)
noexcept

Reads result column column of the current row as a floating-point number; as ReadInt64.

Parameters
stmtThe statement.
columnThe column.
valueReceives the value; untouched for NULL.
indicatorAs for ReadInt64.
Returns
As for ReadInt64.

References Lightweight::Driver::Sqlite3::ReadDouble().

Referenced by Lightweight::Driver::Sqlite3::ReadDouble().

◆ ReadText()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::ReadText ( Statement &  stmt,
SqlColumnIndex  column,
std::string_view &  utf8,
SqlIndicator *  indicator 
)
noexcept

Reads result column column of the current row as UTF-8 text, without copying it.

The view points into SQLite's buffer: it stays valid until the statement is stepped (Fetch), reset (Execute, CloseCursor, ...) or finalized, or the same column is read as UTF-16 or as a blob.

Parameters
stmtThe statement.
columnThe column.
utf8Receives the text, with its full length (embedded NULs kept); untouched for NULL.
indicatorAs for ReadInt64; the byte length.
Returns
As for ReadInt64; also Error HY001 when SQLite runs out of memory converting the value.

References Lightweight::Driver::Sqlite3::ReadText().

Referenced by Lightweight::Driver::Sqlite3::ReadText().

◆ ReadText16()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::ReadText16 ( Statement &  stmt,
SqlColumnIndex  column,
std::u16string_view &  utf16,
SqlIndicator *  indicator 
)
noexcept

Reads result column column of the current row as UTF-16 text (native byte order), without copying it.

The view points into SQLite's buffer, valid as long as that of ReadText (reading the column as UTF-8 ends it).

Parameters
stmtThe statement.
columnThe column.
utf16Receives the text; untouched for NULL.
indicatorAs for ReadInt64; the byte length (twice the code units).
Returns
As for ReadText.

References Lightweight::Driver::Sqlite3::ReadText16().

Referenced by Lightweight::Driver::Sqlite3::ReadText16().

◆ ReadBlob()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::ReadBlob ( Statement &  stmt,
SqlColumnIndex  column,
std::span< std::byte const > &  bytes,
SqlIndicator *  indicator 
)
noexcept

Reads result column column of the current row as bytes, without copying them.

The span points into SQLite's buffer, valid as long as that of ReadText (reading the column as text ends it).

Parameters
stmtThe statement.
columnThe column.
bytesReceives the bytes; untouched for NULL.
indicatorAs for ReadInt64; the byte length.
Returns
As for ReadText.

References Lightweight::Driver::Sqlite3::ReadBlob().

Referenced by Lightweight::Driver::Sqlite3::ReadBlob().

◆ TypeOfStorageClass()

constexpr SqlResultColumnType Lightweight::Driver::Sqlite3::TypeOfStorageClass ( StorageClass  storageClass)
constexprnoexcept

The driver-neutral type of a value of storageClass, as ColumnType reports a column whose declared type does not name one: Integer is BigInt, Float Double, Text VarChar, Blob VarBinary, Null Unknown.

Parameters
storageClassThe storage class.
Returns
The type.

Definition at line 486 of file Statement.hpp.

References Lightweight::Driver::Sqlite3::TypeOfStorageClass().

Referenced by Lightweight::Driver::Sqlite3::TypeOfStorageClass().

◆ ColumnStorageClass()

LIGHTWEIGHT_API StorageClass Lightweight::Driver::Sqlite3::ColumnStorageClass ( Statement const &  stmt,
SqlColumnIndex  column 
)
noexcept

The storage class of result column column's value in the row at hand (the pending or the current one).

Parameters
stmtThe statement.
columnThe column.
Returns
The storage class; Null when there is no row at hand, the column is out of range or the connection is closed.

References Lightweight::Driver::Sqlite3::ColumnStorageClass().

Referenced by Lightweight::Driver::Sqlite3::ColumnStorageClass().

◆ ExpandedSql()

LIGHTWEIGHT_API std::string Lightweight::Driver::Sqlite3::ExpandedSql ( Statement const &  stmt)

The prepared SQL text with the values currently bound in place of the parameters (sqlite3_expanded_sql); unbound parameters read NULL.

It reads every value currently bound. A parameter stays bound across executions until it is bound again, ResetParameters runs or another query is prepared, and on a statement without result columns text and blobs are bound by reference: every currently bound value must still be alive when this is called. That includes values bound by an SqlStatement::Execute(args...) or a batch, which may be gone once that call returned (the statement resets them only at the next bind by hand). A statement with result columns copied its values when they were bound. For tests of the driver; library code must not use it for logging (it would read the caller's values at a moment the caller does not control).

Parameters
stmtThe statement.
Returns
The text; empty when nothing is prepared, memory ran out, or SQLite was built without it.

References Lightweight::Driver::Sqlite3::ExpandedSql().

Referenced by Lightweight::Driver::Sqlite3::ExpandedSql().

◆ ColumnDeclaredType()

LIGHTWEIGHT_API std::string_view Lightweight::Driver::Sqlite3::ColumnDeclaredType ( Statement const &  stmt,
SqlColumnIndex  column 
)
noexcept

The type result column column is declared with (sqlite3_column_decltype).

The view stays valid until the statement is stepped again (SQLite re-prepares a statement whose schema changed on its next step), prepared again or freed.

Parameters
stmtThe statement.
columnThe column.
Returns
The declared type as written in the schema; empty for an expression column, an out-of-range column, or when nothing is prepared.

References Lightweight::Driver::Sqlite3::ColumnDeclaredType().

Referenced by Lightweight::Driver::Sqlite3::ColumnDeclaredType().

◆ RegisterOutputReader()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Sqlite3::RegisterOutputReader ( Statement &  stmt,
SqlColumnIndex  column,
OutputReader  reader,
void *  target,
SqlIndicator *  indicator 
)
noexcept

Registers reader as the reader of column, run on every row Fetch makes current.

Registering a column again replaces its reader. The reader table grows here, never during a fetch.

Parameters
stmtThe statement.
columnThe column; it is not checked against the prepared statement (a reader of a column the result set lacks fails when it reads, with 07009).
readerThe reader; null unregisters the column.
targetHanded to reader on every row.
indicatorHanded to reader on every row.
Returns
Success; Error with 07009 for column 0, HY001 when memory ran out, 08003 on a statement whose connection is closed.

References Lightweight::Driver::Sqlite3::RegisterOutputReader().

Referenced by Lightweight::Driver::Sqlite3::RegisterOutputColumn(), and Lightweight::Driver::Sqlite3::RegisterOutputReader().

◆ OutputReaderCallback()

LIGHTWEIGHT_API SqlDataBinderCallback const & Lightweight::Driver::Sqlite3::OutputReaderCallback ( )
noexcept

The binder callback the readers of RegisterOutputColumn hand to SqlDataBinder<T>::GetColumn.

Answers ServerType() with SqlServerType::SQLITE and DriverName() with "sqlite3-native"; it refers to no statement.

Returns
The one, stateless, callback.

References Lightweight::Driver::Sqlite3::OutputReaderCallback().

Referenced by Lightweight::Driver::Sqlite3::OutputReaderCallback().

◆ RegisterOutputColumn()

template<typename T >
SqlResult Lightweight::Driver::Sqlite3::RegisterOutputColumn ( Statement &  stmt,
SqlColumnIndex  column,
T *  result,
SqlIndicator *  indicator 
)
noexcept

Registers SqlDataBinder<T>::GetColumn as the reader of column, filling result on every row (what every leaf binder's OutputColumn calls). A NULL row leaves result holding T{} (for a type that has one: a disengaged optional, a NULL SqlVariant, 0, an empty string), never the previous row's value.

Parameters
stmtThe statement.
columnThe column.
resultThe bound target.
indicatorThe bound indicator.
Returns
As for RegisterOutputReader.

Definition at line 598 of file Statement.hpp.

References Lightweight::Driver::Sqlite3::RegisterOutputColumn(), and Lightweight::Driver::Sqlite3::RegisterOutputReader().

Referenced by Lightweight::Driver::Sqlite3::RegisterOutputColumn().