introduced execute_result
This commit is contained in:
@@ -18,7 +18,7 @@ public:
|
||||
explicit connection_statement_proxy(std::unique_ptr<statement_impl>&& stmt)
|
||||
: statement_proxy(std::move(stmt)) {}
|
||||
|
||||
utils::result<size_t, utils::error> execute(parameter_binder& bindings) override {
|
||||
utils::result<execute_result, utils::error> execute(parameter_binder& bindings) override {
|
||||
return statement_->execute(bindings);
|
||||
}
|
||||
utils::result<std::unique_ptr<query_result_impl>, utils::error> fetch(parameter_binder& bindings) override {
|
||||
@@ -163,53 +163,22 @@ utils::result<bool, utils::error> connection::exists(const std::string &table_na
|
||||
return connection_->exists(dialect().default_schema_name(), table_name);
|
||||
}
|
||||
|
||||
utils::result<size_t, utils::error> connection::execute(const std::string &sql) const {
|
||||
logger_->on_execute(sql);
|
||||
std::cout << sql << std::endl;
|
||||
return connection_->execute(sql);
|
||||
}
|
||||
|
||||
bool has_unknown_columns(const std::vector<object::attribute> &columns) {
|
||||
return std::any_of(std::begin(columns), std::end(columns), [](const auto &col) {
|
||||
return col.type() == utils::basic_type::Null;
|
||||
});
|
||||
}
|
||||
|
||||
// query_result<record> connection::fetch(const query_context &ctx) const
|
||||
// {
|
||||
// if (ctx.prototype.empty() || is_unknown(ctx.prototype)) {
|
||||
// const auto table_prototype = describe(ctx.table.name);
|
||||
// for (auto &col : ctx.prototype) {
|
||||
// const auto rit = std::find_if(std::begin(table_prototype), std::end(table_prototype), [&col](const auto &value) {
|
||||
// return value.name() == col.name();
|
||||
// });
|
||||
// if (col.type() == data_type::type_unknown && rit != table_prototype.end()) {
|
||||
// const_cast<column_definition&>(col).type(rit->type());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// // auto it = prototypes_.find(q.table_name);
|
||||
// // if (it == prototypes_.end()) {
|
||||
// // it = prototypes_.emplace(q.table_name, describe(q.table_name)).first;
|
||||
// // }
|
||||
// // // adjust columns from given query
|
||||
// // for (auto &col : q.prototype) {
|
||||
// // if (const auto rit = it->second.find(col.name()); col.type() == data_type_t::type_unknown && rit != it->second.end()) {
|
||||
// // const_cast<column&>(col).type(rit->type());
|
||||
// // }
|
||||
// // }
|
||||
// auto res = fetch(ctx.sql);
|
||||
// return query_result<record>{std::move(res), ctx.prototype};
|
||||
// }
|
||||
|
||||
utils::result<std::unique_ptr<query_result_impl>, utils::error> connection::fetch(const query_context &ctx) const {
|
||||
logger_->on_fetch(ctx.sql);
|
||||
std::cout << ctx.sql << std::endl;
|
||||
return connection_->fetch(ctx);
|
||||
}
|
||||
|
||||
utils::result<size_t, utils::error> connection::execute(const query_context& ctx) const {
|
||||
return execute(ctx.sql);
|
||||
utils::result<execute_result, utils::error> connection::execute(const query_context& ctx) const {
|
||||
logger_->on_execute(ctx.sql);
|
||||
std::cout << ctx.sql << std::endl;
|
||||
return connection_->execute(ctx.sql);
|
||||
}
|
||||
|
||||
utils::result<statement, utils::error> connection::prepare(const query_context &ctx) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "matador/sql/statement.hpp"
|
||||
#include "matador/sql/execute_result.hpp"
|
||||
#include "matador/sql/record.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -49,7 +50,7 @@ statement &statement::bind(const size_t pos, std::string &val, const size_t size
|
||||
return *this;
|
||||
}
|
||||
|
||||
utils::result<size_t, utils::error> statement::execute() const {
|
||||
utils::result<execute_result, utils::error> statement::execute() const {
|
||||
logger_->on_execute(statement_proxy_->sql());
|
||||
std::cout << statement_proxy_->sql() << std::endl;
|
||||
return statement_proxy_->execute(*bindings_);
|
||||
|
||||
@@ -31,10 +31,10 @@ public:
|
||||
, connection_id_(connection_id)
|
||||
, bus_(bus) {}
|
||||
|
||||
utils::result<size_t, utils::error> execute(parameter_binder& bindings) override {
|
||||
utils::result<execute_result, utils::error> execute(parameter_binder& bindings) override {
|
||||
execution_metrics metrics{std::chrono::steady_clock::now()};
|
||||
|
||||
auto result = try_with_retry([this, &bindings, &metrics]() -> utils::result<size_t, utils::error> {
|
||||
auto result = try_with_retry([this, &bindings, &metrics]() -> utils::result<execute_result, utils::error> {
|
||||
const auto query = sql();
|
||||
if (!try_lock()) {
|
||||
++metrics.lock_attempts;
|
||||
|
||||
Reference in New Issue
Block a user