moved parameter_binder from member to parameter to bind, execute and fetch methods
This commit is contained in:
@@ -19,11 +19,11 @@ public:
|
||||
explicit connection_statement_proxy(std::unique_ptr<statement_impl>&& stmt)
|
||||
: statement_proxy(std::move(stmt)) {}
|
||||
|
||||
utils::result<size_t, utils::error> execute() override {
|
||||
return statement_->execute();
|
||||
utils::result<size_t, utils::error> execute(interface::parameter_binder& bindings) override {
|
||||
return statement_->execute(bindings);
|
||||
}
|
||||
utils::result<std::unique_ptr<query_result_impl>, utils::error> fetch() override {
|
||||
return statement_->fetch();
|
||||
utils::result<std::unique_ptr<query_result_impl>, utils::error> fetch(interface::parameter_binder& bindings) override {
|
||||
return statement_->fetch(bindings);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -6,35 +6,29 @@ statement_impl::statement_impl(query_context query)
|
||||
: query_(std::move(query))
|
||||
{}
|
||||
|
||||
void statement_impl::bind(const size_t pos, const char *value, const size_t size)
|
||||
{
|
||||
utils::data_type_traits<const char*>::bind_value(binder(), adjust_index(pos), value, size);
|
||||
void statement_impl::bind(const size_t pos, const char *value, const size_t size, interface::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, std::string &val, const size_t size)
|
||||
{
|
||||
utils::data_type_traits<std::string>::bind_value(binder(), adjust_index(pos), val, size);
|
||||
void statement_impl::bind(const size_t pos, std::string &val, const size_t size, interface::parameter_binder& bindings) const {
|
||||
utils::data_type_traits<std::string>::bind_value(bindings, adjust_index(pos), val, size);
|
||||
}
|
||||
|
||||
const std::vector<std::string> &statement_impl::bind_vars() const
|
||||
{
|
||||
const std::vector<std::string> &statement_impl::bind_vars() const {
|
||||
return query_.bind_vars;
|
||||
}
|
||||
|
||||
bool statement_impl::is_valid_host_var(const std::string &host_var, const size_t pos) const
|
||||
{
|
||||
bool statement_impl::is_valid_host_var(const std::string &host_var, const size_t pos) const {
|
||||
const auto host_var_at_pos = bind_vars().at(pos);
|
||||
|
||||
return host_var_at_pos == host_var;
|
||||
}
|
||||
|
||||
size_t statement_impl::start_index() const
|
||||
{
|
||||
size_t statement_impl::start_index() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t statement_impl::adjust_index( size_t index ) const
|
||||
{
|
||||
size_t statement_impl::adjust_index(const size_t index) const {
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,14 +4,18 @@ namespace matador::sql {
|
||||
statement_proxy::statement_proxy(std::unique_ptr<statement_impl>&& stmt)
|
||||
: statement_(std::move(stmt)){}
|
||||
|
||||
void statement_proxy::bind(const size_t pos, const char* value, const size_t size) const {
|
||||
statement_->bind(pos, value, size);
|
||||
void statement_proxy::bind(const size_t pos, const char* value, const size_t size, interface::parameter_binder& bindings) const {
|
||||
statement_->bind(pos, value, size, bindings);
|
||||
}
|
||||
void statement_proxy::bind(const size_t pos, std::string& val, const size_t size) const {
|
||||
statement_->bind(pos, val, size);
|
||||
void statement_proxy::bind(const size_t pos, std::string& val, const size_t size, interface::parameter_binder& bindings) const {
|
||||
statement_->bind(pos, val, size, bindings);
|
||||
}
|
||||
|
||||
void statement_proxy::reset() const {
|
||||
statement_->reset();
|
||||
}
|
||||
|
||||
std::unique_ptr<utils::attribute_writer> statement_proxy::create_binder() const {
|
||||
return statement_->create_binder();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,20 +11,47 @@ statement::statement(const std::shared_ptr<statement_proxy>& proxy, logger_ptr
|
||||
: statement_proxy_(proxy)
|
||||
, logger_(std::move(logger)){}
|
||||
|
||||
statement &statement::bind(const size_t pos, const char *value) {
|
||||
statement_proxy_->bind(pos, value, strlen(value));
|
||||
statement::statement(statement&& x) noexcept
|
||||
: statement_proxy_(std::move(x.statement_proxy_))
|
||||
, bindings_(std::move(x.bindings_))
|
||||
, logger_(std::move(x.logger_)) {
|
||||
}
|
||||
|
||||
statement& statement::operator=(statement&& x) noexcept {
|
||||
statement_proxy_ = std::move(x.statement_proxy_);
|
||||
bindings_ = std::move(x.bindings_);
|
||||
logger_ = std::move(x.logger_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
statement &statement::bind(const size_t pos, std::string &val, const size_t size)
|
||||
{
|
||||
statement_proxy_->bind(pos, val, size);
|
||||
statement::statement(const statement& x)
|
||||
: statement_proxy_(x.statement_proxy_)
|
||||
, bindings_(x.statement_proxy_->create_binder())
|
||||
, logger_(x.logger_) {
|
||||
}
|
||||
statement& statement::operator=(const statement& x) {
|
||||
if (&x == this) {
|
||||
return *this;
|
||||
}
|
||||
statement_proxy_ = x.statement_proxy_;
|
||||
bindings_ = x.statement_proxy_->create_binder();
|
||||
logger_ = x.logger_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
statement &statement::bind(const size_t pos, const char *value) {
|
||||
statement_proxy_->bind(pos, value, strlen(value), *bindings_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
statement &statement::bind(const size_t pos, std::string &val, const size_t size) {
|
||||
statement_proxy_->bind(pos, val, size, *bindings_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
utils::result<size_t, utils::error> statement::execute() const {
|
||||
// logger_.info(statement_->query_.sql);
|
||||
return statement_proxy_->execute();
|
||||
return statement_proxy_->execute(*bindings_);
|
||||
}
|
||||
|
||||
//bool is_unknown(const std::vector<object::column_definition> &columns) {
|
||||
@@ -39,7 +66,7 @@ utils::result<query_result<record>, utils::error> statement::fetch() const {
|
||||
// }
|
||||
|
||||
|
||||
auto result = statement_proxy_->fetch();
|
||||
auto result = statement_proxy_->fetch(*bindings_);
|
||||
if (!result.is_ok()) {
|
||||
return utils::failure(result.err());
|
||||
}
|
||||
@@ -49,7 +76,7 @@ utils::result<query_result<record>, utils::error> statement::fetch() const {
|
||||
|
||||
utils::result<std::optional<record>, utils::error> statement::fetch_one() const {
|
||||
// logger_.info(statement_->query_.sql);
|
||||
auto result = statement_proxy_->fetch();
|
||||
auto result = statement_proxy_->fetch(*bindings_);
|
||||
if (!result.is_ok()) {
|
||||
return utils::failure(result.err());
|
||||
}
|
||||
|
||||
@@ -10,11 +10,11 @@ public:
|
||||
explicit statement_cache_proxy(std::unique_ptr<statement_impl>&& stmt)
|
||||
: statement_proxy(std::move(stmt)) {}
|
||||
|
||||
utils::result<size_t, utils::error> execute() override {
|
||||
return statement_->execute();
|
||||
utils::result<size_t, utils::error> execute(interface::parameter_binder& bindings) override {
|
||||
return statement_->execute(bindings);
|
||||
}
|
||||
utils::result<std::unique_ptr<query_result_impl>, utils::error> fetch() override {
|
||||
return statement_->fetch();
|
||||
utils::result<std::unique_ptr<query_result_impl>, utils::error> fetch(interface::parameter_binder& bindings) override {
|
||||
return statement_->fetch(bindings);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -43,8 +43,8 @@ utils::result<statement, utils::error> statement_cache::acquire(const query_cont
|
||||
|
||||
// If cache max size reached ensure space
|
||||
if (cache_map_.size() >= max_size_) {
|
||||
const size_t& lru_key = usage_list_.back();
|
||||
cache_map_.erase(lru_key);
|
||||
const auto& key_to_remove = usage_list_.back();
|
||||
cache_map_.erase(key_to_remove);
|
||||
usage_list_.pop_back();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user