moved parameter_binder from member to parameter to bind, execute and fetch methods
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "matador/sql/query_result.hpp"
|
||||
|
||||
#include "matador/sql/interface/statement_proxy.hpp"
|
||||
#include "matador/sql/interface/parameter_binder.hpp"
|
||||
|
||||
#include "matador/utils/error.hpp"
|
||||
#include "matador/utils/result.hpp"
|
||||
@@ -38,10 +39,7 @@ public:
|
||||
*
|
||||
* @param x The statement to move from
|
||||
*/
|
||||
statement(statement &&x) noexcept
|
||||
: statement_proxy_(std::move(x.statement_proxy_))
|
||||
, logger_(std::move(x.logger_)) {
|
||||
}
|
||||
statement(statement &&x) noexcept;
|
||||
|
||||
/**
|
||||
* Assignment move constructor for statement
|
||||
@@ -49,14 +47,10 @@ public:
|
||||
* @param x The statement to move from
|
||||
* @return Reference to this
|
||||
*/
|
||||
statement &operator=(statement &&x) noexcept {
|
||||
statement_proxy_ = std::move(x.statement_proxy_);
|
||||
logger_ = std::move(x.logger_);
|
||||
return *this;
|
||||
}
|
||||
statement &operator=(statement &&x) noexcept;
|
||||
|
||||
statement(const statement &x) = default;
|
||||
statement &operator=(const statement &x) = default;
|
||||
statement(const statement &x);
|
||||
statement &operator=(const statement &x);
|
||||
|
||||
statement &bind(size_t pos, const char *value);
|
||||
statement &bind(size_t pos, std::string &val, size_t size);
|
||||
@@ -134,24 +128,25 @@ private:
|
||||
|
||||
private:
|
||||
std::shared_ptr<statement_proxy> statement_proxy_;
|
||||
std::unique_ptr<utils::attribute_writer> bindings_;
|
||||
std::shared_ptr<abstract_sql_logger> logger_;
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
statement &statement::bind(size_t pos, Type &value) {
|
||||
statement_proxy_->bind(pos, value);
|
||||
statement_proxy_->bind(pos, value, *bindings_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
statement &statement::bind(const Type &obj) {
|
||||
statement_proxy_->bind(obj);
|
||||
statement_proxy_->bind(obj, bindings_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
utils::result<query_result<Type>, utils::error> statement::fetch() {
|
||||
return statement_proxy_->fetch().and_then([](std::unique_ptr<query_result_impl> &&value) {
|
||||
return statement_proxy_->fetch(*bindings_).and_then([](std::unique_ptr<query_result_impl> &&value) {
|
||||
return utils::ok(query_result<Type>(std::forward<decltype(value)>(value)));
|
||||
});
|
||||
// if (!result.is_ok()) {
|
||||
@@ -162,7 +157,7 @@ utils::result<query_result<Type>, utils::error> statement::fetch() {
|
||||
|
||||
template<class Type>
|
||||
utils::result<std::unique_ptr<Type>, utils::error> statement::fetch_one() {
|
||||
auto result = statement_proxy_->fetch();
|
||||
auto result = statement_proxy_->fetch(*bindings_);
|
||||
if (!result.is_ok()) {
|
||||
return utils::failure(result.err());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user