9#ifndef HEADER_SQLITEPP_STATEMENT_IFACE_INCLUDED
10#define HEADER_SQLITEPP_STATEMENT_IFACE_INCLUDED
13#include "string_param.hpp"
16#include "memory_iface.hpp"
22#if __has_include(<sys/uio.h>)
26#ifndef SQLITEPP_BUILDING_MODULE
35 SQLITEPP_EXPORTED
class value;
55 template<
class T=struct ::iovec,
size_t = sizeof(T)>
56 constexpr struct ::iovec * detect_iovec(T *) {
return{}; }
57 constexpr auto detect_iovec(...) {
return (
iovec_fallback *)
nullptr; }
71 using iovec = std::remove_reference_t<
decltype(*detect_iovec((
::iovec *)
nullptr))>;
73 using iovec = <conditionally declared>;
101 ,
unsigned int flags = 0
119 ,
unsigned int flags = 0
123#if __cpp_char8_t >= 201811
131 ,
unsigned int flags = 0
135 return create(db, (
const char *)
sql.c_str()
149 ,
unsigned int flags = 0
212#if SQLITE_VERSION_NUMBER >= SQLITEPP_SQLITE_VERSION(3, 31, 1)
259 void bind(
int idx, int64_t val)
306 #if __cpp_char8_t >= 201811
381 template<
class T,
class D>
383 void)
bind(
int idx, T * ptr,
const char * type, D destroy)
398 { this->
bind(idx, ptr.
release(),
typeid(T).name(), [](T * p)
noexcept { delete p; }); }
417#if SQLITE_VERSION_NUMBER >= SQLITEPP_SQLITE_VERSION(3, 52, 0)
421 static constexpr bool supported_carray_type =
426 #if __cpp_char8_t >= 201811
433 static constexpr int carray_type()
436 return SQLITE_CARRAY_INT32;
438 return SQLITE_CARRAY_INT64;
440 return SQLITE_CARRAY_DOUBLE;
442 return SQLITE_CARRAY_TEXT;
443 #if __cpp_char8_t >= 201811
445 return SQLITE_CARRAY_TEXT;
448 return SQLITE_CARRAY_BLOB;
450 static_assert(dependent_false<T>,
"unsupported carray type");
473 SQLITEPP_ENABLE_IF(supported_carray_type<T>,
495 SQLITEPP_ENABLE_IF(supported_carray_type<T>,
517 SQLITEPP_ENABLE_IF(supported_carray_type<T>,
518 void)
carray_bind(
int idx,
span<T> array,
void (*destroy)(
void *)
noexcept,
void * destroy_arg =
nullptr)
521 carray_type<T>(), (
void(*)(
void *))destroy, destroy_arg));
598 static constexpr bool supported_column_type =
603 #if __cpp_char8_t >= 201811
631 SQLITEPP_ENABLE_IF(supported_column_type<T>,
704 const char *
sql() const noexcept
707#if SQLITE_VERSION_NUMBER >= SQLITEPP_SQLITE_VERSION(3, 14, 0)
719 void check_error(
int res)
const;
805 template<auto_reset_flags Flags>
852 void destroy() noexcept
sqlite3_bind_parameter_count
sqlite3_bind_parameter_index
sqlite3_bind_parameter_name
#define SQLITE_VERSION_NUMBER
RAII wrapper that resets statement on destruction.
Definition statement_iface.hpp:807
auto_reset()
Constructs an empty instance with no statement.
Definition statement_iface.hpp:810
auto_reset(const std::unique_ptr< statement > &st) noexcept
Constructs an instance referring to a given statement.
Definition statement_iface.hpp:819
~auto_reset() noexcept
Resets the statement if present.
Definition statement_iface.hpp:844
auto_reset(statement *st) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition statement_iface.hpp:824
statement * operator->() const noexcept
Access the stored statement.
Definition statement_iface.hpp:848
Database Connection.
Definition database_iface.hpp:109
sqlite3_stmt * c_ptr() const noexcept
Definition handle.hpp:45
std::unique_ptr< statement > next()
Return the next statement if any.
statement_parser(const database &db, std::string_view sql)
Create a parser for the given database and SQL text.
Definition statement_iface.hpp:757
Prepared Statement Object.
Definition statement_iface.hpp:87
explain_type isexplain() const noexcept
Query the EXPLAIN Setting for the statement.
Definition statement_iface.hpp:220
bool step()
Evaluate the statement.
class database & database() const noexcept
Returns the database to which this statement belongs.
Definition statement_iface.hpp:170
bool readonly() const noexcept
Determine if the statement writes to the database.
Definition statement_iface.hpp:229
void reset() noexcept
Reset the statement.
Definition statement_iface.hpp:190
void bind(int idx, const value &val)
Bind a dynamically typed value to a parameter of the statement.
void bind(int idx, const std::u8string_view &val)
Bind a string value to a parameter of the statement.
void bind(int idx, std::nullptr_t)
Bind a NULL value to a parameter of the statement.
Definition statement_iface.hpp:245
bool busy() const noexcept
Determine if the statement has been reset.
Definition statement_iface.hpp:198
const value & raw_column_value(int idx) const noexcept
Get result values from a query as a raw value object.
Definition statement_iface.hpp:639
void bind_reference(int idx, const std::u8string_view &val)
Bind a string reference to a parameter of the statement.
void bind(int idx, std::unique_ptr< T > ptr)
Bind a custom pointer to a parameter of the statement.
Definition statement_iface.hpp:397
void carray_bind(int idx, span< T > array, void(*destroy)(void *) noexcept, void *destroy_arg=nullptr)
Bind a reference to an array for the CARRAY table-valued function in the statement.
Definition statement_iface.hpp:518
void bind_reference(int idx, const std::string_view &val, void(*unref)(const char *) noexcept)
Bind a string reference to a parameter of the statement.
const char * sql() const noexcept
Returns a pointer to a copy of the SQL text used to create the statement.
Definition statement_iface.hpp:704
void bind(int idx, int val)
Bind an int value to a parameter of the statement.
Definition statement_iface.hpp:252
int column_type(int idx) const noexcept
Default datatype of the result column.
Definition statement_iface.hpp:649
allocated_string expanded_sql() const
Returns SQL text of the statement with bound parameters expanded.
void bind_reference(int idx, const blob_view &val, void(*unref)(const std::byte *) noexcept)
Bind a blob reference to a parameter of the statement.
void bind(int idx, const zero_blob &val)
Bind a blob of zeroes to a parameter of the statement.
Definition statement_iface.hpp:370
void carray_bind(int idx, span< T > array)
Bind the content of an array for the CARRAY table-valued function in the statement.
Definition statement_iface.hpp:474
int column_count() const noexcept
Number of columns in a result set.
Definition statement_iface.hpp:579
void bind(int idx, int64_t val)
Bind an int64_t value to a parameter of the statement.
Definition statement_iface.hpp:259
static std::unique_ptr< statement > create(const database &db, std::string_view &sql, unsigned int flags=0)
Compile an SQL statement.
const char * column_table_name(int idx) const noexcept
Table that is the origin of a result column.
Definition statement_iface.hpp:678
const char * bind_parameter_name(int idx) const noexcept
Returns the name of a parameter with a given index.
Definition statement_iface.hpp:562
void bind_reference(int idx, const std::u8string_view &val, void(*unref)(const char8_t *) noexcept)
Bind a string reference to a parameter of the statement.
const char * column_origin_name(int idx) const noexcept
Table column that is the origin of a result column.
Definition statement_iface.hpp:686
static std::unique_ptr< statement > create(const database &db, const string_param &sql, unsigned int flags=0)
Compile an SQL statement.
void bind(int idx, T *ptr, const char *type, D destroy)
Definition statement_iface.hpp:383
const char * column_database_name(int idx) const noexcept
Database that is the origin of a result column.
Definition statement_iface.hpp:670
~statement() noexcept
Equivalent to sqlite3_finalize.
Definition statement_iface.hpp:162
void bind(int idx, double val)
Bind a double value to a parameter of the statement.
Definition statement_iface.hpp:266
static std::unique_ptr< statement > create(const database &db, std::u8string_view &sql, unsigned int flags=0)
Compile an SQL statement.
Definition statement_iface.hpp:147
explain_type
Return type for isexplain().
Definition statement_iface.hpp:205
@ explain_query_plan
The statement is an EXPLAIN QUERY PLAN.
Definition statement_iface.hpp:208
@ explain
The statement is an EXPLAIN statement.
Definition statement_iface.hpp:207
@ not_explain
The statement is an ordinary statement.
Definition statement_iface.hpp:206
const char * column_name(int idx) const noexcept
Name of the result column.
Definition statement_iface.hpp:662
T column_value(int idx) const noexcept
Get result value from a query.
void bind(int idx, const blob_view &val)
Bind a blob value to a parameter of the statement.
void bind_reference(int idx, const std::string_view &val)
Bind a string reference to a parameter of the statement.
void bind_reference(int idx, const blob_view &val)
Bind a blob reference to a parameter of the statement.
int bind_parameter_count() const noexcept
Returns the number of SQL parameters.
Definition statement_iface.hpp:546
void clear_bindings() noexcept
Reset all bindings on the statement.
Definition statement_iface.hpp:538
void carray_bind_reference(int idx, span< T > array)
Bind a reference to an array for the CARRAY table-valued function in the statement.
Definition statement_iface.hpp:496
int bind_parameter_index(const string_param &name) const noexcept
Returns the index of a parameter with a given name.
Definition statement_iface.hpp:554
const char * column_declared_type(int idx) const noexcept
Declared datatype of a result column.
Definition statement_iface.hpp:694
void bind(int idx, const std::string_view &val)
Bind a string value to a parameter of the statement.
static std::unique_ptr< statement > create(const database &db, const u8string_param &sql, unsigned int flags=0)
Compile an SQL statement.
Definition statement_iface.hpp:129
int data_count() const noexcept
Number of columns in a result set.
Definition statement_iface.hpp:593
Dynamically Typed Value Object.
Definition value_iface.hpp:36
An efficient blob of zeroes of a given size.
Definition span.hpp:257
sqlite3_column_database_name
void * iov_base
Base address of a memory region for input or output.
Definition statement_iface.hpp:50
size_t iov_len
The size of the memory pointed to by iov_base.
Definition statement_iface.hpp:52
< conditionally declared > iovec
A portable version of struct iovec that SQLite uses for carray() functionality.
Definition statement_iface.hpp:73
A fallback version of struct iovec for platforms that lack it.
Definition statement_iface.hpp:48
std::span< T > span
Alias or reimplementation of std::span.
Definition span.hpp:36
span< const std::byte > blob_view
A blob_view is a span of bytes.
Definition span.hpp:239
basic_string_param< char > string_param
Convenience typedef.
Definition string_param.hpp:58
std::unique_ptr< char, sqlite_deleter< char > > allocated_string
A string allocated by SQLite.
Definition memory_iface.hpp:50
basic_string_param< char8_t > u8string_param
Convenience typedef. Only available if you compiler/library supports char8_t.
Definition string_param.hpp:63
auto_reset_flags
Bitwise mask of resets to perform for thinsqlitepp::auto_reset.
Definition statement_iface.hpp:780
@ none
Reset nothing.
Definition statement_iface.hpp:781
@ reset
Reset the statement (does not affect the bindings).
Definition statement_iface.hpp:782
@ all
Reset everything.
Definition statement_iface.hpp:784
@ clear_bindings
Reset the bindings.
Definition statement_iface.hpp:783
ThinSQLite++ namespace.
Definition backup_iface.hpp:17