implemented sqlite fetch
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#ifndef QUERY_QUERY_RESULT_HPP
|
||||
#define QUERY_QUERY_RESULT_HPP
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "matador/sql/query_result_impl.hpp"
|
||||
|
||||
#include <memory>
|
||||
@@ -23,10 +25,10 @@ public:
|
||||
|
||||
public:
|
||||
query_result_iterator() = default;
|
||||
explicit query_result_iterator(query_result<Type> &res)
|
||||
explicit query_result_iterator(query_result<Type> *res)
|
||||
: result_(res)
|
||||
{}
|
||||
query_result_iterator(query_result<Type> &res, std::unique_ptr<Type> obj)
|
||||
query_result_iterator(query_result<Type> *res, std::unique_ptr<Type> obj)
|
||||
: obj_(std::move(obj))
|
||||
, result_(res)
|
||||
{}
|
||||
@@ -56,9 +58,9 @@ public:
|
||||
|
||||
self& operator++()
|
||||
{
|
||||
obj_.reset(result_.create());
|
||||
result_.bind(*obj_);
|
||||
if (!result_.fetch(*obj_)) {
|
||||
obj_.reset(result_->create());
|
||||
result_->bind(*obj_);
|
||||
if (!result_->fetch(*obj_)) {
|
||||
obj_.reset();
|
||||
}
|
||||
|
||||
@@ -69,9 +71,9 @@ public:
|
||||
{
|
||||
const self tmp(result_, obj_);
|
||||
|
||||
obj_.reset(result_.create());
|
||||
result_.bind(*obj_);
|
||||
if (!result_.fetch(*obj_)) {
|
||||
obj_.reset(result_->create());
|
||||
result_->bind(*obj_);
|
||||
if (!result_->fetch(*obj_)) {
|
||||
obj_.reset();
|
||||
}
|
||||
|
||||
@@ -100,7 +102,7 @@ public:
|
||||
|
||||
private:
|
||||
std::unique_ptr<Type> obj_;
|
||||
query_result<Type> &result_;
|
||||
query_result<Type> *result_{nullptr};
|
||||
};
|
||||
|
||||
template < typename Type >
|
||||
@@ -108,18 +110,22 @@ class query_result
|
||||
{
|
||||
public:
|
||||
using iterator = query_result_iterator<Type>;
|
||||
using creator_func = std::function<Type*()>;
|
||||
|
||||
public:
|
||||
explicit query_result(std::unique_ptr<query_result_impl> impl)
|
||||
: impl_(std::move(impl)) {}
|
||||
query_result(std::unique_ptr<query_result_impl> impl, creator_func creator)
|
||||
: creator_(creator)
|
||||
, impl_(std::move(impl)) {}
|
||||
|
||||
iterator begin() { return std::move(++iterator(*this)); }
|
||||
iterator begin() { return std::move(++iterator(this)); }
|
||||
iterator end() { return {}; }
|
||||
|
||||
private:
|
||||
friend class query_result_iterator<Type>;
|
||||
|
||||
Type* create() { return new Type; }
|
||||
Type* create() { return creator_(); }
|
||||
|
||||
void bind(const Type &obj)
|
||||
{
|
||||
@@ -132,6 +138,7 @@ private:
|
||||
}
|
||||
|
||||
private:
|
||||
creator_func creator_ = []{ return new Type; };
|
||||
std::unique_ptr<query_result_impl> impl_;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user