has many fetch progress
This commit is contained in:
@@ -5,12 +5,15 @@
|
||||
#include "matador/utils/field_attributes.hpp"
|
||||
#include "matador/utils/foreign_attributes.hpp"
|
||||
#include "matador/utils/default_type_traits.hpp"
|
||||
#include "matador/utils/identifier.hpp"
|
||||
|
||||
#include "matador/sql/interface/query_result_reader.hpp"
|
||||
|
||||
#include "matador/object/attribute_definition.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <typeindex>
|
||||
#include <unordered_set>
|
||||
@@ -70,6 +73,10 @@ public:
|
||||
void on_primary_key(const char *id, ValueType &value, std::enable_if_t<std::is_integral_v<ValueType> && !std::is_same_v<bool, ValueType>>* = nullptr)
|
||||
{
|
||||
utils::data_type_traits<ValueType>::read_value(*reader_, id, column_index_++, value);
|
||||
if (type_stack_.size() == 1) {
|
||||
last_pk_ = current_pk_;
|
||||
current_pk_ = value;
|
||||
}
|
||||
}
|
||||
void on_primary_key(const char *id, std::string &value, size_t size);
|
||||
void on_revision(const char *id, uint64_t &rev);
|
||||
@@ -86,25 +93,27 @@ public:
|
||||
template < class Pointer >
|
||||
void on_belongs_to(const char * /*id*/, Pointer &x, const utils::foreign_attributes &attr) {
|
||||
if (x.empty()) {
|
||||
x = new typename Pointer::value_type;
|
||||
x.reset(new typename Pointer::value_type);
|
||||
}
|
||||
if (attr.fetch() == utils::fetch_type::LAZY) {
|
||||
pk_reader_.read(*x, column_index_++);
|
||||
} else if (const auto ti = std::type_index(typeid(*x)); processed_types_.count(ti) == 0) {
|
||||
processed_types_.insert(ti);
|
||||
type_stack_.push(ti);
|
||||
access::process(*this, *x);
|
||||
type_stack_.pop();
|
||||
}
|
||||
}
|
||||
template < class Pointer >
|
||||
void on_has_one(const char * /*id*/, Pointer &x, const utils::foreign_attributes &attr)
|
||||
{
|
||||
if (x.empty()) {
|
||||
x = new typename Pointer::value_type;
|
||||
x.reset(new typename Pointer::value_type);
|
||||
}
|
||||
if (attr.fetch() == utils::fetch_type::LAZY) {
|
||||
pk_reader_.read(*x, column_index_++);
|
||||
} else if (const auto ti = std::type_index(typeid(*x)); processed_types_.count(ti) == 0) {
|
||||
processed_types_.insert(ti);
|
||||
processed_types_.insert(ti);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,11 +125,13 @@ public:
|
||||
void on_has_many(const char * /*id*/, ContainerType &cont, const char * /*join_column*/, const utils::foreign_attributes &attr) {
|
||||
if ( attr.fetch() == utils::fetch_type::LAZY ) {
|
||||
// pk_reader_.read(*id, column_index_++);
|
||||
} else if (const auto ti = std::type_index(typeid(typename ContainerType::value_type::value_type)); processed_types_.count(ti) == 0) {
|
||||
} else /*if (const auto ti = std::type_index(typeid(typename ContainerType::value_type::value_type)); processed_types_.count(ti) == 0)*/ {
|
||||
const auto ti = std::type_index(typeid(typename ContainerType::value_type::value_type));
|
||||
processed_types_.insert(ti);
|
||||
auto obj = std::make_unique<typename ContainerType::value_type::value_type>();
|
||||
// typename ContainerType::value_type x(new typename ContainerType::value_type::value_type);
|
||||
type_stack_.push(ti);
|
||||
access::process(*this, *obj);
|
||||
type_stack_.pop();
|
||||
auto ptr = typename ContainerType::value_type(obj.release());
|
||||
const auto pk = ptr.primary_key();
|
||||
if (ptr.primary_key().is_valid()) {
|
||||
@@ -138,18 +149,25 @@ public:
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
bool fetch(Type &obj)
|
||||
{
|
||||
column_index_ = reader_->start_column_index();
|
||||
auto fetched = reader_->fetch();
|
||||
if (!fetched.is_ok()) {
|
||||
return false;
|
||||
}
|
||||
if (!*fetched) {
|
||||
return false;
|
||||
}
|
||||
processed_types_.insert(typeid(Type));
|
||||
access::process(*this, obj);
|
||||
bool fetch(Type &obj) {
|
||||
bool result = false;
|
||||
do {
|
||||
column_index_ = reader_->start_column_index();
|
||||
auto fetched = reader_->fetch();
|
||||
if (!fetched.is_ok()) {
|
||||
return false;
|
||||
}
|
||||
if (!*fetched) {
|
||||
return false;
|
||||
}
|
||||
processed_types_.insert(typeid(Type));
|
||||
type_stack_.push(typeid(Type));
|
||||
access::process(*this, obj);
|
||||
type_stack_.pop();
|
||||
std::cout << "last pk: " << last_pk_.str() << std::endl;
|
||||
std::cout << "current pk: " << current_pk_.str() << std::endl;
|
||||
std::cout << "last == current: " << std::boolalpha << (last_pk_ == current_pk_) << std::endl;
|
||||
} while (last_pk_ == current_pk_);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -161,6 +179,9 @@ protected:
|
||||
std::unique_ptr<query_result_reader> reader_;
|
||||
detail::pk_reader pk_reader_;
|
||||
std::unordered_set<std::type_index> processed_types_;
|
||||
std::stack<std::type_index> type_stack_;
|
||||
utils::identifier current_pk_{};
|
||||
utils::identifier last_pk_{};
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
Reference in New Issue
Block a user