statement binding progress

This commit is contained in:
Sascha Kühl
2025-10-13 16:14:03 +02:00
parent 24842f3313
commit d0e2e4340e
12 changed files with 147 additions and 101 deletions
+25 -6
View File
@@ -2,16 +2,35 @@
namespace matador::sql {
statement_impl::statement_impl(query_context query)
statement_impl::statement_impl(query_context query, const size_t start_bind_pos)
: query_(std::move(query))
, start_bind_pos_(start_bind_pos)
{}
void statement_impl::bind(const size_t pos, const char *value, const size_t size, parameter_binder& bindings) const {
utils::data_type_traits<const char*>::bind_value(bindings, adjust_index(pos), value, size);
void statement_impl::bind(const size_t pos, const char *value, const size_t size, parameter_binder& bindings) {
current_bind_pos_ = pos;
bind(value, size, bindings);
}
void statement_impl::bind(const size_t pos, std::string &val, const size_t size, parameter_binder& bindings) const {
utils::data_type_traits<std::string>::bind_value(bindings, adjust_index(pos), val, size);
void statement_impl::bind(const char* value, const size_t size, parameter_binder& bindings) {
utils::data_type_traits<const char*>::bind_value(bindings, adjust_index(current_bind_pos_++), value, size);
}
void statement_impl::bind(const size_t pos, std::string &value, const size_t size, parameter_binder& bindings) {
current_bind_pos_ = pos;
bind(value, size, bindings);
}
void statement_impl::bind(std::string& value, const size_t size, parameter_binder& bindings) {
utils::data_type_traits<std::string>::bind_value(bindings, adjust_index(current_bind_pos_++), value, size);
}
void statement_impl::reset() {
current_bind_pos_ = start_bind_pos_;
}
size_t statement_impl::bind_pos() const {
return current_bind_pos_;
}
const std::vector<std::string> &statement_impl::bind_vars() const {
@@ -25,7 +44,7 @@ bool statement_impl::is_valid_host_var(const std::string &host_var, const size_t
}
size_t statement_impl::start_index() const {
return 0;
return start_bind_pos_;
}
size_t statement_impl::adjust_index(const size_t index) const {
@@ -7,14 +7,24 @@ statement_proxy::statement_proxy(std::unique_ptr<statement_impl>&& stmt)
void statement_proxy::bind(const size_t pos, const char* value, const size_t size, parameter_binder& bindings) const {
statement_->bind(pos, value, size, bindings);
}
void statement_proxy::bind(const char* value, const size_t size, parameter_binder& bindings) const {
statement_->bind(value, size, bindings);
}
void statement_proxy::bind(const size_t pos, std::string& val, const size_t size, parameter_binder& bindings) const {
statement_->bind(pos, val, size, bindings);
}
void statement_proxy::bind(std::string& val, const size_t size, parameter_binder& bindings) const {
statement_->bind(val, size, bindings);
}
void statement_proxy::reset() const {
statement_->reset();
}
size_t statement_proxy::bind_pos() const {
return statement_->bind_pos();
}
std::string statement_proxy::sql() const {
return statement_->query_.sql;
}
+2 -9
View File
@@ -1,13 +1,7 @@
#include "matador/sql/object_parameter_binder.hpp"
#include "matador/sql/interface/parameter_binder.hpp"
namespace matador::sql {
object_parameter_binder::object_parameter_binder(bool include_primary_key)
: include_primary_key_(include_primary_key) {
}
void object_parameter_binder::reset(const size_t start_index)
{
void object_parameter_binder::reset(const size_t start_index) {
index_ = start_index;
}
@@ -15,8 +9,7 @@ size_t object_parameter_binder::current_index() const {
return index_;
}
void object_parameter_binder::on_revision(const char * /*id*/, uint64_t &rev)
{
void object_parameter_binder::on_revision(const char * /*id*/, uint64_t &rev) {
utils::data_type_traits<uint64_t>::bind_value(*binder_, index_++, rev);
}
+5 -2
View File
@@ -86,11 +86,14 @@ utils::result<std::optional<record>, utils::error> statement::fetch_one() const
return utils::ok(std::optional{*first.release()});
}
void statement::reset() const
{
void statement::reset() const {
statement_proxy_->reset();
}
size_t statement::bind_pos() const {
return statement_proxy_->bind_pos();
}
std::string statement::sql() const {
return statement_proxy_->sql();
}