5#include "../../Api.hpp"
6#include "../../SqlBindingTypes.hpp"
7#include "../../SqlError.hpp"
8#include "../Concept.hpp"
18#include <source_location>
45class SqlDataBinderCallback;
48namespace Lightweight::Driver::Sqlite3
99[[nodiscard]] LIGHTWEIGHT_API SqlResult
Prepare(
Statement& stmt, std::string_view query,
bool wideQueryText);
223[[nodiscard]] LIGHTWEIGHT_API std::expected<SqlResultColumnType, SqlErrorInfo>
ColumnType(
Statement const& stmt,
224 SqlColumnIndex column);
252 std::source_location location = std::source_location::current());
261 [[maybe_unused]] std::source_location location)
noexcept
263 return ::Lightweight::Driver::CallOutcome { .
succeeded = Succeeded(result), .injectedError = std::nullopt };
279 [[maybe_unused]]
int dataType)
noexcept
281 return SqlResultColumnType::Unknown;
291 SqlColumnIndex column,
300 [[maybe_unused]]
Statement const& stmt, [[maybe_unused]] SqlColumnIndex column)
noexcept
312 SqlColumnIndex column,
313 SqlOutputColumnLength length)
noexcept;
327[[nodiscard]] LIGHTWEIGHT_API SqlResult BindUtf16TextParameter(
Statement& stmt,
328 std::uint16_t parameter,
330 std::size_t columnSize,
331 SqlIndicator& lengthIndicator)
noexcept;
343[[nodiscard]] LIGHTWEIGHT_API SqlResult
Fail(
Statement& stmt, std::string_view sqlState, std::string_view message)
noexcept;
350[[nodiscard]] LIGHTWEIGHT_API SqlResult
BindNull(
Statement& stmt, SqlColumnIndex parameter)
noexcept;
357[[nodiscard]] LIGHTWEIGHT_API SqlResult
BindInt64(
Statement& stmt, SqlColumnIndex parameter, std::int64_t value)
noexcept;
364[[nodiscard]] LIGHTWEIGHT_API SqlResult
BindDouble(
Statement& stmt, SqlColumnIndex parameter,
double value)
noexcept;
376[[nodiscard]] LIGHTWEIGHT_API SqlResult
BindText(
Statement& stmt, SqlColumnIndex parameter, std::string_view utf8)
noexcept;
384 SqlColumnIndex parameter,
385 std::u16string_view utf16)
noexcept;
394 SqlColumnIndex parameter,
395 std::span<std::byte const> bytes)
noexcept;
406 SqlColumnIndex column,
408 SqlIndicator* indicator)
noexcept;
417 SqlColumnIndex column,
419 SqlIndicator* indicator)
noexcept;
432 SqlColumnIndex column,
433 std::string_view& utf8,
434 SqlIndicator* indicator)
noexcept;
447 SqlColumnIndex column,
448 std::u16string_view& utf16,
449 SqlIndicator* indicator)
noexcept;
462 SqlColumnIndex column,
463 std::span<std::byte const>& bytes,
464 SqlIndicator* indicator)
noexcept;
488 switch (storageClass)
490 case StorageClass::Integer:
491 return SqlResultColumnType::BigInt;
492 case StorageClass::Float:
493 return SqlResultColumnType::Double;
494 case StorageClass::Text:
495 return SqlResultColumnType::VarChar;
496 case StorageClass::Blob:
497 return SqlResultColumnType::VarBinary;
498 case StorageClass::Null:
501 return SqlResultColumnType::Unknown;
556 Statement& stmt, SqlColumnIndex column,
OutputReader reader,
void* target, SqlIndicator* indicator)
noexcept;
575 template <
typename T>
576 SqlResult ReadOutputColumn(
Statement& stmt, SqlColumnIndex column,
void* target, SqlIndicator* indicator)
578 auto*
const result =
static_cast<T*
>(target);
579 auto const read = SqlDataBinder<T>::GetColumn(stmt, column, result, indicator,
OutputReaderCallback());
582 if constexpr (std::default_initializable<T> && std::is_move_assignable_v<T>)
583 if (Succeeded(read) && indicator && *indicator == SqlNullData)
599 SqlColumnIndex column,
601 SqlIndicator* indicator)
noexcept
608static_assert(::Lightweight::Driver::SqlDriverStatementOperations<Driver>);
609static_assert(::Lightweight::Driver::SqlDriver<Driver>);
void ResetParameterArrays(StatementHandle &statement) noexcept
Restores single-row parameter binding after a parameter-array execution. Not reported.
void CloseCursor(StatementHandle &statement) noexcept
Closes the cursor of a result set that was read to its end. Pending result sets are left alone.
SqlResult UnbindColumns(StatementHandle &statement) noexcept
Unbinds every bound result column.
std::optional< std::int16_t > DescribeResultColumnSqlType(StatementHandle const &statement, SqlColumnIndex column) noexcept
The driver's own SQL type code of a result column, as the driver's leaf binders read it (see SqlDataB...
void Allocate(ConnectionHandle &connection) noexcept
Allocates the driver's connection resources, unless the connection already holds them.
void RequireSuccess(StatementHandle const &statement, SqlResult result, std::source_location location=std::source_location::current())
Throws unless result indicates success: std::invalid_argument for a soft failure the caller is expect...
SqlResult NumResultColumns(StatementHandle const &statement, std::int16_t &count) noexcept
Reports the number of columns of the current result set.
SqlResult SetQueryTimeout(StatementHandle &statement, std::chrono::seconds timeout) noexcept
Sets the query timeout of the statement.
void DiscardResults(StatementHandle &statement) noexcept
Drains every pending result set and closes the cursor, so the handle can run another query....
void Free(StatementHandle &statement) noexcept
Frees the statement's driver handle and leaves statement empty, bound to the same driver.
SqlResult OpenCatalog(StatementHandle const &statement, SqlCatalogRequest const &request)
Opens the catalog result set request names on statement, in the layout the ODBC specification gives t...
SqlResult NumParameters(StatementHandle const &statement, std::int16_t &count) noexcept
Reports the number of parameters of the prepared statement.
SqlResultColumnType CatalogColumnType(StatementHandle const &statement, int dataType) noexcept
The type a DATA_TYPE code of the driver's catalog result sets (see OpenCatalog) stands for.
SqlResult QueryTimeout(StatementHandle const &statement, std::chrono::seconds &timeout) noexcept
Reports the query timeout of the statement.
void ResetRowArrayAttributes(StatementHandle &statement) noexcept
Restores single-row fetching after a row-array fetch. Not reported; nothing for a driver without row ...
SqlResult NumRowsAffected(StatementHandle const &statement, std::ptrdiff_t &count) noexcept
Reports the number of rows the last executed statement affected.
void Abandon(StatementHandle &statement) noexcept
Gives up the statement's driver handle after its connection session ended, and leaves statement empty...
std::size_t DeclaredBoundColumnSize(StatementHandle const &statement, SqlColumnIndex column, SqlOutputColumnLength length) noexcept
The declared length of a result column as a bound buffer size (see SqlDataBinderCallback::MinimumOutp...
SqlErrorInfo Diagnose(StatementHandle const &statement)
Reads the statement's diagnostics: the first record its last failed call left.
SqlResult DescribeColumn(StatementHandle const &statement, SqlColumnIndex column, SqlColumnDescription &description)
Describes a result column: its type and its size.
SqlResult ResetParameters(StatementHandle &statement) noexcept
Drops every parameter binding.
std::expected< SqlResultColumnType, SqlErrorInfo > ColumnType(StatementHandle const &statement, SqlColumnIndex column)
The SQL data type of a result column, as the driver describes it.
SqlResult MoreResults(StatementHandle &statement) noexcept
Advances to the next pending result set.
CallOutcome CheckResult(StatementHandle const &statement, SqlResult result, std::source_location location)
The non-throwing, fault-seam-aware verdict on result.
LIGHTWEIGHT_API SqlResult 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.
SqlResult 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 ever...
StorageClass
The storage class of a SQLite value.
@ Float
An 8-byte IEEE floating-point number.
@ Integer
A signed integer of up to 8 bytes.
@ Blob
Bytes, stored as given.
LIGHTWEIGHT_API StorageClass 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 SqlResult 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 stateme...
LIGHTWEIGHT_API SqlResult 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.
LIGHTWEIGHT_API SqlResult 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 std::string_view ColumnDeclaredType(Statement const &stmt, SqlColumnIndex column) noexcept
The type result column column is declared with (sqlite3_column_decltype).
SqlResult(*)(Statement &stmt, SqlColumnIndex column, void *target, SqlIndicator *indicator) OutputReader
A registered reader: reads one column of the current row into the bound target.
LIGHTWEIGHT_API SqlResult BindInt64(Statement &stmt, SqlColumnIndex parameter, std::int64_t value) noexcept
Binds an integer to parameter, by value.
LIGHTWEIGHT_API SqlResult 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 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 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 SqlResult 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,...
LIGHTWEIGHT_API SqlResult 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 SqlDataBinderCallback const & OutputReaderCallback() noexcept
The binder callback the readers of RegisterOutputColumn hand to SqlDataBinder<T>::GetColumn.
LIGHTWEIGHT_API std::string ExpandedSql(Statement const &stmt)
The prepared SQL text with the values currently bound in place of the parameters (sqlite3_expanded_sq...
LIGHTWEIGHT_API SqlResult 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 BindDouble(Statement &stmt, SqlColumnIndex parameter, double value) noexcept
Binds a floating-point number to parameter, by value.
constexpr SqlResultColumnType TypeOfStorageClass(StorageClass storageClass) noexcept
The driver-neutral type of a value of storageClass, as ColumnType reports a column whose declared typ...
LIGHTWEIGHT_API SqlResult 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.
@ Execute
The execution of a prepared statement (SqlStatement::Execute).
@ ExecuteDirect
The execution of a one-shot statement (SqlStatement::ExecuteDirect).
@ Prepare
The preparation of a statement (SqlStatement::Prepare).
bool succeeded
Whether the checked call should be treated as having succeeded.
What a catalog call asks for: the ODBC catalog function and its arguments, in driver-neutral terms.
What a driver reports about a result column (see DescribeColumn).
The SQLite3 driver's connection handle struct: one pointer to the driver-owned connection state.
The SQLite3 driver's statement handle struct: one pointer to the driver-owned statement state.
Represents a SQL error as reported by the database driver.