From c838e9dd7bfa787301fe88bf7dfc9bf52492ba84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20K=C3=BChl?= Date: Sat, 31 Jan 2026 11:25:44 +0100 Subject: [PATCH] removed query_record_result and moved content to query_result --- .../query/intermediates/fetchable_query.hpp | 1 - .../query/query_collection_resolver.hpp | 16 +-- include/matador/query/schema.hpp | 16 +-- include/matador/sql/query_record_result.hpp | 132 ------------------ include/matador/sql/query_result.hpp | 125 +++++++++++++++++ source/orm/CMakeLists.txt | 1 - source/orm/orm/session.cpp | 1 - .../query/intermediates/fetchable_query.cpp | 1 - source/orm/sql/statement.cpp | 1 - test/backends/QueryRecordTest.cpp | 2 - 10 files changed, 140 insertions(+), 156 deletions(-) delete mode 100644 include/matador/sql/query_record_result.hpp diff --git a/include/matador/query/intermediates/fetchable_query.hpp b/include/matador/query/intermediates/fetchable_query.hpp index 95f23bd..4e4a963 100644 --- a/include/matador/query/intermediates/fetchable_query.hpp +++ b/include/matador/query/intermediates/fetchable_query.hpp @@ -5,7 +5,6 @@ #include "matador/sql/executor.hpp" #include "matador/sql/query_result.hpp" -#include "matador/sql/query_record_result.hpp" #include "matador/sql/record.hpp" #include "matador/utils/error.hpp" diff --git a/include/matador/query/query_collection_resolver.hpp b/include/matador/query/query_collection_resolver.hpp index cf18f09..42fe2bf 100644 --- a/include/matador/query/query_collection_resolver.hpp +++ b/include/matador/query/query_collection_resolver.hpp @@ -35,15 +35,15 @@ struct value_to_identifier{ void operator()(const uint16_t &x) { assign(x); } void operator()(const uint32_t &x) { assign(x); } void operator()(const uint64_t &x) { assign(x); } - void operator()(const bool &x) {} - void operator()(const float &x) {} - void operator()(const double &x) { /* assign(x);*/ } - void operator()(const char *x) {} + void operator()(const bool &) {} + void operator()(const float &) {} + void operator()(const double &) {} + void operator()(const char *) {} void operator()(const std::string &x) { assign(x); } - void operator()(const utils::date_type_t &x) {} - void operator()(const utils::time_type_t &x) {} - void operator()(const utils::timestamp_type_t &x) {} - void operator()(const utils::blob_type_t &x) {} + void operator()(const utils::date_type_t &) {} + void operator()(const utils::time_type_t &) {} + void operator()(const utils::timestamp_type_t &) {} + void operator()(const utils::blob_type_t &) {} template void assign(const Type &x) { id_ = x; } diff --git a/include/matador/query/schema.hpp b/include/matador/query/schema.hpp index 172b955..dd614f4 100644 --- a/include/matador/query/schema.hpp +++ b/include/matador/query/schema.hpp @@ -188,23 +188,21 @@ public: {} template - void on_primary_key(const char *id, ValueType &value, const utils::primary_key_attribute& attr = utils::default_pk_attributes) { - - } + static void on_primary_key(const char * /*id*/, ValueType &/*value*/, const utils::primary_key_attribute& /*attr*/ = utils::default_pk_attributes) {} static void on_revision(const char * /*id*/, uint64_t &/*rev*/) {} template static void on_attribute(const char * /*id*/, Type &/*value*/, const utils::field_attributes &/*attr*/ = utils::null_attributes) {} template - void on_belongs_to(const char * /*id*/, Pointer &x, const utils::foreign_attributes &attr) {} + static void on_belongs_to(const char * /*id*/, Pointer & /*x*/, const utils::foreign_attributes &/*attr*/) {} template - void on_has_one(const char * /*id*/, Pointer &x, const utils::foreign_attributes &attr) {} + static void on_has_one(const char * /*id*/, Pointer & /*x*/, const utils::foreign_attributes &/*attr*/) {} template - void on_has_many_to_many(const char *, ContainerType &, const char * /*join_column*/, const char * /*inverse_join_column*/, const utils::foreign_attributes &attr) {} + static void on_has_many_to_many(const char *, ContainerType &, const char * /*join_column*/, const char * /*inverse_join_column*/, const utils::foreign_attributes &/*attr*/) {} template - void on_has_many_to_many(const char *, ContainerType &, const utils::foreign_attributes &attr) {} + static void on_has_many_to_many(const char *, ContainerType &, const utils::foreign_attributes &/*attr*/) {} template - void on_has_many(const char * /*id*/, CollectionType &cont, const char *join_column, const utils::foreign_attributes &attr, std::enable_if_t::value> * = nullptr) { + void on_has_many(const char * /*id*/, CollectionType &/*cont*/, const char *join_column, const utils::foreign_attributes &/*attr*/, std::enable_if_t::value> * = nullptr) { const auto it = schema_.find(typeid(typename CollectionType::value_type::value_type)); if (it == schema_.end()) { throw query_builder_exception{query_build_error::UnknownType}; @@ -224,7 +222,7 @@ public: } template - void on_has_many(const char * /*id*/, CollectionType &cont, const char * /*join_column*/, const utils::foreign_attributes &attr, std::enable_if_t::value> * = nullptr) { + void on_has_many(const char * /*id*/, CollectionType &/*cont*/, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/, std::enable_if_t::value> * = nullptr) { } diff --git a/include/matador/sql/query_record_result.hpp b/include/matador/sql/query_record_result.hpp deleted file mode 100644 index 96abf63..0000000 --- a/include/matador/sql/query_record_result.hpp +++ /dev/null @@ -1,132 +0,0 @@ -#ifndef MATADOR_QUERY_RECORD_RESULT_HPP -#define MATADOR_QUERY_RECORD_RESULT_HPP - -#include "matador/sql/query_result.hpp" - -namespace matador::sql { - -template <> -class query_result; - -template <> -class query_result_iterator { -public: - using iterator_category = std::forward_iterator_tag; - using value_type = record; - using difference_type = std::ptrdiff_t; - using self = query_result_iterator; /**< Shortcut for this class. */ - using pointer = value_type*; /**< Shortcut for the pointer type. */ - using reference = value_type&; /**< Shortcut for the reference type */ - -public: - query_result_iterator() = default; - explicit query_result_iterator(query_result *res) - : result_(res) - {} - query_result_iterator(query_result *res, record rec) - : record_(std::move(rec)) - , result_(res) - {} - query_result_iterator(query_result_iterator&& x) noexcept - : record_(std::move(x.record_)) - , result_(x.result_) - {} - query_result_iterator& operator=(query_result_iterator&& x) noexcept { - result_ = x.result_; - record_ = std::move(x.record_); - return *this; - } - - ~query_result_iterator() = default; - - bool operator==(const query_result_iterator& rhs) const { - return record_ == rhs.record_; - } - - bool operator!=(const query_result_iterator& rhs) const { - return !(*this == rhs); - } - - self& operator++(); - self operator++(int); - - pointer operator->() { return &record_; } - reference operator*() { return record_; } - record release() { return std::move(record_); } - -private: - record record_; - query_result *result_{nullptr}; -}; - -template<> -class query_result final { -public: - using iterator = query_result_iterator; - - query_result(std::unique_ptr &&impl, const std::vector &prototype) - : impl_(std::move(impl)) - , prototype_(prototype) {} - - iterator begin() { return std::move(++iterator(this)); } - iterator end() { return {}; } - -private: - friend class query_result_iterator; - - [[nodiscard]] record create() const; - void bind(const record& obj) const; - bool fetch(record& obj) const; - -protected: - std::unique_ptr impl_; - std::vector prototype_; -}; - -inline record query_result::create() const { - record rec; - int index{0}; - for (const auto &col: prototype_) { - rec.append({ - col.name(), - col.type(), - col.attributes().options(), - col.attributes().size(), - index++ - }); - } - return rec; - -} - -inline void query_result::bind(const record &obj) const { - impl_->bind(obj); -} - -inline bool query_result::fetch(record &obj) const { - return impl_->fetch(obj); -} - -inline query_result_iterator::self & query_result_iterator::operator++() { - record_ = result_->create(); - result_->bind(record_); - if (!result_->fetch(record_)) { - record_.clear(); - } - - return *this; -} - -inline query_result_iterator::self query_result_iterator::operator++(int) { - self tmp(result_, record_); - - record_ = result_->create(); - result_->bind(record_); - if (!result_->fetch(record_)) { - record_.clear(); - } - - return tmp; -} -} -#endif //MATADOR_QUERY_RECORD_RESULT_HPP \ No newline at end of file diff --git a/include/matador/sql/query_result.hpp b/include/matador/sql/query_result.hpp index 2f9d250..1399877 100644 --- a/include/matador/sql/query_result.hpp +++ b/include/matador/sql/query_result.hpp @@ -149,6 +149,131 @@ template bool query_result::fetch(Type &obj) { return impl_->fetch(obj); } + +template <> +class query_result; + +template <> +class query_result_iterator { +public: + using iterator_category = std::forward_iterator_tag; + using value_type = record; + using difference_type = std::ptrdiff_t; + using self = query_result_iterator; /**< Shortcut for this class. */ + using pointer = value_type*; /**< Shortcut for the pointer type. */ + using reference = value_type&; /**< Shortcut for the reference type */ + +public: + query_result_iterator() = default; + explicit query_result_iterator(query_result *res) + : result_(res) + {} + query_result_iterator(query_result *res, record rec) + : record_(std::move(rec)) + , result_(res) + {} + query_result_iterator(query_result_iterator&& x) noexcept + : record_(std::move(x.record_)) + , result_(x.result_) + {} + query_result_iterator& operator=(query_result_iterator&& x) noexcept { + result_ = x.result_; + record_ = std::move(x.record_); + return *this; + } + + ~query_result_iterator() = default; + + bool operator==(const query_result_iterator& rhs) const { + return record_ == rhs.record_; + } + + bool operator!=(const query_result_iterator& rhs) const { + return !(*this == rhs); + } + + self& operator++(); + self operator++(int); + + pointer operator->() { return &record_; } + reference operator*() { return record_; } + record release() { return std::move(record_); } + +private: + record record_; + query_result *result_{nullptr}; +}; + +template<> +class query_result final { +public: + using iterator = query_result_iterator; + + query_result(std::unique_ptr &&impl, const std::vector &prototype) + : impl_(std::move(impl)) + , prototype_(prototype) {} + + iterator begin() { return std::move(++iterator(this)); } + iterator end() { return {}; } + +private: + friend class query_result_iterator; + + [[nodiscard]] record create() const; + void bind(const record& obj) const; + bool fetch(record& obj) const; + +protected: + std::unique_ptr impl_; + std::vector prototype_; +}; + +inline record query_result::create() const { + record rec; + int index{0}; + for (const auto &col: prototype_) { + rec.append({ + col.name(), + col.type(), + col.attributes().options(), + col.attributes().size(), + index++ + }); + } + return rec; + +} + +inline void query_result::bind(const record &obj) const { + impl_->bind(obj); +} + +inline bool query_result::fetch(record &obj) const { + return impl_->fetch(obj); +} + +inline query_result_iterator::self & query_result_iterator::operator++() { + record_ = result_->create(); + result_->bind(record_); + if (!result_->fetch(record_)) { + record_.clear(); + } + + return *this; +} + +inline query_result_iterator::self query_result_iterator::operator++(int) { + self tmp(result_, record_); + + record_ = result_->create(); + result_->bind(record_); + if (!result_->fetch(record_)) { + record_.clear(); + } + + return tmp; +} + } // namespace matador::sql #endif //QUERY_QUERY_RESULT_HPP diff --git a/source/orm/CMakeLists.txt b/source/orm/CMakeLists.txt index b067148..62dab9a 100644 --- a/source/orm/CMakeLists.txt +++ b/source/orm/CMakeLists.txt @@ -92,7 +92,6 @@ add_library(matador-orm STATIC ../../include/matador/sql/internal/statement_object_resolver.hpp ../../include/matador/sql/producer_resolver_factory.hpp ../../include/matador/sql/query_context.hpp - ../../include/matador/sql/query_record_result.hpp ../../include/matador/sql/query_result.hpp ../../include/matador/sql/record.hpp ../../include/matador/sql/resolver_service.hpp diff --git a/source/orm/orm/session.cpp b/source/orm/orm/session.cpp index 3f5a62c..bf76bc0 100644 --- a/source/orm/orm/session.cpp +++ b/source/orm/orm/session.cpp @@ -2,7 +2,6 @@ #include "matador/sql/backend_provider.hpp" #include "matador/sql/dialect.hpp" -#include "matador/sql/query_record_result.hpp" #include "matador/query/query.hpp" diff --git a/source/orm/query/intermediates/fetchable_query.cpp b/source/orm/query/intermediates/fetchable_query.cpp index b9f57c3..d0e0df6 100644 --- a/source/orm/query/intermediates/fetchable_query.cpp +++ b/source/orm/query/intermediates/fetchable_query.cpp @@ -5,7 +5,6 @@ #include "matador/sql/executor.hpp" #include "matador/sql/field.hpp" #include "matador/sql/statement.hpp" -#include "matador/sql/query_record_result.hpp" namespace matador::query { diff --git a/source/orm/sql/statement.cpp b/source/orm/sql/statement.cpp index e2e9dc1..a3c8920 100644 --- a/source/orm/sql/statement.cpp +++ b/source/orm/sql/statement.cpp @@ -1,7 +1,6 @@ #include "matador/sql/statement.hpp" #include "matador/sql/record.hpp" #include "matador/sql/field.hpp" -#include "matador/sql/query_record_result.hpp" #include #include diff --git a/test/backends/QueryRecordTest.cpp b/test/backends/QueryRecordTest.cpp index b276166..a83e329 100644 --- a/test/backends/QueryRecordTest.cpp +++ b/test/backends/QueryRecordTest.cpp @@ -519,8 +519,6 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with group by and order for (const auto &r: *result) { const auto age_count_val = r.at(0); const auto age_val = r.at(1); - const auto ec = expected_values.front().first; - const auto ea = expected_values.front().second; REQUIRE(age_count_val == expected_values.front().first); REQUIRE(age_val == expected_values.front().second); expected_values.pop_front();