session update progress
This commit is contained in:
parent
1cda78412b
commit
24842f3313
|
|
@ -29,7 +29,7 @@ public:
|
||||||
|
|
||||||
template < class V >
|
template < class V >
|
||||||
void on_primary_key(const char *id, V &x, const utils::primary_key_attribute& /*attr*/ = utils::default_pk_attributes) {
|
void on_primary_key(const char *id, V &x, const utils::primary_key_attribute& /*attr*/ = utils::default_pk_attributes) {
|
||||||
result_.emplace_back(id, x);
|
// result_.emplace_back(id, x);
|
||||||
}
|
}
|
||||||
void on_revision(const char *id, uint64_t &/*rev*/);
|
void on_revision(const char *id, uint64_t &/*rev*/);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,12 @@ public:
|
||||||
virtual utils::result<std::unique_ptr<query_result_impl>, utils::error> fetch(const parameter_binder& bindings) = 0;
|
virtual utils::result<std::unique_ptr<query_result_impl>, utils::error> fetch(const parameter_binder& bindings) = 0;
|
||||||
|
|
||||||
template < class Type >
|
template < class Type >
|
||||||
void bind_object(Type &obj, parameter_binder& bindings) {
|
size_t bind_object(Type &obj, parameter_binder& bindings) {
|
||||||
object_parameter_binder object_binder_;
|
object_parameter_binder object_binder_(query_.command != sql_command::SQL_UPDATE);
|
||||||
object_binder_.reset(start_index());
|
object_binder_.reset(start_index());
|
||||||
object_binder_.bind(obj, bindings);
|
object_binder_.bind(obj, bindings);
|
||||||
|
|
||||||
|
return object_binder_.current_index();
|
||||||
}
|
}
|
||||||
|
|
||||||
template < class Type >
|
template < class Type >
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,8 @@ private:
|
||||||
|
|
||||||
class object_parameter_binder {
|
class object_parameter_binder {
|
||||||
public:
|
public:
|
||||||
|
explicit object_parameter_binder(bool include_primary_key = true);
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
void bind(Type &obj, utils::attribute_writer &binder) {
|
void bind(Type &obj, utils::attribute_writer &binder) {
|
||||||
binder_ = &binder;
|
binder_ = &binder;
|
||||||
|
|
@ -69,11 +71,14 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset(size_t start_index);
|
void reset(size_t start_index);
|
||||||
|
[[nodiscard]] size_t current_index() const;
|
||||||
|
|
||||||
template < class Type >
|
template < class Type >
|
||||||
void on_primary_key(const char * /*id*/, Type &val, const utils::primary_key_attribute& attr = utils::default_pk_attributes) {
|
void on_primary_key(const char * /*id*/, Type &val, const utils::primary_key_attribute& attr = utils::default_pk_attributes) {
|
||||||
|
if (include_primary_key_) {
|
||||||
utils::data_type_traits<Type>::bind_value(*binder_, index_++, val, attr.size());
|
utils::data_type_traits<Type>::bind_value(*binder_, index_++, val, attr.size());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
void on_revision(const char *id, uint64_t &/*rev*/);
|
void on_revision(const char *id, uint64_t &/*rev*/);
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
|
|
@ -109,6 +114,7 @@ private:
|
||||||
utils::attribute_writer *binder_{};
|
utils::attribute_writer *binder_{};
|
||||||
size_t index_{0};
|
size_t index_{0};
|
||||||
detail::fk_binder fk_binder_;
|
detail::fk_binder fk_binder_;
|
||||||
|
bool include_primary_key_{true};
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,19 @@
|
||||||
#include "matador/sql/interface/parameter_binder.hpp"
|
#include "matador/sql/interface/parameter_binder.hpp"
|
||||||
|
|
||||||
namespace matador::sql {
|
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;
|
index_ = start_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
utils::data_type_traits<uint64_t>::bind_value(*binder_, index_++, rev);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue