SQT
A C++ ORM framework for SQLite
Loading...
Searching...
No Matches

◆ BeginBindings()

template<QuerierType QUERIER>
auto sqt::Executor< QUERIER >::BeginBindings ( )
noexcept

Begins a binding process to bind parameters to the placeholders.

Returns
A sqt::BinderChain<> instance corresponds to the placeholders in the querier. The instance remains valid until the executor is destructed.
Note
This method is only available for queriers that contain placeholders.

The returned sqt::BinderChain<> instance enables binding parameters in a chain fashion. The number of binders, their order, and their value types correspond exactly to the placeholders in the querier. The following code demonstrates how to use the BeginBindings() method:

// The entity type, assuming its table type has been defined and registered, and its
// columns' names are defined as the same as the entity's field names.
struct MyEntity {
int id{};
std::string name;
int age{};
};
// Create an inserter with three placeholders.
constexpr auto inserter = sqt::DataContext<MyEntity>::MakeInserter(
sqt::Table<MyEntity>.id = sqt::_,
sqt::Table<MyEntity>.name = sqt::_,
sqt::Table<MyEntity>.age = sqt::_
);
// Create an executor for the inserter.
sqt::DataContext<MyEntity> data_context{ shared_db };
auto executor = data_context.Prepare(inserter);
// Bind parameters to the placeholders.
executor.BeginBindings()
.Bind(1) // Binds to the first placeholder of the id column.
.Bind("The First") // Binds to the second placeholder of the name column.
.Bind(18); // Binds to the third placeholder of the age column.
// Execute the statement.
executor.Execute();
Executor< QUERIER > Prepare(const QUERIER &querier)
Creates an executor for executing the specified querier.
Definition data_context.h:639
static constexpr auto MakeInserter() noexcept
Creates an inserter for inserting an entire entity into the database table.
Definition data_context.h:156
See also
sqt::BinderChain<>