#include "matador/sql/statement.hpp" #include "matador/sql/record.hpp" #include "matador/sql/field.hpp" #include namespace matador::sql { statement::statement(std::unique_ptr impl, const std::shared_ptr &logger) : statement_(std::move(impl)) , logger_(logger) {} statement &statement::bind(const size_t pos, const char *value) { statement_->bind(pos, value, 0); return *this; } statement &statement::bind(const size_t pos, std::string &val, const size_t size) { statement_->bind(pos, val, size); return *this; } utils::result statement::execute() const { // logger_.info(statement_->query_.sql); return statement_->execute(); } //bool is_unknown(const std::vector &columns) { // return std::all_of(std::begin(columns), std::end(columns), [](const auto &col) { // return col.is_unknown(); // }); //} utils::result, utils::error> statement::fetch() const { // if (is_unknown(statement_->query_.prototype)) { // // } auto result = statement_->fetch(); if (!result.is_ok()) { return utils::failure(result.err()); } // logger_.info(statement_->query_.sql); return utils::ok(query_result{std::move(*result)}); } utils::result, utils::error> statement::fetch_one() const { // logger_.info(statement_->query_.sql); auto result = statement_->fetch(); if (!result.is_ok()) { return utils::failure(result.err()); } query_result records(std::move(*result)); auto first = records.begin(); if (first == records.end()) { return utils::ok(std::optional{std::nullopt}); } return utils::ok(std::optional{*first.release()}); } void statement::reset() const { statement_->reset(); } }