diff --git a/include/sqlpp11/boolean.h b/include/sqlpp11/boolean.h index b8fad9ae..dfffaca1 100644 --- a/include/sqlpp11/boolean.h +++ b/include/sqlpp11/boolean.h @@ -98,7 +98,7 @@ namespace sqlpp bool _is_null; }; - template + template struct _result_entry_t { _result_entry_t(): @@ -190,8 +190,8 @@ namespace sqlpp }; }; - template - inline std::ostream& operator<<(std::ostream& os, const boolean::_result_entry_t& e) + template + inline std::ostream& operator<<(std::ostream& os, const boolean::_result_entry_t& e) { return os << e.value(); } diff --git a/include/sqlpp11/floating_point.h b/include/sqlpp11/floating_point.h index cd46a71f..026dcfe9 100644 --- a/include/sqlpp11/floating_point.h +++ b/include/sqlpp11/floating_point.h @@ -98,7 +98,7 @@ namespace sqlpp bool _is_null; }; - template + template struct _result_entry_t { using _value_type = integral; @@ -238,8 +238,8 @@ namespace sqlpp }; }; - template - inline std::ostream& operator<<(std::ostream& os, const floating_point::_result_entry_t& e) + template + inline std::ostream& operator<<(std::ostream& os, const floating_point::_result_entry_t& e) { return os << e.value(); } diff --git a/include/sqlpp11/integral.h b/include/sqlpp11/integral.h index 20f76ef2..55cc77cb 100644 --- a/include/sqlpp11/integral.h +++ b/include/sqlpp11/integral.h @@ -98,7 +98,7 @@ namespace sqlpp bool _is_null; }; - template + template struct _result_entry_t { using _value_type = integral; @@ -245,8 +245,8 @@ namespace sqlpp }; }; - template - inline std::ostream& operator<<(std::ostream& os, const integral::_result_entry_t& e) + template + inline std::ostream& operator<<(std::ostream& os, const integral::_result_entry_t& e) { return os << e.value(); } diff --git a/include/sqlpp11/result_row.h b/include/sqlpp11/result_row.h index 1a6fb3ac..0249737a 100644 --- a/include/sqlpp11/result_row.h +++ b/include/sqlpp11/result_row.h @@ -41,13 +41,13 @@ namespace sqlpp template struct result_row_impl; - template - struct result_row_impl: - public NamedExpr::_name_t::template _member_t>, - public result_row_impl + template + struct result_row_impl: + public NamedExpr::_name_t::template _member_t>, + public result_row_impl { - using _field = typename NamedExpr::_name_t::template _member_t>; - using _rest = result_row_impl; + using _field = typename NamedExpr::_name_t::template _member_t>; + using _rest = result_row_impl; static constexpr size_t _last_index = _rest::_last_index; result_row_impl() = default; @@ -84,13 +84,13 @@ namespace sqlpp } }; - template - struct result_row_impl>, Rest...>: - public AliasProvider::_name_t::template _member_t>, // level prevents identical closures to be present twice in the inheritance tree - public result_row_impl + template + struct result_row_impl>, Rest...>: + public AliasProvider::_name_t::template _member_t>, // level prevents identical closures to be present twice in the inheritance tree + public result_row_impl { - using _multi_field = typename AliasProvider::_name_t::template _member_t>; - using _rest = result_row_impl; + using _multi_field = typename AliasProvider::_name_t::template _member_t>; + using _rest = result_row_impl; static constexpr size_t _last_index = _rest::_last_index; result_row_impl() = default; @@ -126,8 +126,8 @@ namespace sqlpp } }; - template - struct result_row_impl + template + struct result_row_impl { static constexpr size_t _last_index = index; result_row_impl() = default; @@ -155,10 +155,10 @@ namespace sqlpp }; } - template - struct result_row_t: public detail::result_row_impl<0, 0, NamedExpr...> + template + struct result_row_t: public detail::result_row_impl<0, 0, Db, NamedExpr...> { - using _impl = detail::result_row_impl<0, 0, NamedExpr...>; + using _impl = detail::result_row_impl<0, 0, Db, NamedExpr...>; bool _is_valid; static constexpr size_t _last_static_index = _impl::_last_index; @@ -221,11 +221,11 @@ namespace sqlpp } }; - template - struct dynamic_result_row_t: public detail::result_row_impl<0, 0, NamedExpr...> + template + struct dynamic_result_row_t: public detail::result_row_impl<0, 0, Db, NamedExpr...> { - using _impl = detail::result_row_impl<0, 0, NamedExpr...>; - using _field_type = detail::text::_result_entry_t<>; + using _impl = detail::result_row_impl<0, 0, Db, NamedExpr...>; + using _field_type = detail::text::_result_entry_t; static constexpr size_t _last_static_index = _impl::_last_index; bool _is_valid; diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 9ef444cf..d101fdf2 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -99,7 +99,8 @@ namespace sqlpp using _table_set = ::sqlpp::detail::type_set<>; using _column_list_t = ColumnList; - using _result_row_t = typename _column_list_t::_result_row_t; + template + using _result_row_t = typename _column_list_t::template _result_row_t; using _dynamic_names_t = typename _column_list_t::_dynamic_names_t; using _is_select = std::true_type; @@ -490,13 +491,13 @@ namespace sqlpp size_t get_no_of_result_columns() const { - return _result_row_t::static_size() + get_dynamic_names().size(); + return _column_list_t::static_size() + get_dynamic_names().size(); } template struct can_run_t { - //static_assert(is_where_t::value, "cannot select remove without having a where condition, use .where(true) to remove all rows"); + //static_assert(is_where_t::value, "cannot select select without having a where condition, use .where(true) to remove all rows"); //static_assert(not vendor::is_noop::value, "cannot run select without having selected anything"); //static_assert(is_from_t::value, "cannot run select without a from()"); //static_assert(is_where_t::value, "cannot run select without having a where condition, use .where(true) to select all rows"); @@ -509,7 +510,7 @@ namespace sqlpp // Execute template auto _run(Db& db) const - -> result_t + -> result_t> { static_assert(can_run_t::value, "Cannot execute select statement"); static_assert(_get_static_no_of_parameters() == 0, "cannot run select directly with parameters, use prepare instead"); diff --git a/include/sqlpp11/serialize.h b/include/sqlpp11/serialize.h index 147eadf8..34561439 100644 --- a/include/sqlpp11/serialize.h +++ b/include/sqlpp11/serialize.h @@ -38,6 +38,7 @@ namespace sqlpp return vendor::serializer_t::_(t, context); } + /* namespace vendor // Required if you want to call serialize(sqlpp::value(7), printer), for instance { template @@ -47,6 +48,7 @@ namespace sqlpp return vendor::serializer_t::_(t, context); } } + */ } diff --git a/include/sqlpp11/text.h b/include/sqlpp11/text.h index bac37426..b4f2c386 100644 --- a/include/sqlpp11/text.h +++ b/include/sqlpp11/text.h @@ -97,7 +97,7 @@ namespace sqlpp bool _is_null; }; - template + template struct _result_entry_t { _result_entry_t(): @@ -196,8 +196,8 @@ namespace sqlpp }; }; - template - inline std::ostream& operator<<(std::ostream& os, const text::_result_entry_t& e) + template + inline std::ostream& operator<<(std::ostream& os, const text::_result_entry_t& e) { return os << e.value(); } diff --git a/include/sqlpp11/vendor/select_column_list.h b/include/sqlpp11/vendor/select_column_list.h index 53f4f79e..08ac6211 100644 --- a/include/sqlpp11/vendor/select_column_list.h +++ b/include/sqlpp11/vendor/select_column_list.h @@ -156,9 +156,10 @@ namespace sqlpp }; using _name_t = typename ::sqlpp::detail::get_first_argument_if_unique::_name_t; + template using _result_row_t = typename std::conditional<_is_dynamic::value, - dynamic_result_row_t...>, - result_row_t...>>::type; + dynamic_result_row_t...>, + result_row_t...>>::type; using _dynamic_names_t = typename dynamic_select_column_list::_names_t; @@ -198,7 +199,8 @@ namespace sqlpp struct no_select_column_list_t { using _is_noop = std::true_type; - using _result_row_t = ::sqlpp::result_row_t<>; + template + using _result_row_t = ::sqlpp::result_row_t; using _dynamic_names_t = typename dynamic_select_column_list::_names_t; using _value_type = no_value_t; struct _name_t {}; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0eb84955..c98458d0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,7 +10,7 @@ build_and_run(InterpretTest) #build_and_run(InsertTest) #build_and_run(RemoveTest) #build_and_run(UpdateTest) -#build_and_run(SelectTest) +build_and_run(SelectTest) #build_and_run(FunctionTest) #build_and_run(PreparedTest) diff --git a/tests/FunctionTest.cpp b/tests/FunctionTest.cpp index 632875b0..1b37be29 100644 --- a/tests/FunctionTest.cpp +++ b/tests/FunctionTest.cpp @@ -32,7 +32,7 @@ #include -DbMock db = {}; +MockDb db = {}; SQLPP_ALIAS_PROVIDER(kaesekuchen); int main() diff --git a/tests/InsertTest.cpp b/tests/InsertTest.cpp index 9c64b4dc..ebe64982 100644 --- a/tests/InsertTest.cpp +++ b/tests/InsertTest.cpp @@ -29,8 +29,8 @@ #include #include -DbMock db; -DbMock::_serializer_context_t printer; +MockDb db; +MockDb::_serializer_context_t printer; int main() { diff --git a/tests/InterpretTest.cpp b/tests/InterpretTest.cpp index 5cadd8b8..1f02f33d 100644 --- a/tests/InterpretTest.cpp +++ b/tests/InterpretTest.cpp @@ -34,8 +34,8 @@ #include -DbMock db = {}; -DbMock::_serializer_context_t printer; +MockDb db = {}; +MockDb::_serializer_context_t printer; SQLPP_ALIAS_PROVIDER(kaesekuchen); int main() @@ -101,7 +101,7 @@ int main() serialize(remove_from(t).using_(t).where(t.alpha == sqlpp::tvin(0)), printer).str(); // functions - serialize(sqlpp::value(7), printer).str(); + sqlpp::serialize(sqlpp::value(7), printer).str();// FIXME: Maybe the vendor namespace is not a good idea? argument lives in namespace vendor serialize(sqlpp::verbatim("irgendwas integrales"), printer).str(); serialize(sqlpp::value_list(std::vector({1,2,3,4,5,6,8})), printer).str(); serialize(exists(select(t.alpha).from(t)), printer).str(); diff --git a/tests/MockDb.h b/tests/MockDb.h index f29d1775..bb12350c 100644 --- a/tests/MockDb.h +++ b/tests/MockDb.h @@ -30,7 +30,7 @@ #include #include -struct DbMock: public sqlpp::connection +struct MockDb: public sqlpp::connection { struct _serializer_context_t { diff --git a/tests/PreparedTest.cpp b/tests/PreparedTest.cpp index 2dc53876..abeb5c15 100644 --- a/tests/PreparedTest.cpp +++ b/tests/PreparedTest.cpp @@ -31,7 +31,7 @@ #include -DbMock db = {}; +MockDb db = {}; int main() { diff --git a/tests/RemoveTest.cpp b/tests/RemoveTest.cpp index d2a31b7a..21dd4108 100644 --- a/tests/RemoveTest.cpp +++ b/tests/RemoveTest.cpp @@ -30,8 +30,8 @@ #include "is_regular.h" -DbMock db; -DbMock::_serializer_context_t printer; +MockDb db; +MockDb::_serializer_context_t printer; int main() { diff --git a/tests/SelectTest.cpp b/tests/SelectTest.cpp index 15b34006..fbe41a62 100644 --- a/tests/SelectTest.cpp +++ b/tests/SelectTest.cpp @@ -33,8 +33,8 @@ #include -DbMock db = {}; -DbMock::_serializer_context_t printer; +MockDb db = {}; +MockDb::_serializer_context_t printer; namespace alias { @@ -296,14 +296,19 @@ int main() { auto a = select(t.alpha); auto b = select(f.epsilon.as(t.alpha)); - using A = typename decltype(a)::_result_row_t; - using B = typename decltype(b)::_result_row_t; + using A = typename decltype(a)::_result_row_t; + using B = typename decltype(b)::_result_row_t; static_assert(std::is_same< 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"); } + for (const auto& row : db(select(all_of(t)).from(t).where(true))) + { + int64_t a = row.alpha; + } + { auto s = dynamic_select(db, all_of(t)).dynamic_from().dynamic_where().dynamic_limit().dynamic_offset(); s.add_from(t); diff --git a/tests/UpdateTest.cpp b/tests/UpdateTest.cpp index a93fab66..0aedd8aa 100644 --- a/tests/UpdateTest.cpp +++ b/tests/UpdateTest.cpp @@ -29,8 +29,8 @@ #include "MockDb.h" #include "is_regular.h" -DbMock db; -DbMock::_serializer_context_t printer; +MockDb db; +MockDb::_serializer_context_t printer; int main() {