75 lines
2.3 KiB
C++
75 lines
2.3 KiB
C++
#ifndef QUERY_STATEMENT_IMPL_HPP
|
|
#define QUERY_STATEMENT_IMPL_HPP
|
|
|
|
#include "matador/sql/query_context.hpp"
|
|
#include "matador/sql/internal/query_result_impl.hpp"
|
|
#include "matador/sql/interface/parameter_binder.hpp"
|
|
#include "matador/sql/object_parameter_binder.hpp"
|
|
|
|
#include "matador/utils/data_type_traits.hpp"
|
|
|
|
#include <memory>
|
|
|
|
namespace matador::sql {
|
|
|
|
class sql_error;
|
|
|
|
class statement_impl
|
|
{
|
|
protected:
|
|
explicit statement_impl(query_context query, size_t start_bind_pos);
|
|
|
|
public:
|
|
virtual ~statement_impl() = default;
|
|
|
|
virtual utils::result<size_t, utils::error> execute(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 >
|
|
void bind_object(Type &obj, parameter_binder& bindings) {
|
|
object_parameter_binder object_binder_;
|
|
object_binder_.reset(start_index());
|
|
object_binder_.bind(obj, bindings);
|
|
|
|
current_bind_pos_ = object_binder_.current_index();
|
|
}
|
|
|
|
template < class Type >
|
|
void bind(const size_t pos, Type &val, parameter_binder& bindings) {
|
|
current_bind_pos_ = pos;
|
|
bind(val, bindings);
|
|
}
|
|
template < class Type >
|
|
void bind(Type &val, parameter_binder& bindings) {
|
|
utils::data_type_traits<Type>::bind_value(bindings, adjust_index(current_bind_pos_++), val);
|
|
}
|
|
void bind(size_t pos, const char *value, size_t size, parameter_binder& bindings);
|
|
void bind(const char *value, size_t size, parameter_binder& bindings);
|
|
void bind(size_t pos, std::string &val, size_t size, parameter_binder& bindings);
|
|
void bind(std::string &value, size_t size, parameter_binder& bindings);
|
|
|
|
virtual void reset();
|
|
|
|
[[nodiscard]] size_t bind_pos() const;
|
|
|
|
[[nodiscard]] const std::vector<std::string>& bind_vars() const;
|
|
[[nodiscard]] bool is_valid_host_var(const std::string &host_var, size_t pos) const;
|
|
|
|
protected:
|
|
[[nodiscard]] virtual size_t start_index() const;
|
|
[[nodiscard]] virtual size_t adjust_index(size_t index) const;
|
|
[[nodiscard]] virtual std::unique_ptr<utils::attribute_writer> create_binder() const = 0;
|
|
|
|
protected:
|
|
friend class statement;
|
|
friend class statement_proxy;
|
|
|
|
query_context query_;
|
|
size_t start_bind_pos_{0};
|
|
size_t current_bind_pos_{0};
|
|
};
|
|
|
|
}
|
|
|
|
#endif //QUERY_STATEMENT_IMPL_HPP
|