From 609766a9fef5a978ef8de8f1b61832e5cc64099d Mon Sep 17 00:00:00 2001 From: Andreas Sommer Date: Fri, 16 Sep 2016 19:30:17 +0200 Subject: [PATCH 01/22] Allow dynamic sort order --- include/sqlpp11/basic_expression_operators.h | 13 +++++++++---- include/sqlpp11/sort_order.h | 11 ++++++----- test_serializer/CustomQuery.cpp | 6 ++++-- tests/Select.cpp | 1 + 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/include/sqlpp11/basic_expression_operators.h b/include/sqlpp11/basic_expression_operators.h index 98e9bae2..ffa56525 100644 --- a/include/sqlpp11/basic_expression_operators.h +++ b/include/sqlpp11/basic_expression_operators.h @@ -187,14 +187,19 @@ namespace sqlpp return {*static_cast(this)}; } - auto asc() const -> sort_order_t + auto asc() const -> sort_order_t { - return {*static_cast(this)}; + return {*static_cast(this), sort_type::asc}; } - auto desc() const -> sort_order_t + auto desc() const -> sort_order_t { - return {*static_cast(this)}; + return {*static_cast(this), sort_type::desc}; + } + + auto order(sort_type s) const -> sort_order_t + { + return {*static_cast(this), s}; } template diff --git a/include/sqlpp11/sort_order.h b/include/sqlpp11/sort_order.h index 391898dd..4ef59e5e 100644 --- a/include/sqlpp11/sort_order.h +++ b/include/sqlpp11/sort_order.h @@ -39,25 +39,26 @@ namespace sqlpp desc }; - template + template struct sort_order_t { using _traits = make_traits; using _nodes = detail::type_vector; Expression _expression; + sort_type _sort_type; }; - template - struct serializer_t> + template + struct serializer_t> { using _serialize_check = serialize_check_of; - using T = sort_order_t; + using T = sort_order_t; static Context& _(const T& t, Context& context) { serialize_operand(t._expression, context); - switch (SortType) + switch (t._sort_type) { case sort_type::asc: context << " ASC"; diff --git a/test_serializer/CustomQuery.cpp b/test_serializer/CustomQuery.cpp index e4afaeb2..4c00aec5 100644 --- a/test_serializer/CustomQuery.cpp +++ b/test_serializer/CustomQuery.cpp @@ -57,9 +57,11 @@ int CustomQuery(int, char* []) custom_query(sqlpp::select(), dynamic_select_flags(db, sqlpp::distinct), dynamic_select_columns(db, foo.omega), dynamic_from(db, foo.join(bar).on(foo.omega == bar.alpha)), dynamic_where(db, bar.alpha > 17), dynamic_group_by(db, foo.omega), dynamic_having(db, avg(bar.alpha) > 19), - dynamic_order_by(db, foo.omega.asc()), sqlpp::dynamic_limit(db), sqlpp::dynamic_offset(db)), + dynamic_order_by(db, foo.omega.asc(), foo.psi.order(sqlpp::sort_type::desc)), + sqlpp::dynamic_limit(db), sqlpp::dynamic_offset(db)), "SELECT DISTINCT tab_foo.omega FROM tab_foo INNER JOIN tab_bar ON (tab_foo.omega=tab_bar.alpha) WHERE " - "(tab_bar.alpha>17) GROUP BY tab_foo.omega HAVING (AVG(tab_bar.alpha)>19) ORDER BY tab_foo.omega ASC "); + "(tab_bar.alpha>17) GROUP BY tab_foo.omega HAVING (AVG(tab_bar.alpha)>19) ORDER BY tab_foo.omega " + "ASC,tab_foo.psi DESC "); // A pragma query for sqlite compare(__LINE__, diff --git a/tests/Select.cpp b/tests/Select.cpp index 4b99b3a7..268488f2 100644 --- a/tests/Select.cpp +++ b/tests/Select.cpp @@ -160,6 +160,7 @@ int Select(int, char* []) s.offset.set(3u); s.group_by.add(t.beta); s.order_by.add(t.beta.asc()); + s.order_by.add(t.delta.order(sqlpp::sort_type::desc)); for (const auto& row : db(s)) { int64_t a = row.alpha; From 82ec05149f9e7ece32da1c5eb9ec1d5aba52b682 Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 7 Oct 2016 12:13:31 +0200 Subject: [PATCH 02/22] Stop clang-format from sorting includes --- .clang-format | 1 + 1 file changed, 1 insertion(+) diff --git a/.clang-format b/.clang-format index 1d9d0f26..c0ffae25 100644 --- a/.clang-format +++ b/.clang-format @@ -51,3 +51,4 @@ CommentPragmas: '^ IWYU pragma:' ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] SpaceBeforeParens: ControlStatements DisableFormat: false +SortIncludes: false From 3963b5065d0e17e28e42835907b3588268f949b2 Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 7 Oct 2016 12:13:58 +0200 Subject: [PATCH 03/22] Added missing pre-generated alias --- include/sqlpp11/alias_provider.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/sqlpp11/alias_provider.h b/include/sqlpp11/alias_provider.h index 38bbf528..3c1abbd4 100644 --- a/include/sqlpp11/alias_provider.h +++ b/include/sqlpp11/alias_provider.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -89,6 +89,7 @@ namespace sqlpp SQLPP_ALIAS_PROVIDER(o) SQLPP_ALIAS_PROVIDER(p) SQLPP_ALIAS_PROVIDER(q) + SQLPP_ALIAS_PROVIDER(r) SQLPP_ALIAS_PROVIDER(s) SQLPP_ALIAS_PROVIDER(t) SQLPP_ALIAS_PROVIDER(u) From fa0fe887b5d7dc7e9d57baeb96ba3564cbfe2ccb Mon Sep 17 00:00:00 2001 From: rbock Date: Mon, 10 Oct 2016 22:25:16 +0200 Subject: [PATCH 04/22] Slightly better comparison of row types for unions. Needs some work for non-static versions --- include/sqlpp11/field_spec.h | 28 ++++++++++++++++++++++++++++ include/sqlpp11/result_row.h | 13 +++++++++++++ include/sqlpp11/union.h | 18 ++++++++++++------ 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/include/sqlpp11/field_spec.h b/include/sqlpp11/field_spec.h index ac862b58..853367eb 100644 --- a/include/sqlpp11/field_spec.h +++ b/include/sqlpp11/field_spec.h @@ -41,11 +41,39 @@ namespace sqlpp using _nodes = detail::type_vector<>; using _alias_t = NameType; + + template + static constexpr auto is_compatible(field_spec_t) -> bool + { + using rhs = field_spec_t; + return std::is_same<_traits, typename rhs::_traits>::value and + std::is_same::value; + } }; template struct multi_field_spec_t { + static_assert(wrong_t::value, + "multi_field_spec_t needs to be specialized with a tuple"); + }; + + template + struct multi_field_spec_t> + { + template + static constexpr auto is_compatible(multi_field_spec_t) -> + typename std::enable_if::type + { + return logic::all_t::value; + } + + template + static constexpr auto is_compatible(multi_field_spec_t) -> + typename std::enable_if::type + { + return false; + } }; namespace detail diff --git a/include/sqlpp11/result_row.h b/include/sqlpp11/result_row.h index 59397496..883065e3 100644 --- a/include/sqlpp11/result_row.h +++ b/include/sqlpp11/result_row.h @@ -186,6 +186,19 @@ namespace sqlpp using _impl = detail::result_row_impl; bool _is_valid; + template + static constexpr auto is_compatible(detail::type_vector>) -> + typename std::enable_if::type + { + return logic::all_t::value; + } + + template + static constexpr auto is_compatible(detail::type_vector>) -> + typename std::enable_if::type + { + return false; + } result_row_t() : _impl(), _is_valid(false) { } diff --git a/include/sqlpp11/union.h b/include/sqlpp11/union.h index e113ea16..12fed78f 100644 --- a/include/sqlpp11/union.h +++ b/include/sqlpp11/union.h @@ -213,10 +213,13 @@ namespace sqlpp static_assert(has_result_row_t>::value, "left hand side argument of a union has to be a complete select statement or union"); - using _result_row_t = get_result_row_t; - static_assert(std::is_same>, _result_row_t>::value, + using lhs_result_row_t = get_result_row_t>; + using rhs_result_row_t = get_result_row_t; + static_assert(lhs_result_row_t::is_compatible(detail::type_vector{}), "both arguments in a union have to have the same result columns (type and name)"); - static_assert(is_static_result_row_t<_result_row_t>::value, "unions must not have dynamically added columns"); + static_assert( + is_static_result_row_t::value && is_static_result_row_t::value, + "unions must not have dynamically added columns"); return _union_impl(check_union_t, Rhs>{}, rhs); } @@ -231,10 +234,13 @@ namespace sqlpp static_assert(has_result_row_t>::value, "left hand side argument of a union has to be a (complete) select statement"); - using _result_row_t = get_result_row_t; - static_assert(std::is_same>, _result_row_t>::value, + using lhs_result_row_t = get_result_row_t>; + using rhs_result_row_t = get_result_row_t; + static_assert(lhs_result_row_t::is_compatible(detail::type_vector{}), "both arguments in a union have to have the same result columns (type and name)"); - static_assert(is_static_result_row_t<_result_row_t>::value, "unions must not have dynamically added columns"); + static_assert( + is_static_result_row_t::value && is_static_result_row_t::value, + "unions must not have dynamically added columns"); return _union_impl(check_union_t, Rhs>{}, rhs); } From 4dad08653ab1fcf16dd979b2156ad010eb31c0cc Mon Sep 17 00:00:00 2001 From: rbock Date: Tue, 11 Oct 2016 07:19:39 +0200 Subject: [PATCH 05/22] Maybe easier to grok for MSVC --- include/sqlpp11/union.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/sqlpp11/union.h b/include/sqlpp11/union.h index 12fed78f..4e044eab 100644 --- a/include/sqlpp11/union.h +++ b/include/sqlpp11/union.h @@ -215,7 +215,8 @@ namespace sqlpp using lhs_result_row_t = get_result_row_t>; using rhs_result_row_t = get_result_row_t; - static_assert(lhs_result_row_t::is_compatible(detail::type_vector{}), + constexpr auto vec_rhs = detail::type_vector{}; + static_assert(lhs_result_row_t::is_compatible(vec_rhs), "both arguments in a union have to have the same result columns (type and name)"); static_assert( is_static_result_row_t::value && is_static_result_row_t::value, @@ -236,7 +237,8 @@ namespace sqlpp using lhs_result_row_t = get_result_row_t>; using rhs_result_row_t = get_result_row_t; - static_assert(lhs_result_row_t::is_compatible(detail::type_vector{}), + constexpr auto vec_rhs = detail::type_vector{}; + static_assert(lhs_result_row_t::is_compatible(vec_rhs), "both arguments in a union have to have the same result columns (type and name)"); static_assert( is_static_result_row_t::value && is_static_result_row_t::value, From ae37d063a49ea15a4210d86d34302cdf861bb17a Mon Sep 17 00:00:00 2001 From: rbock Date: Tue, 11 Oct 2016 16:09:49 +0200 Subject: [PATCH 06/22] Loosen union constraints a bit more --- include/sqlpp11/field_spec.h | 5 ++++- include/sqlpp11/union.h | 6 ------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/include/sqlpp11/field_spec.h b/include/sqlpp11/field_spec.h index 853367eb..65320dd4 100644 --- a/include/sqlpp11/field_spec.h +++ b/include/sqlpp11/field_spec.h @@ -46,7 +46,10 @@ namespace sqlpp static constexpr auto is_compatible(field_spec_t) -> bool { using rhs = field_spec_t; - return std::is_same<_traits, typename rhs::_traits>::value and + return std::is_same::value and // We might need to know that float can hold int, too + (CanBeNull or CanBeNull == C) and // The left hand side determines the result row and therefore must allow + // NULL if the right hand side allows it + (NullIsTrivialValue or NullIsTrivialValue == T) and std::is_same::value; } }; diff --git a/include/sqlpp11/union.h b/include/sqlpp11/union.h index 4e044eab..6a3920f1 100644 --- a/include/sqlpp11/union.h +++ b/include/sqlpp11/union.h @@ -218,9 +218,6 @@ namespace sqlpp constexpr auto vec_rhs = detail::type_vector{}; static_assert(lhs_result_row_t::is_compatible(vec_rhs), "both arguments in a union have to have the same result columns (type and name)"); - static_assert( - is_static_result_row_t::value && is_static_result_row_t::value, - "unions must not have dynamically added columns"); return _union_impl(check_union_t, Rhs>{}, rhs); } @@ -240,9 +237,6 @@ namespace sqlpp constexpr auto vec_rhs = detail::type_vector{}; static_assert(lhs_result_row_t::is_compatible(vec_rhs), "both arguments in a union have to have the same result columns (type and name)"); - static_assert( - is_static_result_row_t::value && is_static_result_row_t::value, - "unions must not have dynamically added columns"); return _union_impl(check_union_t, Rhs>{}, rhs); } From c6062116f8adf57cd89c663a5c30db673c7cb70c Mon Sep 17 00:00:00 2001 From: rbock Date: Tue, 1 Nov 2016 18:38:09 +0100 Subject: [PATCH 07/22] Added a few more UNION tests --- tests/Union.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/Union.cpp b/tests/Union.cpp index b896cf94..d4eb541e 100644 --- a/tests/Union.cpp +++ b/tests/Union.cpp @@ -29,6 +29,12 @@ #include #include +namespace greek +{ + SQLPP_ALIAS_PROVIDER(alpha) + SQLPP_ALIAS_PROVIDER(beta) +} + int Union(int, char* []) { MockDb db; @@ -40,6 +46,15 @@ int Union(int, char* []) db(select(t.alpha).from(t).unconditionally().union_distinct(select(f.epsilon.as(t.alpha)).from(f).unconditionally())); db(select(t.alpha).from(t).unconditionally().union_all(select(f.epsilon.as(t.alpha)).from(f).unconditionally())); + // t.alpha can be null, a given value cannot + db(select(t.alpha).from(t).unconditionally().union_all(select(sqlpp::value(1).as(t.alpha)))); + db(select(t.alpha).from(t).unconditionally().union_all(select(sqlpp::value(1).as(greek::alpha)))); + + // t.beta can be null, f.delta cannot + static_assert(sqlpp::can_be_null_t::value, ""); + static_assert(!sqlpp::can_be_null_t::value, ""); + db(select(t.beta).from(t).unconditionally().union_all(select(f.delta.as(greek::beta)).from(f).unconditionally())); + auto u = select(t.alpha) .from(t) .unconditionally() From 7f701dff905ab2b47ba2b82a21ee664b27b1d540 Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 10 Nov 2016 12:28:46 +0100 Subject: [PATCH 08/22] Added a first few tests for .as() --- test_serializer/As.cpp | 46 ++++++++++++++++++++++++++++++++++ test_serializer/CMakeLists.txt | 1 + 2 files changed, 47 insertions(+) create mode 100644 test_serializer/As.cpp diff --git a/test_serializer/As.cpp b/test_serializer/As.cpp new file mode 100644 index 00000000..78eb5b19 --- /dev/null +++ b/test_serializer/As.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2016-2016, Roland Bock + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "compare.h" +#include "Sample.h" +#include + +#include + +SQLPP_ALIAS_PROVIDER(cheese); + +int As(int, char* []) +{ + const auto foo = test::TabFoo{}; + const auto bar = test::TabBar{}; + + compare(__LINE__, foo.omega.as(cheese), "tab_foo.omega AS cheese"); + compare(__LINE__, (foo.omega + 17).as(cheese), "(tab_foo.omega+17) AS cheese"); + compare(__LINE__, (foo.omega - 17).as(cheese), "(tab_foo.omega-17) AS cheese"); + compare(__LINE__, (foo.omega - bar.alpha).as(cheese), "(tab_foo.omega-tab_bar.alpha) AS cheese"); + compare(__LINE__, (count(foo.omega) - bar.alpha).as(cheese), "(COUNT(tab_foo.omega)-tab_bar.alpha) AS cheese"); + + return 0; +} diff --git a/test_serializer/CMakeLists.txt b/test_serializer/CMakeLists.txt index b00c6860..f7f38f91 100644 --- a/test_serializer/CMakeLists.txt +++ b/test_serializer/CMakeLists.txt @@ -24,6 +24,7 @@ set(test_serializer_names CustomQuery + As From In Insert From 7c20a68e0b33e757b1caef18c17218d7ef6ae35b Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 12 Nov 2016 10:35:03 +0100 Subject: [PATCH 09/22] Fixed result types for `signed OP unsigned` expressions. --- .../sqlpp11/data_types/integral/expression_operators.h | 8 ++++---- .../data_types/unsigned_integral/expression_operators.h | 2 +- test_serializer/As.cpp | 2 ++ test_serializer/CMakeLists.txt | 2 +- tests/SelectType.cpp | 3 ++- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/include/sqlpp11/data_types/integral/expression_operators.h b/include/sqlpp11/data_types/integral/expression_operators.h index 445703b5..71e7a876 100644 --- a/include/sqlpp11/data_types/integral/expression_operators.h +++ b/include/sqlpp11/data_types/integral/expression_operators.h @@ -53,7 +53,7 @@ namespace sqlpp struct return_type_plus> { using check = consistent_t; - using type = integral; + using type = plus_t, integral, wrap_operand_t>; }; template @@ -67,7 +67,7 @@ namespace sqlpp struct return_type_minus> { using check = consistent_t; - using type = integral; + using type = minus_t, integral, wrap_operand_t>; }; template @@ -81,7 +81,7 @@ namespace sqlpp struct return_type_multiplies> { using check = consistent_t; - using type = integral; + using type = multiplies_t, integral, wrap_operand_t>; }; template @@ -95,7 +95,7 @@ namespace sqlpp struct return_type_divides> { using check = consistent_t; - using type = integral; + using type = divides_t, wrap_operand_t>; }; template diff --git a/include/sqlpp11/data_types/unsigned_integral/expression_operators.h b/include/sqlpp11/data_types/unsigned_integral/expression_operators.h index 1c016102..bb5730b7 100644 --- a/include/sqlpp11/data_types/unsigned_integral/expression_operators.h +++ b/include/sqlpp11/data_types/unsigned_integral/expression_operators.h @@ -38,7 +38,7 @@ namespace sqlpp { struct integral; - + template struct expression_operators : public basic_expression_operators { diff --git a/test_serializer/As.cpp b/test_serializer/As.cpp index 78eb5b19..76c4dcfa 100644 --- a/test_serializer/As.cpp +++ b/test_serializer/As.cpp @@ -39,8 +39,10 @@ int As(int, char* []) compare(__LINE__, foo.omega.as(cheese), "tab_foo.omega AS cheese"); compare(__LINE__, (foo.omega + 17).as(cheese), "(tab_foo.omega+17) AS cheese"); compare(__LINE__, (foo.omega - 17).as(cheese), "(tab_foo.omega-17) AS cheese"); + compare(__LINE__, (foo.omega - uint32_t(17)).as(cheese), "(tab_foo.omega-17) AS cheese"); compare(__LINE__, (foo.omega - bar.alpha).as(cheese), "(tab_foo.omega-tab_bar.alpha) AS cheese"); compare(__LINE__, (count(foo.omega) - bar.alpha).as(cheese), "(COUNT(tab_foo.omega)-tab_bar.alpha) AS cheese"); + compare(__LINE__, (count(foo.omega) - uint32_t(17)).as(cheese), "(COUNT(tab_foo.omega)-17) AS cheese"); return 0; } diff --git a/test_serializer/CMakeLists.txt b/test_serializer/CMakeLists.txt index f7f38f91..07add5a0 100644 --- a/test_serializer/CMakeLists.txt +++ b/test_serializer/CMakeLists.txt @@ -28,8 +28,8 @@ set(test_serializer_names From In Insert - Where TableAlias + Where ) create_test_sourcelist(test_serializer_sources test_serializer_main.cpp ${test_serializer_names}) diff --git a/tests/SelectType.cpp b/tests/SelectType.cpp index 9dc7d845..f0781007 100644 --- a/tests/SelectType.cpp +++ b/tests/SelectType.cpp @@ -167,7 +167,8 @@ int SelectType(int, char* []) static_assert(sqlpp::is_integral_t>::value, "type requirement"); static_assert(sqlpp::is_integral_t>::value, "type requirement"); static_assert(sqlpp::is_integral_t>::value, "type requirement"); - static_assert(sqlpp::is_integral_t>::value, "type requirement"); + static_assert(sqlpp::is_floating_point_t>::value, + "type requirement"); static_assert(sqlpp::is_integral_t>::value, "type requirement"); } From 1b9a4b15940fce6a9c875bf5fc70cc4c9e16b4c2 Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 25 Dec 2016 10:44:22 +0100 Subject: [PATCH 10/22] Replace is_compatible function with class template MSVC choked on that function (claimed that the number of arguments was incorrect) --- include/sqlpp11/result_row.h | 27 ++++++++++++++------------- include/sqlpp11/union.h | 6 ++---- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/include/sqlpp11/result_row.h b/include/sqlpp11/result_row.h index 883065e3..bebe78dd 100644 --- a/include/sqlpp11/result_row.h +++ b/include/sqlpp11/result_row.h @@ -186,19 +186,6 @@ namespace sqlpp using _impl = detail::result_row_impl; bool _is_valid; - template - static constexpr auto is_compatible(detail::type_vector>) -> - typename std::enable_if::type - { - return logic::all_t::value; - } - - template - static constexpr auto is_compatible(detail::type_vector>) -> - typename std::enable_if::type - { - return false; - } result_row_t() : _impl(), _is_valid(false) { } @@ -264,6 +251,20 @@ namespace sqlpp } }; + template + struct is_result_compatible + { + static constexpr auto value = false; + }; + + template + struct is_result_compatible, + result_row_t, + typename std::enable_if::type> + { + static constexpr auto value = logic::all_t::value; + }; + template struct dynamic_result_row_t : public detail::result_row_impl, FieldSpecs...> diff --git a/include/sqlpp11/union.h b/include/sqlpp11/union.h index 6a3920f1..624e5ff2 100644 --- a/include/sqlpp11/union.h +++ b/include/sqlpp11/union.h @@ -215,8 +215,7 @@ namespace sqlpp using lhs_result_row_t = get_result_row_t>; using rhs_result_row_t = get_result_row_t; - constexpr auto vec_rhs = detail::type_vector{}; - static_assert(lhs_result_row_t::is_compatible(vec_rhs), + static_assert(is_result_compatible::value, "both arguments in a union have to have the same result columns (type and name)"); return _union_impl(check_union_t, Rhs>{}, rhs); @@ -234,8 +233,7 @@ namespace sqlpp using lhs_result_row_t = get_result_row_t>; using rhs_result_row_t = get_result_row_t; - constexpr auto vec_rhs = detail::type_vector{}; - static_assert(lhs_result_row_t::is_compatible(vec_rhs), + static_assert(is_result_compatible::value, "both arguments in a union have to have the same result columns (type and name)"); return _union_impl(check_union_t, Rhs>{}, rhs); From fa8cb7b0afdea95d8fc2e5f465e77b039622b7e7 Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 25 Dec 2016 11:37:41 +0100 Subject: [PATCH 11/22] Replaced field_spec_t::is_compatible function with a class template. Also removed two stand-alone union functions which did not work anyway. Let's see if MSVC is happy now. --- include/sqlpp11/field_spec.h | 55 +++++++++++++++++++++--------------- include/sqlpp11/result_row.h | 2 +- include/sqlpp11/union.h | 2 ++ 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/include/sqlpp11/field_spec.h b/include/sqlpp11/field_spec.h index 65320dd4..53d6189f 100644 --- a/include/sqlpp11/field_spec.h +++ b/include/sqlpp11/field_spec.h @@ -41,17 +41,6 @@ namespace sqlpp using _nodes = detail::type_vector<>; using _alias_t = NameType; - - template - static constexpr auto is_compatible(field_spec_t) -> bool - { - using rhs = field_spec_t; - return std::is_same::value and // We might need to know that float can hold int, too - (CanBeNull or CanBeNull == C) and // The left hand side determines the result row and therefore must allow - // NULL if the right hand side allows it - (NullIsTrivialValue or NullIsTrivialValue == T) and - std::is_same::value; - } }; template @@ -64,19 +53,39 @@ namespace sqlpp template struct multi_field_spec_t> { - template - static constexpr auto is_compatible(multi_field_spec_t) -> - typename std::enable_if::type - { - return logic::all_t::value; - } + }; - template - static constexpr auto is_compatible(multi_field_spec_t) -> - typename std::enable_if::type - { - return false; - } + template + struct is_field_compatible + { + static constexpr auto value = false; + }; + + template + struct is_field_compatible, + field_spec_t> + { + static constexpr auto value = + std::is_same::value and + std::is_same::value and // Same value type + (LeftCanBeNull or !RightCanBeNull) and // The left hand side determines the result row and therefore must allow + // NULL if the right hand side allows it + (LeftNullIsTrivial or !RightNullIsTrivial); // as above + }; + + template + struct is_field_compatible>, + multi_field_spec_t>, + typename std::enable_if::type> + { + static constexpr auto value = logic::all_t::value...>::value; }; namespace detail diff --git a/include/sqlpp11/result_row.h b/include/sqlpp11/result_row.h index bebe78dd..8c620322 100644 --- a/include/sqlpp11/result_row.h +++ b/include/sqlpp11/result_row.h @@ -262,7 +262,7 @@ namespace sqlpp result_row_t, typename std::enable_if::type> { - static constexpr auto value = logic::all_t::value; + static constexpr auto value = logic::all_t::value...>::value; }; template diff --git a/include/sqlpp11/union.h b/include/sqlpp11/union.h index 624e5ff2..dd15400d 100644 --- a/include/sqlpp11/union.h +++ b/include/sqlpp11/union.h @@ -253,6 +253,7 @@ namespace sqlpp }; }; + /* template auto union_all(T&& t) -> decltype(statement_t().union_all(std::forward(t))) { @@ -264,6 +265,7 @@ namespace sqlpp { return statement_t().union_distinct(std::forward(t)); } + */ } #endif From 522d760a4924624e7c26953c6472de376de8c0cf Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 25 Dec 2016 12:57:20 +0100 Subject: [PATCH 12/22] Cleaned up travis config a bit OSX: Using the default XCode now Linux: Installing CMake as package (not by downloading and compiling) --- .travis.yml | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index c9d8325d..3a257492 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,6 @@ os: - linux - osx -osx_image: xcode7 - compiler: - clang - gcc @@ -29,19 +27,12 @@ install: - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test && sudo add-apt-repository -y ppa:apokluda/boost1.53 + && sudo add-apt-repository -y ppa:george-edison55/cmake-3.x + && sudo apt-get update -qq && sudo apt-get update -qq && sudo apt-get install -qq g++-4.8 libboost1.53-dev --no-install-recommends - && sudo update-alternatives --quiet --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6 --slave /usr/bin/gcov gcov /usr/bin/gcov-4.6 - && sudo update-alternatives --quiet --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8 --slave /usr/bin/gcov gcov /usr/bin/gcov-4.8 - && sudo update-alternatives --quiet --set gcc /usr/bin/gcc-4.8 - && wget --no-check-certificate http://www.cmake.org/files/v${CMAKE_VERSION_MM}/cmake-${CMAKE_VERSION_FULL}-Linux-x86_64.sh - && sudo sh cmake-${CMAKE_VERSION_FULL}-Linux-x86_64.sh --prefix=/usr/local --exclude-subdir; - fi - - if [ "$TRAVIS_OS_NAME" = "osx" ]; then - brew update - && ((brew list -1 | grep -q "^$cmake\$") || brew install cmake) - && (brew outdated cmake || brew upgrade cmake) - && cmake --version; + && sudo apt-get install -qq -y g++-4.9 cmake cmake-data + ; fi before_script: From 91be9e7ea00c785e68ffd4f78d47f24c8901f9cf Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 25 Dec 2016 13:22:06 +0100 Subject: [PATCH 13/22] Fine tuning travis linux settings --- .travis.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3a257492..3a249ef3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,8 +18,6 @@ notifications: on_failure: always install: - - CMAKE_VERSION_MM=3.2 - - CMAKE_VERSION_FULL=$CMAKE_VERSION_MM.2 - git clone https://github.com/HowardHinnant/date - cd date - git checkout tags/v1.0.0 @@ -29,9 +27,8 @@ install: && sudo add-apt-repository -y ppa:apokluda/boost1.53 && sudo add-apt-repository -y ppa:george-edison55/cmake-3.x && sudo apt-get update -qq - && sudo apt-get update -qq + && sudo apt-get upgrade -qq -y && sudo apt-get install -qq g++-4.8 libboost1.53-dev --no-install-recommends - && sudo apt-get install -qq -y g++-4.9 cmake cmake-data ; fi From 0a1a123c3602fa5bdbe9834bf5332178cd78c6fd Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 25 Dec 2016 13:33:38 +0100 Subject: [PATCH 14/22] Still trying to get travis setup right --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3a249ef3..8c5dad07 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,8 +27,8 @@ install: && sudo add-apt-repository -y ppa:apokluda/boost1.53 && sudo add-apt-repository -y ppa:george-edison55/cmake-3.x && sudo apt-get update -qq - && sudo apt-get upgrade -qq -y - && sudo apt-get install -qq g++-4.8 libboost1.53-dev --no-install-recommends + && sudo apt-get install g++-4.8 libboost1.53-dev --no-install-recommends -y + && sudo apt-get install cmake cmake-data -y ; fi From 638c8d502ebdf60ea57e0e5b6be3306db1d3d993 Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 25 Dec 2016 13:38:53 +0100 Subject: [PATCH 15/22] Next attempt for apt-get et al. --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8c5dad07..13a3f0d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,7 +28,8 @@ install: && sudo add-apt-repository -y ppa:george-edison55/cmake-3.x && sudo apt-get update -qq && sudo apt-get install g++-4.8 libboost1.53-dev --no-install-recommends -y - && sudo apt-get install cmake cmake-data -y + && sudo apt-get remove cmake -y + && sudo apt-get install cmake -y ; fi From 92b841c58fc53b9d497d51d9e95db361e949abfe Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 25 Dec 2016 13:46:46 +0100 Subject: [PATCH 16/22] WTF --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 13a3f0d2..a6477f1a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,9 +26,8 @@ install: sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test && sudo add-apt-repository -y ppa:apokluda/boost1.53 && sudo add-apt-repository -y ppa:george-edison55/cmake-3.x - && sudo apt-get update -qq + && sudo apt-get update && sudo apt-get install g++-4.8 libboost1.53-dev --no-install-recommends -y - && sudo apt-get remove cmake -y && sudo apt-get install cmake -y ; fi From 47eb562e5dc5f6ae3e16fb6b59293986d66d5f97 Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 25 Dec 2016 14:08:05 +0100 Subject: [PATCH 17/22] Looking for cmake-3.* --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index a6477f1a..f8df5424 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,7 @@ install: && sudo add-apt-repository -y ppa:apokluda/boost1.53 && sudo add-apt-repository -y ppa:george-edison55/cmake-3.x && sudo apt-get update + && sudo apt-cache madison cmake && sudo apt-get install g++-4.8 libboost1.53-dev --no-install-recommends -y && sudo apt-get install cmake -y ; From 89185c0bf7737ac667bfc8b405aa9ff459dfb2b4 Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 25 Dec 2016 14:16:38 +0100 Subject: [PATCH 18/22] Switching travis to trusty --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index f8df5424..e670d98c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,9 @@ os: - linux - osx +dist: trusty +sudo: required + compiler: - clang - gcc @@ -22,6 +25,7 @@ install: - cd date - git checkout tags/v1.0.0 - cd .. + - g++ --version - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test && sudo add-apt-repository -y ppa:apokluda/boost1.53 From 57270414ea6e42f186af6728e25a16ccc7affa62 Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 25 Dec 2016 14:24:10 +0100 Subject: [PATCH 19/22] Hah! trusty comes with gcc-4.8 already --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e670d98c..07725e19 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,13 +26,12 @@ install: - git checkout tags/v1.0.0 - cd .. - g++ --version + - cmake --version - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test - && sudo add-apt-repository -y ppa:apokluda/boost1.53 && sudo add-apt-repository -y ppa:george-edison55/cmake-3.x && sudo apt-get update && sudo apt-cache madison cmake - && sudo apt-get install g++-4.8 libboost1.53-dev --no-install-recommends -y && sudo apt-get install cmake -y ; fi From 65d32fac8c0443c67ad944c0fe83b5679478dba6 Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 25 Dec 2016 14:25:30 +0100 Subject: [PATCH 20/22] Disabled part of the travis matrix for testing --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 07725e19..7587256c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,17 +2,17 @@ language: cpp os: - linux - - osx + #- osx dist: trusty sudo: required compiler: - - clang + #- clang - gcc env: - - CONFIG=Release + #- CONFIG=Release - CONFIG=Debug notifications: From f21102398121dcecc53a555420e0baf136cb9acc Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 25 Dec 2016 14:32:47 +0100 Subject: [PATCH 21/22] CMake 3.2 seems to be available on trusty already --- .travis.yml | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7587256c..222c4842 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,18 +2,18 @@ language: cpp os: - linux - #- osx + - osx dist: trusty sudo: required compiler: - #- clang + - clang - gcc env: - #- CONFIG=Release - - CONFIG=Debug + - CONFIG=Release + #- CONFIG=Debug notifications: email: @@ -21,20 +21,12 @@ notifications: on_failure: always install: + - g++ --version + - cmake --version - git clone https://github.com/HowardHinnant/date - cd date - git checkout tags/v1.0.0 - cd .. - - g++ --version - - cmake --version - - if [ "$TRAVIS_OS_NAME" == "linux" ]; then - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test - && sudo add-apt-repository -y ppa:george-edison55/cmake-3.x - && sudo apt-get update - && sudo apt-cache madison cmake - && sudo apt-get install cmake -y - ; - fi before_script: - mkdir build From ee6aa6e2c55273e12eada10bcb44f96f1cfb9092 Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 25 Dec 2016 14:44:26 +0100 Subject: [PATCH 22/22] Silence warning in gcc about unused parameter --- include/sqlpp11/select_column_list.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/sqlpp11/select_column_list.h b/include/sqlpp11/select_column_list.h index 8059eef6..ae29d52f 100644 --- a/include/sqlpp11/select_column_list.h +++ b/include/sqlpp11/select_column_list.h @@ -376,7 +376,7 @@ namespace sqlpp template static constexpr auto _check_args(T... args) -> decltype(_check_tuple(detail::column_tuple_merge(args...))) { - return {}; + return _check_tuple(detail::column_tuple_merge(args...)); } template