|
Lightweight 0.20260303.0
|
High level API for (prepared) raw SQL statements. More...
#include <SqlStatement.hpp>
Public Member Functions | |
| LIGHTWEIGHT_API | SqlStatement () |
| Construct a new SqlStatement object, using a new connection, and connect to the default database. | |
| LIGHTWEIGHT_API | SqlStatement (SqlStatement &&other) noexcept |
| Move constructor. | |
| LIGHTWEIGHT_API SqlStatement & | operator= (SqlStatement &&other) noexcept |
| Move assignment operator. | |
| SqlStatement (SqlStatement const &) noexcept=delete | |
| SqlStatement & | operator= (SqlStatement const &) noexcept=delete |
| LIGHTWEIGHT_API | SqlStatement (SqlConnection &relatedConnection) |
| Construct a new SqlStatement object, using the given connection. | |
| LIGHTWEIGHT_API | SqlStatement (std::nullopt_t) |
| Construct a new empty SqlStatement object. No SqlConnection is associated with this statement. | |
| LIGHTWEIGHT_API bool | IsAlive () const noexcept |
| Checks whether the statement's connection is alive and the statement handle is valid. | |
| LIGHTWEIGHT_API bool | IsPrepared () const noexcept |
| Checks whether the statement has been prepared. | |
| LIGHTWEIGHT_API SqlConnection & | Connection () noexcept |
| Retrieves the connection associated with this statement. | |
| LIGHTWEIGHT_API SqlConnection const & | Connection () const noexcept |
| Retrieves the connection associated with this statement. | |
| LIGHTWEIGHT_API SqlErrorInfo | LastError () const |
| Retrieves the last error information with respect to this SQL statement handle. | |
| LIGHTWEIGHT_API SqlQueryBuilder | Query (std::string_view const &table={}) const |
| Creates a new query builder for the given table, compatible with the SQL server being connected. | |
| LIGHTWEIGHT_API SqlQueryBuilder | QueryAs (std::string_view const &table, std::string_view const &tableAlias) const |
| Creates a new query builder for the given table with an alias, compatible with the SQL server being connected. | |
| LIGHTWEIGHT_API SQLHSTMT | NativeHandle () const noexcept |
| Retrieves the native handle of the statement. | |
| LIGHTWEIGHT_API void | Prepare (std::string_view query) & |
| LIGHTWEIGHT_API SqlStatement | Prepare (std::string_view query) && |
| Prepares the statement for execution on an rvalue reference and returns the statement. | |
| void | Prepare (SqlQueryObject auto const &queryObject) & |
| SqlStatement | Prepare (SqlQueryObject auto const &queryObject) && |
| Prepares the statement from a query object on an rvalue reference and returns the statement. | |
| std::string const & | PreparedQuery () const noexcept |
| Retrieves the last prepared query string. | |
| template<SqlInputParameterBinder Arg> | |
| void | BindInputParameter (SQLSMALLINT columnIndex, Arg const &arg) |
| Binds an input parameter to the prepared statement at the given column index. | |
| template<SqlInputParameterBinder Arg, typename ColumnName > | |
| void | BindInputParameter (SQLSMALLINT columnIndex, Arg const &arg, ColumnName &&columnNameHint) |
| Binds an input parameter to the prepared statement at the given column index with a column name hint. | |
| template<SqlInputParameterBinder... Args> | |
| SqlResultCursor | Execute (Args const &... args) |
| Binds the given arguments to the prepared statement and executes it. | |
| LIGHTWEIGHT_API SqlResultCursor | ExecuteWithVariants (std::vector< SqlVariant > const &args) |
| Binds the given arguments to the prepared statement and executes it. | |
| template<SqlInputParameterBatchBinder FirstColumnBatch, std::ranges::contiguous_range... MoreColumnBatches> | |
| SqlResultCursor | ExecuteBatchNative (FirstColumnBatch const &firstColumnBatch, MoreColumnBatches const &... moreColumnBatches) |
| template<SqlInputParameterBatchBinder FirstColumnBatch, std::ranges::range... MoreColumnBatches> | |
| SqlResultCursor | ExecuteBatchSoft (FirstColumnBatch const &firstColumnBatch, MoreColumnBatches const &... moreColumnBatches) |
| template<SqlInputParameterBatchBinder FirstColumnBatch, std::ranges::range... MoreColumnBatches> | |
| SqlResultCursor | ExecuteBatch (FirstColumnBatch const &firstColumnBatch, MoreColumnBatches const &... moreColumnBatches) |
| LIGHTWEIGHT_API SqlResultCursor | ExecuteBatch (std::span< SqlRawColumn const > columns, size_t rowCount) |
| LIGHTWEIGHT_API SqlResultCursor | ExecuteDirect (std::string_view const &query, std::source_location location=std::source_location::current()) |
| Executes the given query directly. | |
| SqlResultCursor | ExecuteDirect (SqlQueryObject auto const &query, std::source_location location=std::source_location::current()) |
| Executes the given query directly. | |
| template<typename Callable > requires std::invocable<Callable, SqlMigrationQueryBuilder&> | |
| void | MigrateDirect (Callable const &callable, std::source_location location=std::source_location::current()) |
| Executes an SQL migration query, as created b the callback. | |
| template<typename T > requires (!std::same_as<T, SqlVariant>) | |
| std::optional< T > | ExecuteDirectScalar (std::string_view const &query, std::source_location location=std::source_location::current()) |
| template<typename T > requires (std::same_as<T, SqlVariant>) | |
| T | ExecuteDirectScalar (std::string_view const &query, std::source_location location=std::source_location::current()) |
| Executes the given query and returns the single result as an SqlVariant. | |
| template<typename T > requires (!std::same_as<T, SqlVariant>) | |
| std::optional< T > | ExecuteDirectScalar (SqlQueryObject auto const &query, std::source_location location=std::source_location::current()) |
| template<typename T > requires (std::same_as<T, SqlVariant>) | |
| T | ExecuteDirectScalar (SqlQueryObject auto const &query, std::source_location location=std::source_location::current()) |
| Executes the given query object and returns the single result as an SqlVariant. | |
| LIGHTWEIGHT_API size_t | LastInsertId (std::string_view tableName) |
| Retrieves the last insert ID of the given table. | |
| template<SqlOutputColumnBinder... Args> | |
| LIGHTWEIGHT_FORCE_INLINE void | BindOutputColumns (Args *... args) |
| template<SqlOutputColumnBinder T> | |
| LIGHTWEIGHT_FORCE_INLINE void | BindOutputColumn (SQLUSMALLINT columnIndex, T *arg) |
| template<SqlInputParameterBinder Arg> | |
| LIGHTWEIGHT_FORCE_INLINE void | BindInputParameter (SQLSMALLINT columnIndex, Arg const &arg) |
| Binds an input parameter to the prepared statement at the given column index. | |
| template<SqlInputParameterBinder Arg, typename ColumnName > | |
| LIGHTWEIGHT_FORCE_INLINE void | BindInputParameter (SQLSMALLINT columnIndex, Arg const &arg, ColumnName &&columnNameHint) |
| Binds an input parameter to the prepared statement at the given column index with a column name hint. | |
| template<SqlInputParameterBatchBinder FirstColumnBatch, std::ranges::range... MoreColumnBatches> | |
| LIGHTWEIGHT_FORCE_INLINE SqlResultCursor | ExecuteBatch (FirstColumnBatch const &firstColumnBatch, MoreColumnBatches const &... moreColumnBatches) |
Public Member Functions inherited from Lightweight::SqlDataBinderCallback | |
| SqlDataBinderCallback ()=default | |
| Default constructor. | |
| SqlDataBinderCallback (SqlDataBinderCallback &&)=default | |
| Default move constructor. | |
| SqlDataBinderCallback (SqlDataBinderCallback const &)=default | |
| Default copy constructor. | |
| SqlDataBinderCallback & | operator= (SqlDataBinderCallback &&)=default |
| Default move assignment operator. | |
| SqlDataBinderCallback & | operator= (SqlDataBinderCallback const &)=default |
| Default copy assignment operator. | |
High level API for (prepared) raw SQL statements.
SQL prepared statement lifecycle:
Definition at line 52 of file SqlStatement.hpp.
|
inlinenoexcept |
Checks whether the statement's connection is alive and the statement handle is valid.
Definition at line 594 of file SqlStatement.hpp.
References Lightweight::SqlConnection::IsAlive().
|
inlinenoexcept |
Checks whether the statement has been prepared.
Definition at line 599 of file SqlStatement.hpp.
|
inlinenoexcept |
Retrieves the connection associated with this statement.
Definition at line 604 of file SqlStatement.hpp.
Referenced by Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::All(), Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::All(), Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::Count(), Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::Delete(), Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::Exist(), Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::First(), Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::First(), Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::First(), MigrateDirect(), Lightweight::DataMapper::Query(), Lightweight::DataMapper::Query(), Lightweight::DataMapper::Query(), Lightweight::DataMapper::QuerySingle(), and Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::Range().
|
inlinenoexcept |
Retrieves the connection associated with this statement.
Definition at line 609 of file SqlStatement.hpp.
|
inline |
Retrieves the last error information with respect to this SQL statement handle.
Definition at line 614 of file SqlStatement.hpp.
References Lightweight::SqlErrorInfo::FromStatementHandle().
|
inlinenoexcept |
Retrieves the native handle of the statement.
Definition at line 619 of file SqlStatement.hpp.
| LIGHTWEIGHT_API void Lightweight::SqlStatement::Prepare | ( | std::string_view | query | ) | & |
Prepares the statement for execution.
Referenced by Lightweight::DataMapper::ConfigureRelationAutoLoading(), Lightweight::DataMapper::Delete(), Lightweight::DataMapper::Query(), Lightweight::DataMapper::Query(), Lightweight::DataMapper::Query(), Lightweight::DataMapper::QuerySingle(), and Lightweight::DataMapper::Update().
|
inline |
Prepares the statement for execution.
Definition at line 624 of file SqlStatement.hpp.
|
inline |
Prepares the statement from a query object on an rvalue reference and returns the statement.
Definition at line 629 of file SqlStatement.hpp.
|
inlinenoexcept |
Retrieves the last prepared query string.
Definition at line 634 of file SqlStatement.hpp.
| SqlResultCursor Lightweight::SqlStatement::Execute | ( | Args const &... | args | ) |
Binds the given arguments to the prepared statement and executes it.
Definition at line 694 of file SqlStatement.hpp.
References Lightweight::SqlErrorInfo::FromStatementHandle(), Lightweight::SqlLogger::GetLogger(), Lightweight::SqlLogger::OnBindInputParameter(), and Lightweight::SqlLogger::OnExecute().
Referenced by Lightweight::DataMapper::ConfigureRelationAutoLoading(), Lightweight::DataMapper::Delete(), Lightweight::DataMapper::Query(), Lightweight::DataMapper::Query(), Lightweight::DataMapper::Query(), Lightweight::DataMapper::QuerySingle(), and Lightweight::DataMapper::Update().
| SqlResultCursor Lightweight::SqlStatement::ExecuteBatchNative | ( | FirstColumnBatch const & | firstColumnBatch, |
| MoreColumnBatches const &... | moreColumnBatches | ||
| ) |
Executes the prepared statement on a batch of data.
Each parameter represents a column, to be bound as input parameter. The element types of each column container must be explicitly supported.
In order to support column value types, their underlying storage must be contiguous. Also the input range itself must be contiguous. If any of these conditions are not met, the function will not compile - use ExecuteBatch() instead.
Definition at line 752 of file SqlStatement.hpp.
Referenced by ExecuteBatch().
| SqlResultCursor Lightweight::SqlStatement::ExecuteBatchSoft | ( | FirstColumnBatch const & | firstColumnBatch, |
| MoreColumnBatches const &... | moreColumnBatches | ||
| ) |
Executes the prepared statement on a batch of data.
Each parameter represents a column, to be bound as input parameter, and the number of elements in these bound column containers will mandate how many executions will happen.
This function will bind and execute each row separately, which is less efficient than ExecuteBatchNative(), but works non-contiguous input ranges.
Definition at line 800 of file SqlStatement.hpp.
Referenced by ExecuteBatch().
| SqlResultCursor Lightweight::SqlStatement::ExecuteBatch | ( | FirstColumnBatch const & | firstColumnBatch, |
| MoreColumnBatches const &... | moreColumnBatches | ||
| ) |
Executes the prepared statement on a batch of data.
Each parameter represents a column, to be bound as input parameter, and the number of elements in these bound column containers will mandate how many executions will happen.
| LIGHTWEIGHT_API SqlResultCursor Lightweight::SqlStatement::ExecuteBatch | ( | std::span< SqlRawColumn const > | columns, |
| size_t | rowCount | ||
| ) |
Executes the prepared statement on a batch of SqlRawColumn-prepared data.
| columns | The columns to bind as input parameters. |
| rowCount | The number of rows to execute. |
|
inline |
Executes the given query directly.
Definition at line 872 of file SqlStatement.hpp.
References ExecuteDirect().
| void Lightweight::SqlStatement::MigrateDirect | ( | Callable const & | callable, |
| std::source_location | location = std::source_location::current() |
||
| ) |
Executes an SQL migration query, as created b the callback.
Definition at line 880 of file SqlStatement.hpp.
References Connection(), ExecuteDirect(), and Lightweight::SqlConnection::QueryFormatter().
|
inline |
Executes the given query, assuming that only one result row and column is affected, that one will be returned.
Definition at line 893 of file SqlStatement.hpp.
Referenced by Lightweight::DataMapper::Execute().
|
inline |
Executes the given query and returns the single result as an SqlVariant.
Definition at line 902 of file SqlStatement.hpp.
References Lightweight::SqlNullValue.
|
inline |
Executes the given query, assuming that only one result row and column is affected, that one will be returned.
Definition at line 913 of file SqlStatement.hpp.
|
inline |
Executes the given query object and returns the single result as an SqlVariant.
Definition at line 920 of file SqlStatement.hpp.
|
inline |
Definition at line 641 of file SqlStatement.hpp.
|
inline |
Definition at line 667 of file SqlStatement.hpp.
|
inline |
Binds an input parameter to the prepared statement at the given column index.
Definition at line 676 of file SqlStatement.hpp.
|
inline |
Binds an input parameter to the prepared statement at the given column index with a column name hint.
Definition at line 685 of file SqlStatement.hpp.
References BindInputParameter(), Lightweight::SqlLogger::GetLogger(), and Lightweight::SqlLogger::OnBindInputParameter().
|
inline |
Executes the prepared statement on a batch of data.
Each parameter represents a column, to be bound as input parameter, and the number of elements in these bound column containers will mandate how many executions will happen.
Definition at line 788 of file SqlStatement.hpp.
References ExecuteBatchNative(), and ExecuteBatchSoft().