fixed session tests

This commit is contained in:
Sascha Kühl
2025-10-08 16:03:00 +02:00
parent cb0f6322f4
commit 463647ba59
9 changed files with 144 additions and 91 deletions
+15 -25
View File
@@ -40,8 +40,7 @@ public:
, result_(x.result_)
{}
query_result_iterator& operator=(query_result_iterator&& x) noexcept
{
query_result_iterator& operator=(query_result_iterator&& x) noexcept {
result_ = x.result_;
obj_ = std::move(x.obj_);
return *this;
@@ -49,18 +48,15 @@ public:
~query_result_iterator() = default;
bool operator==(const query_result_iterator& rhs)
{
bool operator==(const query_result_iterator& rhs) {
return obj_ == rhs.obj_;
}
bool operator!=(const query_result_iterator& rhs)
{
bool operator!=(const query_result_iterator& rhs) {
return obj_ != rhs.obj_;
}
self& operator++()
{
self& operator++() {
obj_.reset(result_->create());
result_->bind(*obj_);
if (!result_->fetch(*obj_)) {
@@ -70,8 +66,7 @@ public:
return *this;
}
self operator++(int)
{
self operator++(int) {
const self tmp(result_, obj_);
obj_.reset(result_->create());
@@ -83,23 +78,19 @@ public:
return tmp;
}
pointer operator->()
{
pointer operator->() {
return obj_.get();
}
reference operator*()
{
reference operator*() {
return *obj_;
}
pointer get()
{
pointer get() {
return obj_.get();
}
pointer release()
{
pointer release() {
return obj_.release();
}
@@ -111,8 +102,7 @@ private:
namespace detail {
template < typename Type >
Type* create_prototype(const std::vector<object::attribute_definition> &/*prototype*/)
{
Type* create_prototype(const std::vector<object::attribute_definition> &/*prototype*/) {
return new Type{};
}
@@ -128,11 +118,11 @@ public:
using creator_func = std::function<Type*()>;
public:
explicit query_result(std::unique_ptr<query_result_impl> &&impl)
: impl_(std::move(impl))
, creator_([this] {
return detail::create_prototype<Type>(impl_->prototype());
}) {}
// explicit query_result(std::unique_ptr<query_result_impl> &&impl)
// : impl_(std::move(impl))
// , creator_([this] {
// return detail::create_prototype<Type>(impl_->prototype());
// }) {}
query_result(std::unique_ptr<query_result_impl> &&impl, creator_func&& creator)
: impl_(std::move(impl))
+8 -2
View File
@@ -150,7 +150,10 @@ statement &statement::bind(const Type &obj) {
template<class Type>
utils::result<query_result<Type>, utils::error> statement::fetch() {
return statement_proxy_->fetch(*bindings_).and_then([](std::unique_ptr<query_result_impl> &&value) {
return utils::ok(query_result<Type>(std::forward<decltype(value)>(value)));
const auto prototype = value->prototype();
return utils::ok(query_result<Type>(std::forward<decltype(value)>(value), [prototype] {
return detail::create_prototype<Type>(prototype);
}));
});
}
@@ -160,7 +163,10 @@ utils::result<std::unique_ptr<Type>, utils::error> statement::fetch_one() {
if (!result.is_ok()) {
return utils::failure(result.err());
}
auto records = query_result<Type>(result.release());
const auto prototype = result.value()->prototype();
auto records = query_result<Type>(result.release(), [prototype] {
return detail::create_prototype<Type>(prototype);
});
auto first = records.begin();
if (first == records.end()) {
return utils::ok(std::unique_ptr<Type>{nullptr});