diff --git a/include/sqlpp11/result.h b/include/sqlpp11/result.h index 8c346f4e..f7ea4c8d 100644 --- a/include/sqlpp11/result.h +++ b/include/sqlpp11/result.h @@ -40,21 +40,19 @@ namespace sqlpp using result_row_t = typename db_result_t::result_row_t; db_result_t _db_result; - result_row_t _result_row; - result_row_t _end; + db_result_t _end; public: result_t(): _db_result(), - _result_row(), _end() {} result_t(db_result_t&& result): _db_result(std::move(result)), - _result_row(_db_result.next()), - _end({}) - {} + _end() + { + } result_t(const result_t&) = delete; result_t(result_t&&) = default; @@ -65,11 +63,9 @@ namespace sqlpp class iterator { public: - iterator(result_t& result, result_row_t& result_row): - _result(result), - _result_row(result_row) + iterator(db_result_t& result): + _result(result) { - //std::cerr << "result::iterator::constructor" << std::endl; } const result_row_t& operator*() const @@ -84,7 +80,7 @@ namespace sqlpp bool operator==(const iterator& rhs) const { - return _result_row == rhs._result_row; + return _result.front() == rhs._result.front(); } bool operator!=(const iterator& rhs) const @@ -97,33 +93,32 @@ namespace sqlpp _result.pop_front(); } - result_t& _result; - result_row_t& _result_row; + db_result_t& _result; }; iterator begin() { - return iterator(*this, _result_row); + return iterator(_db_result); } iterator end() { - return iterator(*this, _end); + return iterator(_end); } const result_row_t& front() const { - return _result_row; + return _db_result.front(); } bool empty() const { - return _result_row == _end; + return _db_result.front() == _end.front(); } void pop_front() { - _result_row = _db_result.next(); + _db_result.pop_front(); } }; diff --git a/include/sqlpp11/result_row.h b/include/sqlpp11/result_row.h index 59f95d4b..930ce2ce 100644 --- a/include/sqlpp11/result_row.h +++ b/include/sqlpp11/result_row.h @@ -106,20 +106,25 @@ namespace sqlpp raw_result_row_t _raw_result_row; result_row_t(): - _raw_result_row(), - _impl(_raw_result_row), + _impl({}), + _raw_result_row({}), _is_row(false) { } template result_row_t(const raw_result_row_t& raw_result_row, const T&): + _impl(raw_result_row), _raw_result_row(raw_result_row), - _impl(_raw_result_row), _is_row(_raw_result_row.data != nullptr) { } + result_row_t(const result_row_t&) = delete; + result_row_t(result_row_t&&) = default; + result_row_t& operator=(const result_row_t&) = delete; + result_row_t& operator=(result_row_t&&) = default; + result_row_t& operator=(const raw_result_row_t& raw_result_row) { _impl::operator=(raw_result_row); @@ -128,7 +133,7 @@ namespace sqlpp return *this; } - bool operator==(const result_row_t& rhs) + bool operator==(const result_row_t& rhs) const { return _raw_result_row == rhs._raw_result_row; } @@ -146,12 +151,21 @@ namespace sqlpp using _field_type = detail::text::_result_entry_t<0>; static constexpr size_t _last_static_index = _impl::_last_index; + raw_result_row_t _raw_result_row; bool _is_row; std::vector _dynamic_columns; std::map _dynamic_fields; + dynamic_result_row_t(): + _impl({}), + _raw_result_row({}), + _is_row(false) + { + } + dynamic_result_row_t(const raw_result_row_t& raw_result_row, std::vector dynamic_columns): - detail::result_row_impl<0, 0, NamedExpr...>(raw_result_row), + _impl(raw_result_row), + _raw_result_row(raw_result_row), _is_row(raw_result_row.data != nullptr) { raw_result_row_t dynamic_row = raw_result_row; @@ -176,9 +190,15 @@ namespace sqlpp } + dynamic_result_row_t(const dynamic_result_row_t&) = delete; + dynamic_result_row_t(dynamic_result_row_t&&) = default; + dynamic_result_row_t& operator=(const dynamic_result_row_t&) = delete; + dynamic_result_row_t& operator=(dynamic_result_row_t&&) = default; + dynamic_result_row_t& operator=(const raw_result_row_t& raw_result_row) { detail::result_row_impl<0, 0, NamedExpr...>::operator=(raw_result_row); + _raw_result_row = raw_result_row; _is_row = raw_result_row.data != nullptr; raw_result_row_t dynamic_row = raw_result_row; @@ -204,6 +224,11 @@ namespace sqlpp return *this; } + bool operator==(const dynamic_result_row_t& rhs) const + { + return _raw_result_row == rhs._raw_result_row; + } + const _field_type& at(const std::string& field_name) const { return _dynamic_fields.at(field_name); diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 88dfb636..58ecca82 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -568,6 +568,11 @@ namespace sqlpp return *this; } + const typename ExpressionList::_dynamic_names_t& get_dynamic_names() const + { + return _expression_list._dynamic_expressions._dynamic_expression_names; + } + // Execute template auto run(Db& db) const diff --git a/include/sqlpp11/text.h b/include/sqlpp11/text.h index f8da60d6..461b7c3e 100644 --- a/include/sqlpp11/text.h +++ b/include/sqlpp11/text.h @@ -51,6 +51,12 @@ namespace sqlpp template struct _result_entry_t { + _result_entry_t(): + _is_valid(false), + _is_null(true), + _value("") + {} + _result_entry_t(const raw_result_row_t& row): _is_valid(row.data != nullptr), _is_null(row.data == nullptr or row.data[index] == nullptr), diff --git a/tests/SelectTest.cpp b/tests/SelectTest.cpp index 3e579680..c413509a 100644 --- a/tests/SelectTest.cpp +++ b/tests/SelectTest.cpp @@ -298,8 +298,6 @@ int main() decltype(t.alpha)::_value_type::_base_value_type, decltype(f.epsilon)::_value_type::_base_value_type>::value, "Two bigint columns must have identical base_value_type"); static_assert(std::is_same::value, "select with identical columns(name/value_type) need to have identical result_types"); - static_assert(sqlpp::is_regular::value, "type requirement"); - static_assert(sqlpp::is_regular::value, "type requirement"); } {