From d062c1a0d8066f6528d03aae3e13ce6970e38989 Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 15 May 2014 08:00:03 +0200 Subject: [PATCH 01/65] Started to rewrite traits and recursive traits traits are shorter and easier to identify by using tags in a variadic template recursive traits can be automatically derived, which makes it much easier to add new traits to be handed through the expression tree. --- include/sqlpp11/alias.h | 11 ++----- include/sqlpp11/any.h | 9 ++---- include/sqlpp11/avg.h | 10 ++---- include/sqlpp11/boolean.h | 7 +---- include/sqlpp11/column.h | 23 +++++++------- include/sqlpp11/count.h | 10 ++---- include/sqlpp11/default_value.h | 5 ++- include/sqlpp11/exists.h | 10 ++---- include/sqlpp11/floating_point.h | 8 +---- include/sqlpp11/functions.h | 12 ++++--- include/sqlpp11/integral.h | 7 ----- include/sqlpp11/join.h | 9 +++--- include/sqlpp11/max.h | 10 ++---- include/sqlpp11/min.h | 10 ++---- include/sqlpp11/multi_column.h | 9 ++++-- include/sqlpp11/no_value.h | 5 --- include/sqlpp11/null.h | 5 ++- include/sqlpp11/on.h | 4 ++- include/sqlpp11/parameter.h | 10 ++---- include/sqlpp11/result_row.h | 4 +-- include/sqlpp11/select_flags.h | 21 ++++--------- include/sqlpp11/some.h | 8 ++--- include/sqlpp11/sort_order.h | 3 +- include/sqlpp11/sum.h | 8 ++--- include/sqlpp11/table.h | 11 +++++-- include/sqlpp11/table_alias.h | 13 ++++---- include/sqlpp11/text.h | 5 --- include/sqlpp11/tvin.h | 11 ++++--- include/sqlpp11/vendor/assignment.h | 35 ++++++++++++++------- include/sqlpp11/vendor/concat.h | 3 +- include/sqlpp11/vendor/expression.h | 15 ++++++--- include/sqlpp11/vendor/extra_tables.h | 6 ++-- include/sqlpp11/vendor/from.h | 7 +++-- include/sqlpp11/vendor/group_by.h | 6 ++-- include/sqlpp11/vendor/having.h | 6 ++-- include/sqlpp11/vendor/in.h | 3 +- include/sqlpp11/vendor/insert_value.h | 6 ++-- include/sqlpp11/vendor/insert_value_list.h | 16 +++++----- include/sqlpp11/vendor/is_null.h | 3 +- include/sqlpp11/vendor/like.h | 3 +- include/sqlpp11/vendor/limit.h | 9 ++++-- include/sqlpp11/vendor/offset.h | 9 ++++-- include/sqlpp11/vendor/order_by.h | 6 ++-- include/sqlpp11/vendor/select_column_list.h | 6 ++-- include/sqlpp11/vendor/select_flag_list.h | 6 ++-- include/sqlpp11/vendor/single_table.h | 7 +++-- include/sqlpp11/vendor/update_list.h | 3 +- include/sqlpp11/vendor/using.h | 6 ++-- include/sqlpp11/vendor/where.h | 9 ++++-- include/sqlpp11/vendor/wrap_operand.h | 12 ++++--- include/sqlpp11/verbatim_table.h | 2 -- 51 files changed, 218 insertions(+), 224 deletions(-) diff --git a/include/sqlpp11/alias.h b/include/sqlpp11/alias.h index 39f3bb52..da2b5f9a 100644 --- a/include/sqlpp11/alias.h +++ b/include/sqlpp11/alias.h @@ -33,18 +33,13 @@ namespace sqlpp template struct expression_alias_t { + using _traits = make_traits_t, tag::named_expression>; + using _recursive_traits = make_recursive_traits_t; + static_assert(is_expression_t::value, "invalid argument for an expression alias"); static_assert(not is_alias_t::value, "cannot create an alias of an alias"); - struct _value_type: Expression::_value_type - { - using _is_expression = std::false_type; - using _is_named_expression = std::true_type; - using _is_alias = std::true_type; - }; - using _name_t = typename AliasProvider::_name_t; - using _table_set = typename Expression::_table_set; Expression _expression; }; diff --git a/include/sqlpp11/any.h b/include/sqlpp11/any.h index 1f8a55b5..fa7eb456 100644 --- a/include/sqlpp11/any.h +++ b/include/sqlpp11/any.h @@ -37,11 +37,8 @@ namespace sqlpp template struct any_t { - struct _value_type: public Select::_value_type::_base_value_type - { - using _is_expression = std::false_type; - using _is_multi_expression = std::true_type; // must not be named or used with +,-,*,/, etc - }; + using _traits = make_traits_t, tag::multi_expression>; + using _recursive_traits = make_recursive_traits_t; + static_assert(is_noop::value or std::is_same::value, "avg() used with flag other than 'distinct'"); static_assert(is_numeric_t::value, "avg() requires a value expression as argument"); - struct _value_type: public floating_point - { - using _is_named_expression = std::true_type; - }; - - using _table_set = typename Expr::_table_set; - struct _name_t { static constexpr const char* _get_name() { return "AVG"; } diff --git a/include/sqlpp11/boolean.h b/include/sqlpp11/boolean.h index 66e80853..ee8a3dc4 100644 --- a/include/sqlpp11/boolean.h +++ b/include/sqlpp11/boolean.h @@ -42,16 +42,11 @@ namespace sqlpp // boolean value type struct boolean { - using _value_type = boolean; - using _base_value_type = boolean; - using _is_boolean = std::true_type; - using _is_value = std::true_type; - using _is_expression = std::true_type; using _cpp_value_type = bool; struct _parameter_t { - using _value_type = boolean; + using _value_type = boolean; // FIXME _parameter_t(): _value(false), diff --git a/include/sqlpp11/column.h b/include/sqlpp11/column.h index 8292f376..8c227a30 100644 --- a/include/sqlpp11/column.h +++ b/include/sqlpp11/column.h @@ -45,21 +45,20 @@ namespace sqlpp struct column_t: public ColumnSpec::_value_type::template expression_operators>, public ColumnSpec::_value_type::template column_operators> { - using _is_column = std::true_type; + using _traits = make_traits_t, tag::column, tag::expression, tag::named_expression>; + struct _recursive_traits + { + using _provided_tables = detail::type_set<>; + using _required_tables = detail::type_set<_table>; + }; + using _spec_t = ColumnSpec; using _table = Table; - using _table_set = detail::type_set<_table>; - using _column_type = typename ColumnSpec::_column_type; - struct _value_type: ColumnSpec::_value_type - { - using _is_expression = std::true_type; - using _is_named_expression = std::true_type; - using _is_alias = std::false_type; - }; - template - using _is_valid_operand = typename _value_type::template _is_valid_operand; + using _column_type = typename _spec_t::_column_type; + using _name_t = typename _spec_t::_name_t; - using _name_t = typename ColumnSpec::_name_t; + template + using _is_valid_operand = typename value_type_of::template _is_valid_operand; column_t() = default; column_t(const column_t&) = default; diff --git a/include/sqlpp11/count.h b/include/sqlpp11/count.h index dc54437f..8cdd61df 100644 --- a/include/sqlpp11/count.h +++ b/include/sqlpp11/count.h @@ -37,16 +37,12 @@ namespace sqlpp template struct count_t: public sqlpp::detail::integral::template expression_operators> { + using _traits = make_traits_t, tag::expression, tag::named_expression>; + using _recursive_traits = make_recursive_traits_t; + static_assert(is_select_t; verbatim_t(std::string verbatim): _verbatim(verbatim) {} verbatim_t(const verbatim_t&) = default; @@ -102,9 +103,10 @@ namespace sqlpp template struct value_list_t // to be used in .in() method { + using _traits = make_traits_t; + using _recursive_traits = make_recursive_traits_t; + static_assert(is_value_t::value, "max() requires a value expression as argument"); - struct _value_type: public Expr::_value_type::_base_value_type - { - using _is_named_expression = std::true_type; - }; - - using _table_set = typename Expr::_table_set; - struct _name_t { static constexpr const char* _get_name() { return "MAX"; } diff --git a/include/sqlpp11/min.h b/include/sqlpp11/min.h index c7d9f9e0..3199ba8d 100644 --- a/include/sqlpp11/min.h +++ b/include/sqlpp11/min.h @@ -36,15 +36,11 @@ namespace sqlpp template struct min_t: public Expr::_value_type::template expression_operators> { + using _traits = make_traits_t, tag::expression, tag::named_expression>; + using _recursive_traits = make_recursive_traits_t; struct _name_t { @@ -54,7 +51,6 @@ namespace sqlpp const T& operator()() const { return some; } }; }; - using _table_set = typename Select::_table_set; some_t(Select select): _select(select) diff --git a/include/sqlpp11/sort_order.h b/include/sqlpp11/sort_order.h index d0616449..8f70b3c8 100644 --- a/include/sqlpp11/sort_order.h +++ b/include/sqlpp11/sort_order.h @@ -41,7 +41,8 @@ namespace sqlpp struct sort_order_t { using _is_sort_order = std::true_type; - using _table_set = typename Expression::_table_set; + using _provided_tables = detail::type_set<>; + using _required_tables = typename Expression::_required_tables; Expression _expression; }; diff --git a/include/sqlpp11/sum.h b/include/sqlpp11/sum.h index 745e48c3..b4a92611 100644 --- a/include/sqlpp11/sum.h +++ b/include/sqlpp11/sum.h @@ -36,14 +36,12 @@ namespace sqlpp template struct sum_t: public Expr::_value_type::template expression_operators> { + using _traits = make_traits_t, tag::expression, tag::named_expression>; + using _recursive_traits = make_recursive_traits_t; + using _traits = make_traits, ::sqlpp::tag::multi_expression>; + using _recursive_traits = make_recursive_traits; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; static_assert(is_noop::value or std::is_same::value, "avg() used with flag other than 'distinct'"); static_assert(is_numeric_t::value, "avg() requires a value expression as argument"); diff --git a/include/sqlpp11/boolean.h b/include/sqlpp11/boolean.h index ee8a3dc4..d5935484 100644 --- a/include/sqlpp11/boolean.h +++ b/include/sqlpp11/boolean.h @@ -42,6 +42,7 @@ namespace sqlpp // boolean value type struct boolean { + using _tag = ::sqlpp::tag::boolean; using _cpp_value_type = bool; struct _parameter_t diff --git a/include/sqlpp11/column.h b/include/sqlpp11/column.h index 8c227a30..8795a08b 100644 --- a/include/sqlpp11/column.h +++ b/include/sqlpp11/column.h @@ -45,11 +45,11 @@ namespace sqlpp struct column_t: public ColumnSpec::_value_type::template expression_operators>, public ColumnSpec::_value_type::template column_operators> { - using _traits = make_traits_t, tag::column, tag::expression, tag::named_expression>; + using _traits = make_traits; struct _recursive_traits { using _provided_tables = detail::type_set<>; - using _required_tables = detail::type_set<_table>; + using _required_tables = detail::type_set; }; using _spec_t = ColumnSpec; @@ -58,7 +58,7 @@ namespace sqlpp using _name_t = typename _spec_t::_name_t; template - using _is_valid_operand = typename value_type_of::template _is_valid_operand; + using _is_valid_operand = typename ColumnSpec::_value_type::template _is_valid_operand; column_t() = default; column_t(const column_t&) = default; diff --git a/include/sqlpp11/count.h b/include/sqlpp11/count.h index 8cdd61df..eec747be 100644 --- a/include/sqlpp11/count.h +++ b/include/sqlpp11/count.h @@ -37,8 +37,8 @@ namespace sqlpp template struct count_t: public sqlpp::detail::integral::template expression_operators> { - using _traits = make_traits_t, tag::expression, tag::named_expression>; - using _recursive_traits = make_recursive_traits_t; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits::value, "exists() requires a select expression as argument"); diff --git a/include/sqlpp11/floating_point.h b/include/sqlpp11/floating_point.h index 2411305a..48bd70b9 100644 --- a/include/sqlpp11/floating_point.h +++ b/include/sqlpp11/floating_point.h @@ -41,6 +41,7 @@ namespace sqlpp // floating_point value type struct floating_point { + using _tag = ::sqlpp::tag::floating_point; using _cpp_value_type = double; struct _parameter_t diff --git a/include/sqlpp11/functions.h b/include/sqlpp11/functions.h index 86ba048b..c05f46a3 100644 --- a/include/sqlpp11/functions.h +++ b/include/sqlpp11/functions.h @@ -50,15 +50,15 @@ namespace sqlpp { using _provided_tables = detail::type_set<>; using _required_tables = ::sqlpp::detail::type_set<>; - static_assert(not is_value_t::value, "value() is to be called with non-sql-type like int, or string"); + static_assert(not is_expression_t::value, "value() is to be called with non-sql-type like int, or string"); return { t }; } template // Csaba Csoma suggests: unsafe_sql instead of verbatim struct verbatim_t: public ValueType::template expression_operators> { - using _traits = make_traits_t; - using _recursive_traits = make_recursive_traits_t; + using _traits = make_traits>; + using _recursive_traits = make_recursive_traits<>; using _container_t = Container; @@ -148,7 +148,7 @@ namespace sqlpp template auto value_list(Container c) -> value_list_t { - static_assert(not is_value_t::value, "value_list() is to be called with a container of non-sql-type like std::vector, or std::list(string)"); + static_assert(not is_expression_t::value, "value_list() is to be called with a container of non-sql-type like std::vector, or std::list(string)"); return { c }; } diff --git a/include/sqlpp11/integral.h b/include/sqlpp11/integral.h index 6e65e4fb..34366d85 100644 --- a/include/sqlpp11/integral.h +++ b/include/sqlpp11/integral.h @@ -42,6 +42,7 @@ namespace sqlpp // integral value type struct integral { + using _tag = ::sqlpp::tag::integral; using _cpp_value_type = int64_t; struct _parameter_t diff --git a/include/sqlpp11/join.h b/include/sqlpp11/join.h index 66b08e05..d4f96abf 100644 --- a/include/sqlpp11/join.h +++ b/include/sqlpp11/join.h @@ -77,8 +77,8 @@ namespace sqlpp template struct join_t { - using _traits = make_traits_t; - using _recursive_traits = make_recursive_traits_t; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; static_assert(is_table_t::value, "lhs argument for join() has to be a table or join"); static_assert(is_table_t::value, "rhs argument for join() has to be a table"); diff --git a/include/sqlpp11/max.h b/include/sqlpp11/max.h index 683a0db7..faf903fb 100644 --- a/include/sqlpp11/max.h +++ b/include/sqlpp11/max.h @@ -34,12 +34,12 @@ namespace sqlpp namespace vendor { template - struct max_t: public Expr::_value_type::template expression_operators> + struct max_t: public value_type_of::template expression_operators> { - using _traits = make_traits_t, tag::expression, tag::named_expression>; - using _recursive_traits = make_recursive_traits_t; + using _traits = make_traits, ::sqlpp::tag::expression, ::sqlpp::tag::named_expression>; + using _recursive_traits = make_recursive_traits; - static_assert(is_value_t::value, "min() requires a value expression as argument"); + static_assert(is_expression_t::value, "min() requires a value expression as argument"); struct _name_t { @@ -87,7 +87,7 @@ namespace sqlpp template auto min(T t) -> typename vendor::min_t> { - static_assert(is_value_t>::value, "min() requires a value expression as argument"); + static_assert(is_expression_t>::value, "min() requires a value expression as argument"); return { t }; } diff --git a/include/sqlpp11/multi_column.h b/include/sqlpp11/multi_column.h index 52c3340f..d61c2aaf 100644 --- a/include/sqlpp11/multi_column.h +++ b/include/sqlpp11/multi_column.h @@ -41,8 +41,8 @@ namespace sqlpp template struct multi_column_t { - using _traits = make_traits_t; - using _recursive_traits = make_recursive_traits_t; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; static_assert(detail::all_t::value...>::value, "multi_column parameters need to be named expressions"); @@ -76,8 +76,8 @@ namespace sqlpp template struct multi_column_alias_t { - using _traits = make_traits_t; - using _recursive_traits = make_recursive_traits_t; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; static_assert(detail::all_t::value...>::value, "multi_column parameters need to be named expressions"); diff --git a/include/sqlpp11/no_value.h b/include/sqlpp11/no_value.h index 4db1b9b1..c5ec11fa 100644 --- a/include/sqlpp11/no_value.h +++ b/include/sqlpp11/no_value.h @@ -33,6 +33,7 @@ namespace sqlpp { struct no_value_t { + using _tag = void; template struct _is_valid_operand { diff --git a/include/sqlpp11/null.h b/include/sqlpp11/null.h index 64c1f706..7119998d 100644 --- a/include/sqlpp11/null.h +++ b/include/sqlpp11/null.h @@ -33,8 +33,8 @@ namespace sqlpp { struct null_t { - using _traits = make_traits_t; - using _recursive_traits = make_recursive_traits_t<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; }; namespace vendor diff --git a/include/sqlpp11/on.h b/include/sqlpp11/on.h index 47e6dcb2..caa23bc6 100644 --- a/include/sqlpp11/on.h +++ b/include/sqlpp11/on.h @@ -37,8 +37,8 @@ namespace sqlpp template struct on_t { - using _traits = make_traits_t; - using _recursive_traits = make_recursive_traits_t; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; diff --git a/include/sqlpp11/parameter.h b/include/sqlpp11/parameter.h index c8df02ae..d13afdbf 100644 --- a/include/sqlpp11/parameter.h +++ b/include/sqlpp11/parameter.h @@ -36,8 +36,8 @@ namespace sqlpp template struct parameter_t: public ValueType::template expression_operators> { - using _traits = make_traits_t; - using _recursive_traits = make_recursive_traits_t<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; using _instance_t = typename NameType::_name_t::template _member_t; @@ -78,7 +78,7 @@ namespace sqlpp auto parameter(const ValueType&, const AliasProvider&) -> parameter_t { - static_assert(is_value_t::value, "first argument is not a value type"); + static_assert(is_expression_t::value, "first argument is not a value type"); static_assert(is_alias_provider_t::value, "second argument is not an alias provider"); return {}; } diff --git a/include/sqlpp11/select_flags.h b/include/sqlpp11/select_flags.h index 4439024c..3462f224 100644 --- a/include/sqlpp11/select_flags.h +++ b/include/sqlpp11/select_flags.h @@ -37,8 +37,8 @@ namespace sqlpp // standard select flags struct all_t { - using _traits = make_traits_t; - using _recursive_traits = make_recursive_traits_t<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; }; static constexpr all_t all = {}; @@ -57,8 +57,8 @@ namespace sqlpp struct distinct_t { - using _traits = make_traits_t; - using _recursive_traits = make_recursive_traits_t<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; }; static constexpr distinct_t distinct = {}; @@ -77,8 +77,8 @@ namespace sqlpp struct straight_join_t { - using _traits = make_traits_t; - using _recursive_traits = make_recursive_traits_t<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; }; static constexpr straight_join_t straight_join = {}; diff --git a/include/sqlpp11/some.h b/include/sqlpp11/some.h index 501004b0..5fe64cac 100644 --- a/include/sqlpp11/some.h +++ b/include/sqlpp11/some.h @@ -37,8 +37,8 @@ namespace sqlpp template struct some_t { - using _traits = make_traits_t, tag::multi_expression>; - using _recursive_traits = make_recursive_traits_t; struct _name_t { @@ -87,7 +87,7 @@ namespace sqlpp auto some(T t) -> typename vendor::some_t> { static_assert(is_select_t>::value, "some() requires a single column select expression as argument"); - static_assert(is_value_t>::value, "some() requires a single column select expression as argument"); + static_assert(is_expression_t>::value, "some() requires a single column select expression as argument"); return { t }; } diff --git a/include/sqlpp11/sum.h b/include/sqlpp11/sum.h index b4a92611..d258ca2d 100644 --- a/include/sqlpp11/sum.h +++ b/include/sqlpp11/sum.h @@ -34,10 +34,10 @@ namespace sqlpp namespace vendor { template - struct sum_t: public Expr::_value_type::template expression_operators> + struct sum_t: public value_type_of::template expression_operators> { - using _traits = make_traits_t, tag::expression, tag::named_expression>; - using _recursive_traits = make_recursive_traits_t
; }; - static_assert(Table::_required_tables::size::value == 0, "table aliases must not depend on external tables"); + static_assert(required_tables_of
::size::value == 0, "table aliases must not depend on external tables"); using _name_t = typename AliasProvider::_name_t; using _column_tuple_t = std::tuple...>; diff --git a/include/sqlpp11/text.h b/include/sqlpp11/text.h index e0b4998a..dbb32118 100644 --- a/include/sqlpp11/text.h +++ b/include/sqlpp11/text.h @@ -41,6 +41,7 @@ namespace sqlpp // text value type struct text { + using _tag = ::sqlpp::tag::text; using _cpp_value_type = std::string; struct _parameter_t diff --git a/include/sqlpp11/tvin.h b/include/sqlpp11/tvin.h index f6444bff..a838296e 100644 --- a/include/sqlpp11/tvin.h +++ b/include/sqlpp11/tvin.h @@ -32,14 +32,15 @@ #include #include #include +#include namespace sqlpp { template struct tvin_t { - using _traits = make_traits_t, tag::operand, tag::expression>; - using _recursive_traits = make_recursive_traits_t; + using _traits = make_traits, tag::expression>; + using _recursive_traits = make_recursive_traits; tvin_t(Operand operand): _value(operand) @@ -55,7 +56,7 @@ namespace sqlpp return _value._is_trivial(); } - _operand_t _value; + Operand _value; }; namespace vendor diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index b4d39bf8..795e0407 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -28,7 +28,7 @@ #define SQLPP_TYPE_TRAITS_H #include -#include +#include namespace sqlpp { @@ -40,8 +40,12 @@ namespace sqlpp template\ struct is_##name##_impl::value>::type>: std::true_type {};\ }\ + namespace tag\ + {\ + struct name{};\ + };\ template\ - struct is_##name##_t: detail::is_##name##_impl {}; + using is_##name##_t = detail::is_element_of; #define SQLPP_IS_COLUMN_TRAIT_GENERATOR(name) \ namespace detail\ @@ -77,13 +81,20 @@ namespace sqlpp struct connector_##name##_t: detail::connector_##name##_impl {}; SQLPP_IS_VALUE_TRAIT_GENERATOR(boolean); - SQLPP_IS_VALUE_TRAIT_GENERATOR(numeric); SQLPP_IS_VALUE_TRAIT_GENERATOR(integral); SQLPP_IS_VALUE_TRAIT_GENERATOR(floating_point); + template + using is_numeric_t = detail::any_t< + detail::is_element_of::value, + detail::is_element_of::value>; SQLPP_IS_VALUE_TRAIT_GENERATOR(text); - SQLPP_IS_VALUE_TRAIT_GENERATOR(value); SQLPP_IS_VALUE_TRAIT_GENERATOR(expression); SQLPP_IS_VALUE_TRAIT_GENERATOR(named_expression); + namespace tag + { + template + using named_expression_if = typename std::conditional::type; + } SQLPP_IS_VALUE_TRAIT_GENERATOR(multi_expression); SQLPP_IS_VALUE_TRAIT_GENERATOR(alias); SQLPP_IS_VALUE_TRAIT_GENERATOR(select_flag); @@ -94,41 +105,82 @@ namespace sqlpp SQLPP_IS_COLUMN_TRAIT_GENERATOR(can_be_null); SQLPP_IS_COLUMN_TRAIT_GENERATOR(trivial_value_is_null); - SQLPP_TYPE_TRAIT_GENERATOR(is_noop); - SQLPP_TYPE_TRAIT_GENERATOR(is_table); - SQLPP_TYPE_TRAIT_GENERATOR(is_join); - SQLPP_TYPE_TRAIT_GENERATOR(is_pseudo_table); - SQLPP_TYPE_TRAIT_GENERATOR(is_column); - SQLPP_TYPE_TRAIT_GENERATOR(is_select); - SQLPP_TYPE_TRAIT_GENERATOR(is_select_flag_list); - SQLPP_TYPE_TRAIT_GENERATOR(is_select_column_list); - SQLPP_TYPE_TRAIT_GENERATOR(is_from); - SQLPP_TYPE_TRAIT_GENERATOR(is_on); - SQLPP_TYPE_TRAIT_GENERATOR(is_dynamic); - SQLPP_TYPE_TRAIT_GENERATOR(is_where); - SQLPP_TYPE_TRAIT_GENERATOR(is_group_by); - SQLPP_TYPE_TRAIT_GENERATOR(is_having); - SQLPP_TYPE_TRAIT_GENERATOR(is_order_by); - SQLPP_TYPE_TRAIT_GENERATOR(is_limit); - SQLPP_TYPE_TRAIT_GENERATOR(is_offset); - SQLPP_TYPE_TRAIT_GENERATOR(is_using); - SQLPP_TYPE_TRAIT_GENERATOR(is_column_list); - SQLPP_TYPE_TRAIT_GENERATOR(is_multi_column); - SQLPP_TYPE_TRAIT_GENERATOR(is_value_list); - SQLPP_TYPE_TRAIT_GENERATOR(is_assignment); - SQLPP_TYPE_TRAIT_GENERATOR(is_update_list); - SQLPP_TYPE_TRAIT_GENERATOR(is_insert_list); - SQLPP_TYPE_TRAIT_GENERATOR(is_insert_value); - SQLPP_TYPE_TRAIT_GENERATOR(is_insert_value_list); - SQLPP_TYPE_TRAIT_GENERATOR(is_sort_order); + SQLPP_IS_VALUE_TRAIT_GENERATOR(noop); + SQLPP_IS_VALUE_TRAIT_GENERATOR(table); + SQLPP_IS_VALUE_TRAIT_GENERATOR(join); + SQLPP_IS_VALUE_TRAIT_GENERATOR(pseudo_table); + SQLPP_IS_VALUE_TRAIT_GENERATOR(column); + SQLPP_IS_VALUE_TRAIT_GENERATOR(select); + SQLPP_IS_VALUE_TRAIT_GENERATOR(select_flag_list); + SQLPP_IS_VALUE_TRAIT_GENERATOR(select_column_list); + SQLPP_IS_VALUE_TRAIT_GENERATOR(from); + SQLPP_IS_VALUE_TRAIT_GENERATOR(on); + SQLPP_IS_VALUE_TRAIT_GENERATOR(dynamic); + SQLPP_IS_VALUE_TRAIT_GENERATOR(where); + SQLPP_IS_VALUE_TRAIT_GENERATOR(group_by); + SQLPP_IS_VALUE_TRAIT_GENERATOR(having); + SQLPP_IS_VALUE_TRAIT_GENERATOR(order_by); + SQLPP_IS_VALUE_TRAIT_GENERATOR(limit); + SQLPP_IS_VALUE_TRAIT_GENERATOR(offset); + SQLPP_IS_VALUE_TRAIT_GENERATOR(using_); + SQLPP_IS_VALUE_TRAIT_GENERATOR(column_list); + SQLPP_IS_VALUE_TRAIT_GENERATOR(multi_column); + SQLPP_IS_VALUE_TRAIT_GENERATOR(value_list); + SQLPP_IS_VALUE_TRAIT_GENERATOR(assignment); + SQLPP_IS_VALUE_TRAIT_GENERATOR(update_list); + SQLPP_IS_VALUE_TRAIT_GENERATOR(insert_list); + SQLPP_IS_VALUE_TRAIT_GENERATOR(insert_value); + SQLPP_IS_VALUE_TRAIT_GENERATOR(insert_value_list); + SQLPP_IS_VALUE_TRAIT_GENERATOR(sort_order); + SQLPP_IS_VALUE_TRAIT_GENERATOR(parameter); + SQLPP_TYPE_TRAIT_GENERATOR(requires_braces); - SQLPP_TYPE_TRAIT_GENERATOR(is_parameter); SQLPP_CONNECTOR_TRAIT_GENERATOR(null_result_is_trivial_value); SQLPP_CONNECTOR_TRAIT_GENERATOR(assert_result_validity); template class IsTag> using copy_type_trait = typename std::conditional::value, std::true_type, std::false_type>::type; + + template + struct make_traits + { + using _value_type = ValueType; + using _tags = detail::make_type_set_t; + }; + template + struct make_recursive_traits + { + }; + + namespace detail + { + template + struct value_type_of_impl + { + using type = typename T::_traits::_value_type; + }; + + template + struct required_table_of_impl + { + using type = typename T::_recursive_traits::_required_tables; + }; + + template + struct provided_table_of_impl + { + using type = typename T::_recursive_traits::_provided_tables; + }; + } + template + using value_type_of = typename detail::value_type_of_impl::type; + + template + using required_tables_of = typename detail::required_table_of_impl::type; + + template + using provided_tables_of = typename detail::provided_table_of_impl::type; } #endif diff --git a/include/sqlpp11/vendor/assignment.h b/include/sqlpp11/vendor/assignment.h index 321a1b11..8026a3e1 100644 --- a/include/sqlpp11/vendor/assignment.h +++ b/include/sqlpp11/vendor/assignment.h @@ -59,26 +59,21 @@ namespace sqlpp template bool is_trivial(const T& t) { - return is_trivial_t::_(t); + return is_trivial_t>::_(t); } template struct assignment_t { - struct _traits - { - using _is_assignment = std::true_type; - using value_type = no_value; - }; - - using _recursive_traits = make_recursive_traits_t; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; using _column_t = Lhs; using _value_t = Lhs; static_assert(can_be_null_t<_column_t>::value ? true : not std::is_same<_value_t, null_t>::value, "column must not be null"); - assignment_t(_column_t lhs, value_type rhs): + assignment_t(_column_t lhs, _value_t rhs): _lhs(lhs), _rhs(rhs) {} @@ -101,7 +96,7 @@ namespace sqlpp static Context& _(const T& t, Context& context) { if ((trivial_value_is_null_t::value - and is_trivial_t::_(t._rhs)) + and is_trivial_t>::_(t._rhs)) or (std::is_same::value)) { serialize(simple_column(t._lhs), context); @@ -120,15 +115,9 @@ namespace sqlpp template struct assignment_t> { - struct _traits - { - using _is_assignment = std::true_type; - using value_type = no_value; - }; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; - using _recursive_traits = make_recursive_traits_t; - - using _is_assignment = std::true_type; using _column_t = Lhs; using _value_t = tvin_t; diff --git a/include/sqlpp11/vendor/concat.h b/include/sqlpp11/vendor/concat.h index 7e1f049f..a5daa2d3 100644 --- a/include/sqlpp11/vendor/concat.h +++ b/include/sqlpp11/vendor/concat.h @@ -35,19 +35,15 @@ namespace sqlpp { namespace vendor { + // FIXME: Remove First, inherit from text_t template - struct concat_t: public First::_value_type::template expression_operators> + struct concat_t: public value_type_of::template expression_operators> { + using _traits = make_traits, ::sqlpp::tag::expression, ::sqlpp::tag::named_expression>; + using _recursive_traits = make_recursive_traits; + static_assert(sizeof...(Args) > 0, "concat requires two arguments at least"); static_assert(sqlpp::detail::all_t::value, is_text_t::value...>::value, "at least one non-text argument detected in concat()"); - using _provided_tables = detail::type_set<>; - using _required_tables = typename ::sqlpp::detail::make_joined_set::type; - - struct _value_type: public First::_value_type::_base_value_type - { - using _is_named_expression = std::true_type; - }; - struct _name_t { static constexpr const char* _get_name() { return "CONCAT"; } diff --git a/include/sqlpp11/vendor/expression.h b/include/sqlpp11/vendor/expression.h index 4cc560d1..b3c6075a 100644 --- a/include/sqlpp11/vendor/expression.h +++ b/include/sqlpp11/vendor/expression.h @@ -42,10 +42,8 @@ namespace sqlpp template struct binary_expression_t: public ::sqlpp::detail::boolean::template expression_operators> { - using _value_type = ::sqlpp::detail::boolean; - using _parameter_tuple_t = std::tuple; - using _provided_tables = detail::type_set<>; - using _required_tables = typename ::sqlpp::detail::make_joined_set::type; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; binary_expression_t(Lhs lhs, Rhs rhs): _lhs(lhs), @@ -88,10 +86,8 @@ namespace sqlpp template struct binary_expression_t: public ::sqlpp::detail::boolean::template expression_operators> { - using _value_type = ::sqlpp::detail::boolean; - using _parameter_tuple_t = std::tuple; - using _provided_tables = detail::type_set<>; - using _required_tables = typename ::sqlpp::detail::make_joined_set::type; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; binary_expression_t(Lhs lhs, Rhs rhs): _lhs(lhs), @@ -134,10 +130,8 @@ namespace sqlpp template struct unary_expression_t: public ::sqlpp::detail::boolean::template expression_operators> { - using _value_type = ::sqlpp::detail::boolean; - using _parameter_tuple_t = std::tuple; - using _provided_tables = detail::type_set<>; - using _required_tables = typename Rhs::_required_tables; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; unary_expression_t(Rhs rhs): _rhs(rhs) @@ -168,16 +162,12 @@ namespace sqlpp }; template - struct binary_expression_t: public O::_value_type::template expression_operators> + struct binary_expression_t: public value_type_of::template expression_operators> { - using _lhs_t = Lhs; - using _rhs_t = Rhs; - using _value_type = typename O::_value_type; - using _parameter_tuple_t = std::tuple<_lhs_t, _rhs_t>; - using _provided_tables = detail::type_set<>; - using _required_tables = typename ::sqlpp::detail::make_joined_set::type; + using _traits = make_traits, sqlpp::tag::expression>; + using _recursive_traits = make_recursive_traits; - binary_expression_t(_lhs_t lhs, _rhs_t rhs): + binary_expression_t(Lhs lhs, Rhs rhs): _lhs(lhs), _rhs(rhs) {} @@ -188,8 +178,8 @@ namespace sqlpp binary_expression_t& operator=(binary_expression_t&&) = default; ~binary_expression_t() = default; - _lhs_t _lhs; - _rhs_t _rhs; + Lhs _lhs; + Rhs _rhs; }; template @@ -211,10 +201,8 @@ namespace sqlpp template struct unary_expression_t: public O::_value_type::template expression_operators> { - using _value_type = typename O::_value_type; - using _parameter_tuple_t = std::tuple; - using _provided_tables = detail::type_set<>; - using _required_tables = typename Rhs::_required_tables; + using _traits = make_traits, sqlpp::tag::expression>; + using _recursive_traits = make_recursive_traits; unary_expression_t(Rhs rhs): _rhs(rhs) diff --git a/include/sqlpp11/vendor/extra_tables.h b/include/sqlpp11/vendor/extra_tables.h index b3574405..04e3b4d8 100644 --- a/include/sqlpp11/vendor/extra_tables.h +++ b/include/sqlpp11/vendor/extra_tables.h @@ -39,18 +39,15 @@ namespace sqlpp template struct extra_tables_t { - using _is_extra_tables = std::true_type; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + + // FIXME: extra_tables must not require tables! static_assert(sizeof...(Tables), "at least one table or join argument required in extra_tables()"); - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in extra_tables()"); - static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a table or join in extra_tables()"); - using _provided_tables = ::sqlpp::detail::make_joined_set_t; - using _required_tables = ::sqlpp::detail::make_joined_set_t; - - extra_tables_t() {} @@ -68,9 +65,8 @@ namespace sqlpp struct no_extra_tables_t { - using _is_noop = std::true_type; - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; template struct _methods_t diff --git a/include/sqlpp11/vendor/field.h b/include/sqlpp11/vendor/field.h index 7cd6ec62..2e0293bb 100644 --- a/include/sqlpp11/vendor/field.h +++ b/include/sqlpp11/vendor/field.h @@ -52,7 +52,7 @@ namespace sqlpp struct make_field_t_impl { using type = field_t, trivial_value_is_null_t::value>; }; diff --git a/include/sqlpp11/vendor/from.h b/include/sqlpp11/vendor/from.h index 7107868b..7a016cde 100644 --- a/include/sqlpp11/vendor/from.h +++ b/include/sqlpp11/vendor/from.h @@ -41,9 +41,9 @@ namespace sqlpp template struct from_t { - using _is_from = std::true_type; - using _required_tables = ::sqlpp::detail::make_joined_set_t; - using _provided_tables = ::sqlpp::detail::make_joined_set_t; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; static_assert(_is_dynamic::value or sizeof...(Tables), "at least one table or join argument required in from()"); @@ -53,7 +53,7 @@ namespace sqlpp static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a table or join in from()"); - static_assert(_required_tables::size::value == 0, "at least one table depends on another table"); + static_assert(required_tables_of::size::value == 0, "at least one table depends on another table"); from_t(Tables... tables): @@ -97,9 +97,8 @@ namespace sqlpp struct no_from_t { - using _is_noop = std::true_type; - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; template struct _methods_t diff --git a/include/sqlpp11/vendor/group_by.h b/include/sqlpp11/vendor/group_by.h index 12ca32c7..ab023f4a 100644 --- a/include/sqlpp11/vendor/group_by.h +++ b/include/sqlpp11/vendor/group_by.h @@ -43,13 +43,10 @@ namespace sqlpp template struct group_by_t { - using _is_group_by = std::true_type; - using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - using _parameter_tuple_t = std::tuple; - using _parameter_list_t = typename make_parameter_list_t<_parameter_tuple_t>::type; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; - using _provided_tables = detail::type_set<>; - using _required_tables = typename ::sqlpp::detail::make_joined_set::type; + using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression (e.g. a column) required in group_by()"); @@ -100,15 +97,14 @@ namespace sqlpp }; const group_by_t& _group_by() const { return *this; } - _parameter_tuple_t _expressions; + std::tuple _expressions; vendor::interpretable_list_t _dynamic_expressions; }; struct no_group_by_t { - using _is_noop = std::true_type; - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; template struct _methods_t diff --git a/include/sqlpp11/vendor/having.h b/include/sqlpp11/vendor/having.h index 093166e1..8c4708e6 100644 --- a/include/sqlpp11/vendor/having.h +++ b/include/sqlpp11/vendor/having.h @@ -42,18 +42,14 @@ namespace sqlpp template struct having_t { - using _is_having = std::true_type; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - using _parameter_tuple_t = std::tuple; static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression argument required in having()"); static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an expression in having()"); - using _parameter_list_t = typename make_parameter_list_t<_parameter_tuple_t>::type; - - using _provided_tables = detail::type_set<>; - using _required_tables = typename ::sqlpp::detail::make_joined_set::type; - having_t(Expressions... expressions): _expressions(expressions...) {} @@ -96,15 +92,14 @@ namespace sqlpp void _add_having_impl(Expression expression, const std::false_type&); }; - _parameter_tuple_t _expressions; + std::tuple _expressions; vendor::interpretable_list_t _dynamic_expressions; }; struct no_having_t { - using _is_noop = std::true_type; - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; template struct _methods_t diff --git a/include/sqlpp11/vendor/in.h b/include/sqlpp11/vendor/in.h index 0059c918..54fec7b7 100644 --- a/include/sqlpp11/vendor/in.h +++ b/include/sqlpp11/vendor/in.h @@ -39,14 +39,12 @@ namespace sqlpp template struct in_t: public boolean::template expression_operators> { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + static constexpr bool _inverted = not NotInverted; static_assert(sizeof...(Args) > 0, "in() requires at least one argument"); - struct _value_type: public boolean - { - using _is_named_expression = std::true_type; - }; - struct _name_t { static constexpr const char* _get_name() { return _inverted ? "NOT IN" : "IN"; } @@ -56,8 +54,6 @@ namespace sqlpp T in; }; }; - using _provided_tables = detail::type_set<>; - using _required_tables = typename ::sqlpp::detail::make_joined_set::type; in_t(Operand operand, Args... args): _operand(operand), diff --git a/include/sqlpp11/vendor/is_null.h b/include/sqlpp11/vendor/is_null.h index 73b2fdb3..d47d5aa7 100644 --- a/include/sqlpp11/vendor/is_null.h +++ b/include/sqlpp11/vendor/is_null.h @@ -38,9 +38,10 @@ namespace sqlpp template struct is_null_t: public boolean::template expression_operators> { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + static constexpr bool _inverted = not NotInverted; - using _provided_tables = detail::type_set<>; - using _required_tables = typename Operand::_required_tables; struct _value_type: public boolean { diff --git a/include/sqlpp11/vendor/like.h b/include/sqlpp11/vendor/like.h index e1b65e07..fd782853 100644 --- a/include/sqlpp11/vendor/like.h +++ b/include/sqlpp11/vendor/like.h @@ -38,16 +38,11 @@ namespace sqlpp template struct like_t: public boolean::template expression_operators> { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + static_assert(is_text_t::value, "Operand for like() has to be a text"); static_assert(is_text_t::value, "Pattern for like() has to be a text"); - using _parameter_tuple_t = std::tuple; - using _provided_tables = detail::type_set<>; - using _required_tables = typename ::sqlpp::detail::make_joined_set::type; - - struct _value_type: public boolean - { - using _is_named_expression = std::true_type; - }; struct _name_t { diff --git a/include/sqlpp11/vendor/value_type.h b/include/sqlpp11/vendor/value_type.h index 06738c36..2f9b5188 100644 --- a/include/sqlpp11/vendor/value_type.h +++ b/include/sqlpp11/vendor/value_type.h @@ -35,7 +35,7 @@ namespace sqlpp namespace vendor { template - using value_type_t = typename wrap_operand::type::_value_type; + using value_type_t = value_type_of>; } } #endif diff --git a/include/sqlpp11/vendor/wrap_operand.h b/include/sqlpp11/vendor/wrap_operand.h index 78925d50..9012aa98 100644 --- a/include/sqlpp11/vendor/wrap_operand.h +++ b/include/sqlpp11/vendor/wrap_operand.h @@ -29,7 +29,7 @@ #include #include -#include +#include namespace sqlpp { @@ -45,11 +45,10 @@ namespace sqlpp { struct boolean_operand { - static constexpr bool _is_expression = true; - using _value_type = sqlpp::detail::boolean; + using _traits = make_traits<::sqlpp::detail::boolean, ::sqlpp::tag::expression>; + using _recursive_traits = make_recursive_traits<>; + using _value_t = bool; - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; boolean_operand(): _t{} @@ -84,11 +83,10 @@ namespace sqlpp struct integral_operand { - static constexpr bool _is_expression = true; - using _value_type = ::sqlpp::detail::integral; + using _traits = make_traits<::sqlpp::detail::integral, ::sqlpp::tag::expression>; + using _recursive_traits = make_recursive_traits<>; + using _value_t = int64_t; - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; integral_operand(): _t{} @@ -124,11 +122,10 @@ namespace sqlpp struct floating_point_operand { - static constexpr bool _is_expression = true; - using _value_type = ::sqlpp::detail::floating_point; + using _traits = make_traits<::sqlpp::detail::floating_point, ::sqlpp::tag::expression>; + using _recursive_traits = make_recursive_traits<>; + using _value_t = double; - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; floating_point_operand(): _t{} @@ -163,11 +160,10 @@ namespace sqlpp struct text_operand { - static constexpr bool _is_expression = true; - using _value_type = ::sqlpp::detail::text; + using _traits = make_traits<::sqlpp::detail::text, ::sqlpp::tag::expression>; + using _recursive_traits = make_recursive_traits<>; + using _value_t = std::string; - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; text_operand(): _t{} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 350602ec..71771eee 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,14 +6,14 @@ macro (build_and_run arg) add_test(${arg} ${arg}) endmacro () -build_and_run(InterpretTest) -build_and_run(InsertTest) -build_and_run(RemoveTest) -build_and_run(UpdateTest) -build_and_run(SelectTest) -build_and_run(SelectTypeTest) +#build_and_run(InterpretTest) +#build_and_run(InsertTest) +#build_and_run(RemoveTest) +#build_and_run(UpdateTest) +#build_and_run(SelectTest) +#build_and_run(SelectTypeTest) build_and_run(FunctionTest) -build_and_run(PreparedTest) +#build_and_run(PreparedTest) find_package(PythonInterp REQUIRED) diff --git a/tests/FunctionTest.cpp b/tests/FunctionTest.cpp index 04aa8f52..6d70f246 100644 --- a/tests/FunctionTest.cpp +++ b/tests/FunctionTest.cpp @@ -26,7 +26,7 @@ #include "Sample.h" #include "MockDb.h" #include -#include +//#include #include #include @@ -171,6 +171,7 @@ int main() // SUB_SELECT_FUNCTIONS // -------------------- +#if 0 // Test exists { using TI = decltype(exists(select(t.alpha).from(t))); @@ -232,6 +233,7 @@ int main() static_assert(not sqlpp::is_floating_point_t::value, "type requirement"); static_assert(sqlpp::is_text_t::value, "type requirement"); } +#endif // NUMERIC FUNCTIONS // ----------------- From 5f4a88c7cee20c4e3960e606a1ea6787b47dc048 Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 16 May 2014 09:18:08 +0200 Subject: [PATCH 03/65] Function tests compile again --- include/sqlpp11/any.h | 1 + include/sqlpp11/select.h | 31 +++++++++------- include/sqlpp11/type_traits.h | 26 ++++++++------ include/sqlpp11/vendor/assignment.h | 4 +-- include/sqlpp11/vendor/expression.h | 6 ++-- include/sqlpp11/vendor/expression_fwd.h | 34 +++++++++--------- include/sqlpp11/vendor/extra_tables.h | 4 +-- include/sqlpp11/vendor/field.h | 2 +- include/sqlpp11/vendor/from.h | 4 +-- include/sqlpp11/vendor/group_by.h | 6 ++-- include/sqlpp11/vendor/having.h | 4 +-- include/sqlpp11/vendor/limit.h | 18 ++++------ include/sqlpp11/vendor/offset.h | 17 ++++----- include/sqlpp11/vendor/order_by.h | 16 ++++----- include/sqlpp11/vendor/select_column_list.h | 39 +++++++++------------ include/sqlpp11/vendor/select_flag_list.h | 15 ++++---- include/sqlpp11/vendor/where.h | 23 +++++------- tests/FunctionTest.cpp | 7 ++-- 18 files changed, 120 insertions(+), 137 deletions(-) diff --git a/include/sqlpp11/any.h b/include/sqlpp11/any.h index f7d8ec0c..b4897b6a 100644 --- a/include/sqlpp11/any.h +++ b/include/sqlpp11/any.h @@ -87,6 +87,7 @@ namespace sqlpp { static_assert(is_select_t>::value, "any() requires a select expression as argument"); static_assert(is_expression_t>::value, "any() requires a single column select expression as argument"); + // FIXME: can we accept non-values like NULL here? return { t }; } diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index fd1b3a59..66eafd90 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -112,27 +112,27 @@ namespace sqlpp static_assert(is_noop_t::value or sqlpp::is_select_column_list_t::value, "column list of select is neither naught nor a valid column list"); static_assert(is_noop_t::value or sqlpp::is_from_t::value, "from() part of select is neither naught nor a valid from()"); - using _known_tables = detail::make_joined_set_t; + using _known_tables = detail::make_joined_set_t, provided_tables_of<_extra_tables_t>>; // FIXME, use provided_tables_of; template - using _no_unknown_tables = detail::is_subset_of; + using _no_unknown_tables = detail::is_subset_of, _known_tables>; using _required_tables = detail::make_joined_set_t< - typename _flag_list_t::_table_set, - typename _column_list_t::_table_set, - typename _where_t::_table_set, - typename _group_by_t::_table_set, - typename _having_t::_table_set, - typename _order_by_t::_table_set, - typename _limit_t::_table_set, - typename _offset_t::_table_set + required_tables_of<_flag_list_t>, + required_tables_of<_column_list_t>, + required_tables_of<_where_t>, + required_tables_of<_group_by_t>, + required_tables_of<_having_t>, + required_tables_of<_order_by_t>, + required_tables_of<_limit_t>, + required_tables_of<_offset_t> >; // The tables not covered by the from. using _table_set = detail::make_difference_set_t< _required_tables, - typename _from_t::_table_set // Hint: extra_tables_t is not used here because it is just a helper for dynamic .add_*() methods and should not change the structural integrity + provided_tables_of<_from_t> // Hint: extra_tables_t is not used here because it is just a helper for dynamic .add_*() methods and should not change the structural integrity >; // A select can be used as a pseudo table if @@ -145,10 +145,12 @@ namespace sqlpp >::type; using _value_type = typename std::conditional< - is_select_column_list_t<_column_list_t>::value and is_subset_of::value, - typename ColumnList::_value_type, + is_select_column_list_t<_column_list_t>::value and is_subset_of, provided_tables_of<_from_t>>::value, + value_type_of<_column_list_t>, no_value_t // If something is selected that requires a table, then we require a from for this to be a value >::type; + + using _traits = make_traits<_value_type>; }; } @@ -160,6 +162,9 @@ namespace sqlpp public detail::select_policies_t::_value_type::template expression_operators>, public detail::select_policies_t::_methods_t { + using _traits = make_traits>, ::sqlpp::tag::select>; + using _recursive_traits = make_recursive_traits<>; // FIXME + using _policies_t = typename detail::select_policies_t; using _database_t = typename _policies_t::_database_t; using _flag_list_t = typename _policies_t::_flag_list_t; diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index 795e0407..fe2c901d 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -114,6 +114,7 @@ namespace sqlpp SQLPP_IS_VALUE_TRAIT_GENERATOR(select_flag_list); SQLPP_IS_VALUE_TRAIT_GENERATOR(select_column_list); SQLPP_IS_VALUE_TRAIT_GENERATOR(from); + SQLPP_IS_VALUE_TRAIT_GENERATOR(extra_tables); SQLPP_IS_VALUE_TRAIT_GENERATOR(on); SQLPP_IS_VALUE_TRAIT_GENERATOR(dynamic); SQLPP_IS_VALUE_TRAIT_GENERATOR(where); @@ -142,17 +143,6 @@ namespace sqlpp template class IsTag> using copy_type_trait = typename std::conditional::value, std::true_type, std::false_type>::type; - template - struct make_traits - { - using _value_type = ValueType; - using _tags = detail::make_type_set_t; - }; - template - struct make_recursive_traits - { - }; - namespace detail { template @@ -181,6 +171,20 @@ namespace sqlpp template using provided_tables_of = typename detail::provided_table_of_impl::type; + + template + struct make_traits + { + using _value_type = ValueType; + using _tags = detail::make_type_set_t; + }; + template + struct make_recursive_traits + { + using _required_tables = detail::make_joined_set_t...>; + using _provided_tables = detail::make_joined_set_t...>; + }; + } #endif diff --git a/include/sqlpp11/vendor/assignment.h b/include/sqlpp11/vendor/assignment.h index 8026a3e1..52ad3c75 100644 --- a/include/sqlpp11/vendor/assignment.h +++ b/include/sqlpp11/vendor/assignment.h @@ -65,7 +65,7 @@ namespace sqlpp template struct assignment_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; using _column_t = Lhs; @@ -115,7 +115,7 @@ namespace sqlpp template struct assignment_t> { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; using _column_t = Lhs; diff --git a/include/sqlpp11/vendor/expression.h b/include/sqlpp11/vendor/expression.h index b3c6075a..03c89cba 100644 --- a/include/sqlpp11/vendor/expression.h +++ b/include/sqlpp11/vendor/expression.h @@ -40,7 +40,7 @@ namespace sqlpp namespace vendor { template - struct binary_expression_t: public ::sqlpp::detail::boolean::template expression_operators> + struct binary_expression_t: public ::sqlpp::detail::boolean::template expression_operators> { using _traits = make_traits; using _recursive_traits = make_recursive_traits; @@ -84,7 +84,7 @@ namespace sqlpp }; template - struct binary_expression_t: public ::sqlpp::detail::boolean::template expression_operators> + struct binary_expression_t: public ::sqlpp::detail::boolean::template expression_operators> { using _traits = make_traits; using _recursive_traits = make_recursive_traits; @@ -128,7 +128,7 @@ namespace sqlpp }; template - struct unary_expression_t: public ::sqlpp::detail::boolean::template expression_operators> + struct unary_expression_t: public ::sqlpp::detail::boolean::template expression_operators> { using _traits = make_traits; using _recursive_traits = make_recursive_traits; diff --git a/include/sqlpp11/vendor/expression_fwd.h b/include/sqlpp11/vendor/expression_fwd.h index 66b446c5..b6529e8b 100644 --- a/include/sqlpp11/vendor/expression_fwd.h +++ b/include/sqlpp11/vendor/expression_fwd.h @@ -31,7 +31,7 @@ namespace sqlpp { namespace vendor { - namespace tag + namespace op { struct less { @@ -139,52 +139,52 @@ namespace sqlpp struct unary_expression_t; template - using less_than_t = binary_expression_t; + using less_than_t = binary_expression_t; template - using less_equal_t = binary_expression_t; + using less_equal_t = binary_expression_t; template - using equal_to_t = binary_expression_t; + using equal_to_t = binary_expression_t; template - using not_equal_to_t = binary_expression_t; + using not_equal_to_t = binary_expression_t; template - using greater_than_t = binary_expression_t; + using greater_than_t = binary_expression_t; template - using greater_equal_t = binary_expression_t; + using greater_equal_t = binary_expression_t; template - using logical_and_t = binary_expression_t; + using logical_and_t = binary_expression_t; template - using logical_or_t = binary_expression_t; + using logical_or_t = binary_expression_t; template - using plus_t = binary_expression_t, Rhs>; + using plus_t = binary_expression_t, Rhs>; template - using minus_t = binary_expression_t, Rhs>; + using minus_t = binary_expression_t, Rhs>; template - using multiplies_t = binary_expression_t, Rhs>; + using multiplies_t = binary_expression_t, Rhs>; template - using divides_t = binary_expression_t; + using divides_t = binary_expression_t; template - using modulus_t = binary_expression_t; + using modulus_t = binary_expression_t; template - using logical_not_t = unary_expression_t; + using logical_not_t = unary_expression_t; template - using unary_plus_t = unary_expression_t, Rhs>; + using unary_plus_t = unary_expression_t, Rhs>; template - using unary_minus_t = unary_expression_t, Rhs>; + using unary_minus_t = unary_expression_t, Rhs>; } } diff --git a/include/sqlpp11/vendor/extra_tables.h b/include/sqlpp11/vendor/extra_tables.h index 04e3b4d8..36fb431a 100644 --- a/include/sqlpp11/vendor/extra_tables.h +++ b/include/sqlpp11/vendor/extra_tables.h @@ -39,7 +39,7 @@ namespace sqlpp template struct extra_tables_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; // FIXME: extra_tables must not require tables! @@ -65,7 +65,7 @@ namespace sqlpp struct no_extra_tables_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; template diff --git a/include/sqlpp11/vendor/field.h b/include/sqlpp11/vendor/field.h index 2e0293bb..caf93c78 100644 --- a/include/sqlpp11/vendor/field.h +++ b/include/sqlpp11/vendor/field.h @@ -52,7 +52,7 @@ namespace sqlpp struct make_field_t_impl { using type = field_t, + value_type_of, trivial_value_is_null_t::value>; }; diff --git a/include/sqlpp11/vendor/from.h b/include/sqlpp11/vendor/from.h index 7a016cde..3e30ea33 100644 --- a/include/sqlpp11/vendor/from.h +++ b/include/sqlpp11/vendor/from.h @@ -41,7 +41,7 @@ namespace sqlpp template struct from_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; @@ -97,7 +97,7 @@ namespace sqlpp struct no_from_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; template diff --git a/include/sqlpp11/vendor/group_by.h b/include/sqlpp11/vendor/group_by.h index ab023f4a..51fb4f11 100644 --- a/include/sqlpp11/vendor/group_by.h +++ b/include/sqlpp11/vendor/group_by.h @@ -43,7 +43,7 @@ namespace sqlpp template struct group_by_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; @@ -97,13 +97,13 @@ namespace sqlpp }; const group_by_t& _group_by() const { return *this; } - std::tuple _expressions; + std::tuple _expressions; vendor::interpretable_list_t _dynamic_expressions; }; struct no_group_by_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; template diff --git a/include/sqlpp11/vendor/having.h b/include/sqlpp11/vendor/having.h index 8c4708e6..fa15285f 100644 --- a/include/sqlpp11/vendor/having.h +++ b/include/sqlpp11/vendor/having.h @@ -42,7 +42,7 @@ namespace sqlpp template struct having_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; @@ -98,7 +98,7 @@ namespace sqlpp struct no_having_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; template diff --git a/include/sqlpp11/vendor/limit.h b/include/sqlpp11/vendor/limit.h index 15d72af1..62e94916 100644 --- a/include/sqlpp11/vendor/limit.h +++ b/include/sqlpp11/vendor/limit.h @@ -39,11 +39,10 @@ namespace sqlpp template struct limit_t { - using _is_limit = std::true_type; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + static_assert(is_integral_t::value, "limit requires an integral value or integral parameter"); - // FIXME: Is this really always empty? - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; limit_t(Limit value): _value(value) @@ -66,10 +65,8 @@ namespace sqlpp template struct dynamic_limit_t { - using _is_limit = std::true_type; - using _is_dynamic = std::true_type; - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; dynamic_limit_t(): _value(noop()) @@ -108,9 +105,8 @@ namespace sqlpp struct no_limit_t { - using _is_noop = std::true_type; - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; template struct _methods_t diff --git a/include/sqlpp11/vendor/offset.h b/include/sqlpp11/vendor/offset.h index 2a873a50..83cacd95 100644 --- a/include/sqlpp11/vendor/offset.h +++ b/include/sqlpp11/vendor/offset.h @@ -39,9 +39,9 @@ namespace sqlpp template struct offset_t { - using _is_offset = std::true_type; - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + static_assert(is_integral_t::value, "offset requires an integral value or integral parameter"); offset_t(Offset value): @@ -65,10 +65,8 @@ namespace sqlpp template struct dynamic_offset_t { - using _is_offset = std::true_type; - using _is_dynamic = std::true_type; - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; dynamic_offset_t(): _value(noop()) @@ -107,9 +105,8 @@ namespace sqlpp struct no_offset_t { - using _is_noop = std::true_type; - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; template struct _methods_t diff --git a/include/sqlpp11/vendor/order_by.h b/include/sqlpp11/vendor/order_by.h index 80d7f891..a6d4a5ad 100644 --- a/include/sqlpp11/vendor/order_by.h +++ b/include/sqlpp11/vendor/order_by.h @@ -42,13 +42,10 @@ namespace sqlpp template struct order_by_t { - using _is_order_by = std::true_type; - using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - using _parameter_tuple_t = std::tuple; - using _parameter_list_t = typename make_parameter_list_t<_parameter_tuple_t>::type; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; - using _provided_tables = detail::type_set<>; - using _required_tables = typename ::sqlpp::detail::make_joined_set::type; + using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one sort-order expression required in order_by()"); @@ -98,15 +95,14 @@ namespace sqlpp void _add_order_by_impl(Expression expression, const std::false_type&); }; - _parameter_tuple_t _expressions; + std::tuple _expressions; vendor::interpretable_list_t _dynamic_expressions; }; struct no_order_by_t { - using _is_noop = std::true_type; - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; template struct _methods_t diff --git a/include/sqlpp11/vendor/select_column_list.h b/include/sqlpp11/vendor/select_column_list.h index 955b4df8..1f160d16 100644 --- a/include/sqlpp11/vendor/select_column_list.h +++ b/include/sqlpp11/vendor/select_column_list.h @@ -47,14 +47,14 @@ namespace sqlpp template struct get_first_argument_if_unique { - using _value_type = no_value_t; + using _traits = make_traits; struct _name_t {}; }; template struct get_first_argument_if_unique { - using _value_type = typename T::_value_type; + using _traits = make_traits, tag::select_column_list, tag::expression, tag::named_expression>; using _name_t = typename T::_name_t; }; } @@ -132,13 +132,13 @@ namespace sqlpp template struct select_column_list_t { - using _is_select_column_list = std::true_type; - using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - using _parameter_tuple_t = std::tuple; - using size = std::tuple_size<_parameter_tuple_t>; + // get_first_argument_if_unique is kind of ugly + using _traits = typename ::sqlpp::detail::get_first_argument_if_unique::_traits; + using _recursive_traits = make_recursive_traits; - using _provided_tables = detail::type_set<>; - using _required_tables = sqlpp::detail::make_joined_set_t; + using _name_t = typename ::sqlpp::detail::get_first_argument_if_unique::_name_t; + + using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected"); @@ -149,13 +149,7 @@ namespace sqlpp static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate name detected"); struct _column_type {}; - struct _value_type: ::sqlpp::detail::get_first_argument_if_unique::_value_type - { - using _is_expression = typename std::conditional::type; - using _is_named_expression = typename std::conditional::type; - using _is_alias = std::false_type; - }; - using _name_t = typename ::sqlpp::detail::get_first_argument_if_unique::_name_t; + template using _result_row_t = typename std::conditional<_is_dynamic::value, @@ -186,7 +180,7 @@ namespace sqlpp static constexpr size_t static_size() { - return size::value; + return sizeof...(Columns); } template @@ -228,7 +222,7 @@ namespace sqlpp const select_column_list_t& _column_list() const { return *this; } - _parameter_tuple_t _columns; + std::tuple _columns; dynamic_select_column_list _dynamic_columns; }; } @@ -245,13 +239,12 @@ namespace sqlpp { struct no_select_column_list_t { - using _is_noop = std::true_type; - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; + 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 {}; template @@ -293,10 +286,10 @@ namespace sqlpp static Context& _(const T& t, Context& context) { // check for at least one expression - static_assert(T::_is_dynamic::value or T::size::value, "at least one select expression required"); + static_assert(T::_is_dynamic::value or sizeof...(Columns), "at least one select expression required"); interpret_tuple(t._columns, ',', context); - if (T::size::value and not t._dynamic_columns.empty()) + if (sizeof...(Columns) and not t._dynamic_columns.empty()) context << ','; serialize(t._dynamic_columns, context); return context; diff --git a/include/sqlpp11/vendor/select_flag_list.h b/include/sqlpp11/vendor/select_flag_list.h index 889debce..85303440 100644 --- a/include/sqlpp11/vendor/select_flag_list.h +++ b/include/sqlpp11/vendor/select_flag_list.h @@ -42,12 +42,10 @@ namespace sqlpp template struct select_flag_list_t { - using _is_select_flag_list = std::true_type; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - using _parameter_tuple_t = std::tuple; - using size = std::tuple_size<_parameter_tuple_t>; - using _provided_tables = detail::type_set<>; - using _required_tables = typename ::sqlpp::detail::make_joined_set::type; static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in select flag list"); @@ -96,15 +94,14 @@ namespace sqlpp }; const select_flag_list_t& _flag_list() const { return *this; } - _parameter_tuple_t _flags; + std::tuple _flags; vendor::interpretable_list_t _dynamic_flags; }; struct no_select_flag_list_t { - using _is_noop = std::true_type; - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; template struct _methods_t diff --git a/include/sqlpp11/vendor/where.h b/include/sqlpp11/vendor/where.h index 03d70ec6..01557cdd 100644 --- a/include/sqlpp11/vendor/where.h +++ b/include/sqlpp11/vendor/where.h @@ -42,19 +42,15 @@ namespace sqlpp template struct where_t { - using _is_where = std::true_type; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - using _parameter_tuple_t = std::tuple; static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression argument required in where()"); static_assert(sqlpp::detail::none_t::value...>::value, "at least one argument is an assignment in where()"); static_assert(sqlpp::detail::all_t::value...>::value, "at least one argument is not valid expression in where()"); - using _parameter_list_t = typename make_parameter_list_t<_parameter_tuple_t>::type; - - using _provided_tables = detail::type_set<>; - using _required_tables = typename ::sqlpp::detail::make_joined_set::type; - where_t(Expressions... expressions): _expressions(expressions...) {} @@ -97,17 +93,15 @@ namespace sqlpp void _add_where_impl(Expression expression, const std::false_type&); }; - _parameter_tuple_t _expressions; + std::tuple _expressions; vendor::interpretable_list_t _dynamic_expressions; }; template<> struct where_t { - using _is_where = std::true_type; - using _is_dynamic = std::false_type; - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; where_t(bool condition): _condition(condition) @@ -129,9 +123,8 @@ namespace sqlpp struct no_where_t { - using _is_noop = std::true_type; - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; template struct _methods_t diff --git a/tests/FunctionTest.cpp b/tests/FunctionTest.cpp index 6d70f246..bc02891b 100644 --- a/tests/FunctionTest.cpp +++ b/tests/FunctionTest.cpp @@ -26,7 +26,7 @@ #include "Sample.h" #include "MockDb.h" #include -//#include +#include #include #include @@ -171,7 +171,6 @@ int main() // SUB_SELECT_FUNCTIONS // -------------------- -#if 0 // Test exists { using TI = decltype(exists(select(t.alpha).from(t))); @@ -189,6 +188,9 @@ int main() // Test any { + using S = decltype(select(t.alpha).from(t)); + static_assert(sqlpp::is_numeric_t::value, "type requirement"); + static_assert(sqlpp::is_numeric_t::value, "type requirement"); using TI = decltype(any(select(t.alpha).from(t))); using TT = decltype(any(select(t.beta).from(t))); @@ -233,7 +235,6 @@ int main() static_assert(not sqlpp::is_floating_point_t::value, "type requirement"); static_assert(sqlpp::is_text_t::value, "type requirement"); } -#endif // NUMERIC FUNCTIONS // ----------------- From 6972758931401ebfd1ecacc860fccd04a30da8b6 Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 16 May 2014 09:33:48 +0200 Subject: [PATCH 04/65] Added extra_tables to recursive_traits --- include/sqlpp11/column.h | 2 ++ include/sqlpp11/parameter.h | 8 +++++++- include/sqlpp11/select.h | 2 +- include/sqlpp11/table.h | 1 + include/sqlpp11/type_traits.h | 10 ++++++++++ include/sqlpp11/vendor/extra_tables.h | 8 ++++++++ 6 files changed, 29 insertions(+), 2 deletions(-) diff --git a/include/sqlpp11/column.h b/include/sqlpp11/column.h index 8795a08b..383f94cc 100644 --- a/include/sqlpp11/column.h +++ b/include/sqlpp11/column.h @@ -48,8 +48,10 @@ namespace sqlpp using _traits = make_traits; struct _recursive_traits { + using _parameters = std::tuple<>; using _provided_tables = detail::type_set<>; using _required_tables = detail::type_set
; + using _extra_tables = detail::type_set<>; }; using _spec_t = ColumnSpec; diff --git a/include/sqlpp11/parameter.h b/include/sqlpp11/parameter.h index d13afdbf..b3769639 100644 --- a/include/sqlpp11/parameter.h +++ b/include/sqlpp11/parameter.h @@ -37,7 +37,13 @@ namespace sqlpp struct parameter_t: public ValueType::template expression_operators> { using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; + struct _recursive_traits + { + using _parameters = std::tuple; + using _provided_tables = detail::type_set<>; + using _required_tables = detail::type_set<>; + using _extra_tables = detail::type_set<>; + }; using _instance_t = typename NameType::_name_t::template _member_t; diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 66eafd90..ee36c6bc 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -112,7 +112,7 @@ namespace sqlpp static_assert(is_noop_t::value or sqlpp::is_select_column_list_t::value, "column list of select is neither naught nor a valid column list"); static_assert(is_noop_t::value or sqlpp::is_from_t::value, "from() part of select is neither naught nor a valid from()"); - using _known_tables = detail::make_joined_set_t, provided_tables_of<_extra_tables_t>>; // FIXME, use provided_tables_of; + using _known_tables = detail::make_joined_set_t, extra_tables_of<_extra_tables_t>>; template using _no_unknown_tables = detail::is_subset_of, _known_tables>; diff --git a/include/sqlpp11/table.h b/include/sqlpp11/table.h index a77120ea..5f74da41 100644 --- a/include/sqlpp11/table.h +++ b/include/sqlpp11/table.h @@ -49,6 +49,7 @@ namespace sqlpp using _parameters = std::tuple<>; using _required_tables = detail::type_set<>; using _provided_tables = detail::type_set
; + using _extra_tables = detail::type_set<>; }; static_assert(sizeof...(ColumnSpec), "at least one column required per table"); diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index fe2c901d..66243bc2 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -162,6 +162,12 @@ namespace sqlpp { using type = typename T::_recursive_traits::_provided_tables; }; + + template + struct extra_table_of_impl + { + using type = typename T::_recursive_traits::_extra_tables; + }; } template using value_type_of = typename detail::value_type_of_impl::type; @@ -172,6 +178,9 @@ namespace sqlpp template using provided_tables_of = typename detail::provided_table_of_impl::type; + template + using extra_tables_of = typename detail::extra_table_of_impl::type; + template struct make_traits { @@ -183,6 +192,7 @@ namespace sqlpp { using _required_tables = detail::make_joined_set_t...>; using _provided_tables = detail::make_joined_set_t...>; + using _extra_tables = detail::make_joined_set_t...>; }; } diff --git a/include/sqlpp11/vendor/extra_tables.h b/include/sqlpp11/vendor/extra_tables.h index 36fb431a..040b5c5f 100644 --- a/include/sqlpp11/vendor/extra_tables.h +++ b/include/sqlpp11/vendor/extra_tables.h @@ -40,6 +40,14 @@ namespace sqlpp struct extra_tables_t { using _traits = make_traits; + struct _recursive_traits + { + using _parameters = std::tuple<>; + using _required_tables = ::sqlpp::detail::type_set<>; + using _provided_tables = ::sqlpp::detail::type_set<>; + using _extra_tables = ::sqlpp::detail::type_set; + }; + using _recursive_traits = make_recursive_traits; // FIXME: extra_tables must not require tables! From f314c6d070aad0324318377c1641b81e6604cb0b Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 16 May 2014 20:06:20 +0200 Subject: [PATCH 05/65] Added recursive_traits to select --- include/sqlpp11/select.h | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index ee36c6bc..da752636 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -117,7 +117,7 @@ namespace sqlpp template using _no_unknown_tables = detail::is_subset_of, _known_tables>; - using _required_tables = + using _all_required_tables = detail::make_joined_set_t< required_tables_of<_flag_list_t>, required_tables_of<_column_list_t>, @@ -130,8 +130,8 @@ namespace sqlpp >; // The tables not covered by the from. - using _table_set = detail::make_difference_set_t< - _required_tables, + using _required_tables = detail::make_difference_set_t< + _all_required_tables, provided_tables_of<_from_t> // Hint: extra_tables_t is not used here because it is just a helper for dynamic .add_*() methods and should not change the structural integrity >; @@ -139,7 +139,7 @@ namespace sqlpp // - at least one column is selected // - the select is complete (leaks no tables) using _can_be_used_as_table = typename std::conditional< - is_select_column_list_t<_column_list_t>::value and _table_set::size::value == 0, + is_select_column_list_t<_column_list_t>::value and _required_tables::size::value == 0, std::true_type, std::false_type >::type; @@ -150,7 +150,16 @@ namespace sqlpp no_value_t // If something is selected that requires a table, then we require a from for this to be a value >::type; - using _traits = make_traits<_value_type>; + using _traits = make_traits<_value_type>; + + struct _recursive_traits + { + using _parameters = std::tuple<>; // FIXME + using _required_tables = _required_tables; + using _provided_tables = detail::type_set<>; + using _extra_tables = detail::type_set<>; + }; + }; } @@ -162,10 +171,12 @@ namespace sqlpp public detail::select_policies_t::_value_type::template expression_operators>, public detail::select_policies_t::_methods_t { - using _traits = make_traits>, ::sqlpp::tag::select>; - using _recursive_traits = make_recursive_traits<>; // FIXME - using _policies_t = typename detail::select_policies_t; + + using _traits = make_traits, ::sqlpp::tag::select>; + + using _recursive_traits = typename _policies_t::_recursive_traits; + using _database_t = typename _policies_t::_database_t; using _flag_list_t = typename _policies_t::_flag_list_t; using _column_list_t = typename _policies_t::_column_list_t; @@ -182,7 +193,6 @@ namespace sqlpp using _parameter_tuple_t = std::tuple; using _parameter_list_t = typename make_parameter_list_t::type; - using _table_set = typename _policies_t::_table_set; template using _result_row_t = typename _column_list_t::template _result_row_t; @@ -256,7 +266,7 @@ namespace sqlpp template struct is_table_subset_of_from { - static constexpr bool value = ::sqlpp::detail::is_subset_of::value; + static constexpr bool value = ::sqlpp::detail::is_subset_of, provided_tables_of<_from_t>>::value; }; void _check_consistency() const @@ -271,7 +281,7 @@ namespace sqlpp static_assert(is_table_subset_of_from<_order_by_t>::value, "order_by() expression requires additional tables in from()"); static_assert(is_table_subset_of_from<_limit_t>::value, "limit() expression requires additional tables in from()"); static_assert(is_table_subset_of_from<_offset_t>::value, "offset() expression requires additional tables in from()"); - static_assert(not _table_set::size::value, "one sub expression contains tables which are not in the from()"); + static_assert(not required_tables_of<_policies_t>::size::value, "one sub expression contains tables which are not in the from()"); } // Execute From e39444b0f70e613b0008fdc760d773538a50d7f2 Mon Sep 17 00:00:00 2001 From: rbock Date: Mon, 19 May 2014 06:42:45 +0200 Subject: [PATCH 06/65] Added tags missing and return_value missing indicates that a statement part has yet to be added (e.g. columns in a select). return_value indicates that a statement part can be used as a return value. --- include/sqlpp11/detail/type_set.h | 3 +++ include/sqlpp11/select.h | 4 ++-- include/sqlpp11/type_traits.h | 2 ++ include/sqlpp11/vendor/select_column_list.h | 6 +++--- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/sqlpp11/detail/type_set.h b/include/sqlpp11/detail/type_set.h index 64a2b005..ecc51a23 100644 --- a/include/sqlpp11/detail/type_set.h +++ b/include/sqlpp11/detail/type_set.h @@ -157,6 +157,9 @@ namespace sqlpp using type = typename make_type_set_if::type::template insert_if::type; }; + template class Predicate, typename... T> + using make_type_set_if_t = typename make_type_set_if::type; + template class Predicate, typename... T> struct make_type_set_if_not { diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index da752636..2f5dc271 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -145,9 +145,9 @@ namespace sqlpp >::type; using _value_type = typename std::conditional< - is_select_column_list_t<_column_list_t>::value and is_subset_of, provided_tables_of<_from_t>>::value, + detail::make_type_set_if_t::size::value == 0, value_type_of<_column_list_t>, - no_value_t // If something is selected that requires a table, then we require a from for this to be a value + no_value_t // if a required statement part is missing (columns in a select), then the statement cannot be used as a value >::type; using _traits = make_traits<_value_type>; diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index 66243bc2..a1f231c5 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -106,6 +106,8 @@ namespace sqlpp SQLPP_IS_COLUMN_TRAIT_GENERATOR(trivial_value_is_null); SQLPP_IS_VALUE_TRAIT_GENERATOR(noop); + SQLPP_IS_VALUE_TRAIT_GENERATOR(missing); + SQLPP_IS_VALUE_TRAIT_GENERATOR(return_value); SQLPP_IS_VALUE_TRAIT_GENERATOR(table); SQLPP_IS_VALUE_TRAIT_GENERATOR(join); SQLPP_IS_VALUE_TRAIT_GENERATOR(pseudo_table); diff --git a/include/sqlpp11/vendor/select_column_list.h b/include/sqlpp11/vendor/select_column_list.h index 1f160d16..ce98c227 100644 --- a/include/sqlpp11/vendor/select_column_list.h +++ b/include/sqlpp11/vendor/select_column_list.h @@ -47,14 +47,14 @@ namespace sqlpp template struct get_first_argument_if_unique { - using _traits = make_traits; + using _traits = make_traits; struct _name_t {}; }; template struct get_first_argument_if_unique { - using _traits = make_traits, tag::select_column_list, tag::expression, tag::named_expression>; + using _traits = make_traits, tag::select_column_list, tag::return_value, tag::expression, tag::named_expression>; using _name_t = typename T::_name_t; }; } @@ -239,7 +239,7 @@ namespace sqlpp { struct no_select_column_list_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; template From bfd13c674372b2639ce87d42f04f526f0e498bf9 Mon Sep 17 00:00:00 2001 From: rbock Date: Mon, 19 May 2014 07:51:24 +0200 Subject: [PATCH 07/65] Determining column_list in a more generic way. By finding the last parameter which is a return value. --- include/sqlpp11/detail/get_last.h | 60 +++++++++++++++++++++++++++++++ include/sqlpp11/select.h | 7 ++-- include/sqlpp11/vendor/noop.h | 3 +- 3 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 include/sqlpp11/detail/get_last.h diff --git a/include/sqlpp11/detail/get_last.h b/include/sqlpp11/detail/get_last.h new file mode 100644 index 00000000..02bacd4b --- /dev/null +++ b/include/sqlpp11/detail/get_last.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2013-2014, 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. + */ + +#ifndef SQLPP_DETAIL_GET_LAST_H +#define SQLPP_DETAIL_GET_LAST_H + +#include + +namespace sqlpp +{ + namespace detail + { + template class Predicate, typename Default, typename... T> + struct get_last_if_impl; + + template class Predicate, typename Default> + struct get_last_if_impl + { + using type = Default; + }; + + template class Predicate, typename Default, typename T, typename... Rest> + struct get_last_if_impl + { + using rest = typename get_last_if_impl::type; + using type = typename std::conditional::value and Predicate::value, + T, + rest>::type; + }; + + template class Predicate, typename Default, typename... T> + using get_last_if = typename get_last_if_impl::type; + } +} + + +#endif diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 2f5dc271..976d4ef4 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -48,6 +48,7 @@ #include #include +#include namespace sqlpp { @@ -135,18 +136,20 @@ namespace sqlpp provided_tables_of<_from_t> // Hint: extra_tables_t is not used here because it is just a helper for dynamic .add_*() methods and should not change the structural integrity >; + using _result_provider = detail::get_last_if; + // A select can be used as a pseudo table if // - at least one column is selected // - the select is complete (leaks no tables) using _can_be_used_as_table = typename std::conditional< - is_select_column_list_t<_column_list_t>::value and _required_tables::size::value == 0, + is_select_column_list_t<_result_provider>::value and _required_tables::size::value == 0, std::true_type, std::false_type >::type; using _value_type = typename std::conditional< detail::make_type_set_if_t::size::value == 0, - value_type_of<_column_list_t>, + value_type_of<_result_provider>, no_value_t // if a required statement part is missing (columns in a select), then the statement cannot be used as a value >::type; diff --git a/include/sqlpp11/vendor/noop.h b/include/sqlpp11/vendor/noop.h index e0c28ef1..1a7bcfe5 100644 --- a/include/sqlpp11/vendor/noop.h +++ b/include/sqlpp11/vendor/noop.h @@ -35,7 +35,8 @@ namespace sqlpp { struct noop { - using is_noop = std::true_type; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; }; template From 569f0ff2ebe42955360f4bfc566a751a89f4c934 Mon Sep 17 00:00:00 2001 From: rbock Date: Mon, 19 May 2014 08:01:14 +0200 Subject: [PATCH 08/65] Wrote down remaining steps for next release --- include/sqlpp11/select.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 976d4ef4..552feafd 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -57,6 +57,11 @@ namespace sqlpp > struct select_t; +#warning STEPS: +#warning replace _select_column_t by _result_provider +#warning turn select into a variadic template (and have a empty_select which contains the default settings +#warning do the same with insert, update and remove +#warning deal with different return types in the connector (select could be a single value, update could be a range of rows) namespace detail { template Date: Mon, 19 May 2014 22:54:47 +0200 Subject: [PATCH 09/65] A step towards turning select into a really variadic template --- include/sqlpp11/select.h | 98 ++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 63 deletions(-) diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 552feafd..40be4bdb 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -115,9 +115,6 @@ namespace sqlpp template using _new_statement_t = typename _policies_update_t::type; - static_assert(is_noop_t::value or sqlpp::is_select_column_list_t::value, "column list of select is neither naught nor a valid column list"); - static_assert(is_noop_t::value or sqlpp::is_from_t::value, "from() part of select is neither naught nor a valid from()"); - using _known_tables = detail::make_joined_set_t, extra_tables_of<_extra_tables_t>>; template @@ -141,7 +138,7 @@ namespace sqlpp provided_tables_of<_from_t> // Hint: extra_tables_t is not used here because it is just a helper for dynamic .add_*() methods and should not change the structural integrity >; - using _result_provider = detail::get_last_if; + using _result_provider = detail::get_last_if; // A select can be used as a pseudo table if // - at least one column is selected @@ -171,34 +168,48 @@ namespace sqlpp }; } + namespace detail + { + template + Target pick_arg_impl(Statement statement, Term term, const std::true_type&) + { + return term; + }; + + template + Target pick_arg_impl(Statement statement, Term term, const std::false_type&) + { + return static_cast(statement); + }; + + template + Target pick_arg(Statement statement, Term term) + { + return pick_arg_impl(statement, term, std::is_same()); + }; + } + // SELECT template struct select_t: + public Policies..., public detail::select_policies_t::_value_type::template expression_operators>, public detail::select_policies_t::_methods_t - { + { using _policies_t = typename detail::select_policies_t; using _traits = make_traits, ::sqlpp::tag::select>; using _recursive_traits = typename _policies_t::_recursive_traits; - using _database_t = typename _policies_t::_database_t; - using _flag_list_t = typename _policies_t::_flag_list_t; - using _column_list_t = typename _policies_t::_column_list_t; - using _from_t = typename _policies_t::_from_t; - using _extra_tables_t = typename _policies_t::_extra_tables_t; - using _where_t = typename _policies_t::_where_t; - using _group_by_t = typename _policies_t::_group_by_t; - using _having_t = typename _policies_t::_having_t; - using _order_by_t = typename _policies_t::_order_by_t; - using _limit_t = typename _policies_t::_limit_t; - using _offset_t = typename _policies_t::_offset_t; - + using _database_t = Db; using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; +#warning replace _column_list_t by a more generic name + using _column_list_t = typename _policies_t::_result_provider; + using _parameter_tuple_t = std::tuple; using _parameter_list_t = typename make_parameter_list_t::type; @@ -216,17 +227,9 @@ namespace sqlpp select_t() {} - template - select_t(Statement s, T t): - _flag_list(detail::arg_selector<_flag_list_t>::_(s._flag_list, t)), - _column_list(detail::arg_selector<_column_list_t>::_(s._column_list, t)), - _from(detail::arg_selector<_from_t>::_(s._from, t)), - _where(detail::arg_selector<_where_t>::_(s._where, t)), - _group_by(detail::arg_selector<_group_by_t>::_(s._group_by, t)), - _having(detail::arg_selector<_having_t>::_(s._having, t)), - _order_by(detail::arg_selector<_order_by_t>::_(s._order_by, t)), - _limit(detail::arg_selector<_limit_t>::_(s._limit, t)), - _offset(detail::arg_selector<_offset_t>::_(s._offset, t)) + template + select_t(Statement statement, Term term): + Policies(detail::pick_arg(statement, term))... {} select_t(const select_t& r) = default; @@ -253,7 +256,7 @@ namespace sqlpp const _dynamic_names_t& get_dynamic_names() const { - return _column_list._dynamic_columns._dynamic_expression_names; + return static_cast(*this)._dynamic_columns._dynamic_expression_names; } static constexpr size_t _get_static_no_of_parameters() @@ -271,24 +274,9 @@ namespace sqlpp return _column_list_t::static_size() + get_dynamic_names().size(); } - template - struct is_table_subset_of_from - { - static constexpr bool value = ::sqlpp::detail::is_subset_of, provided_tables_of<_from_t>>::value; - }; - void _check_consistency() const { - static_assert(is_select_column_list_t<_column_list_t>::value, "no columns selected"); - - static_assert(is_table_subset_of_from<_flag_list_t>::value, "flags require additional tables in from()"); - static_assert(is_table_subset_of_from<_column_list_t>::value, "selected columns require additional tables in from()"); - static_assert(is_table_subset_of_from<_where_t>::value, "where() expression requires additional tables in from()"); - static_assert(is_table_subset_of_from<_group_by_t>::value, "group_by() expression requires additional tables in from()"); - static_assert(is_table_subset_of_from<_having_t>::value, "having() expression requires additional tables in from()"); - static_assert(is_table_subset_of_from<_order_by_t>::value, "order_by() expression requires additional tables in from()"); - static_assert(is_table_subset_of_from<_limit_t>::value, "limit() expression requires additional tables in from()"); - static_assert(is_table_subset_of_from<_offset_t>::value, "offset() expression requires additional tables in from()"); +#warning check for missing terms here, and for missing tables static_assert(not required_tables_of<_policies_t>::size::value, "one sub expression contains tables which are not in the from()"); } @@ -313,15 +301,7 @@ namespace sqlpp return {{}, get_dynamic_names(), db.prepare_select(*this)}; } - _flag_list_t _flag_list; - _column_list_t _column_list; - _from_t _from; - _where_t _where; - _group_by_t _group_by; - _having_t _having; - _order_by_t _order_by; - _limit_t _limit; - _offset_t _offset; + std::tuple _terms; }; namespace vendor @@ -335,15 +315,7 @@ namespace sqlpp { context << "SELECT "; - serialize(t._flag_list, context); - serialize(t._column_list, context); - serialize(t._from, context); - serialize(t._where, context); - serialize(t._group_by, context); - serialize(t._having, context); - serialize(t._order_by, context); - serialize(t._limit, context); - serialize(t._offset, context); + interpret_tuple(t._terms, ' ', context); return context; } From 6d91cf2163c57cb601689418f242cc363fc74db1 Mon Sep 17 00:00:00 2001 From: rbock Date: Mon, 19 May 2014 23:24:41 +0200 Subject: [PATCH 10/65] select is now really a variadic template It is getting ready for customization to reflect vendor specific statement parts, e.g. order by in update and delete for mysql. --- include/sqlpp11/select.h | 106 +++++++++++++-------------------------- 1 file changed, 36 insertions(+), 70 deletions(-) diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 40be4bdb..8d7033a5 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -52,60 +52,24 @@ namespace sqlpp { - template + template struct select_t; #warning STEPS: -#warning replace _select_column_t by _result_provider -#warning turn select into a variadic template (and have a empty_select which contains the default settings #warning do the same with insert, update and remove #warning deal with different return types in the connector (select could be a single value, update could be a range of rows) namespace detail { - template + template struct select_policies_t { using _database_t = Db; - using _flag_list_t = FlagList; - using _column_list_t = ColumnList; - using _from_t = From; - using _extra_tables_t = ExtraTables; - using _where_t = Where; - using _group_by_t = GroupBy; - using _having_t = Having; - using _order_by_t = OrderBy; - using _limit_t = Limit; - using _offset_t = Offset; + using _statement_t = select_t; - using _statement_t = select_t; - - struct _methods_t: - public _flag_list_t::template _methods_t, - public _column_list_t::template _methods_t, - public _from_t::template _methods_t, - public _extra_tables_t::template _methods_t, - public _where_t::template _methods_t, - public _group_by_t::template _methods_t, - public _having_t::template _methods_t, - public _order_by_t::template _methods_t, - public _limit_t::template _methods_t, - public _offset_t::template _methods_t + struct _methods_t: public Policies::template _methods_t... {}; - template + template struct _policies_update_t { static_assert(detail::is_element_of>::value, "policies update for non-policy class detected"); @@ -113,32 +77,24 @@ namespace sqlpp }; template - using _new_statement_t = typename _policies_update_t::type; + using _new_statement_t = typename _policies_update_t::type; - using _known_tables = detail::make_joined_set_t, extra_tables_of<_extra_tables_t>>; + using _all_required_tables = detail::make_joined_set_t...>; + using _all_provided_tables = detail::make_joined_set_t...>; + using _all_extra_tables = detail::make_joined_set_t...>; + + using _known_tables = detail::make_joined_set_t<_all_provided_tables, _all_extra_tables>; template using _no_unknown_tables = detail::is_subset_of, _known_tables>; - using _all_required_tables = - detail::make_joined_set_t< - required_tables_of<_flag_list_t>, - required_tables_of<_column_list_t>, - required_tables_of<_where_t>, - required_tables_of<_group_by_t>, - required_tables_of<_having_t>, - required_tables_of<_order_by_t>, - required_tables_of<_limit_t>, - required_tables_of<_offset_t> - >; - // The tables not covered by the from. using _required_tables = detail::make_difference_set_t< _all_required_tables, - provided_tables_of<_from_t> // Hint: extra_tables_t is not used here because it is just a helper for dynamic .add_*() methods and should not change the structural integrity + _all_provided_tables // Hint: extra_tables are not used here because they are just a helper for dynamic .add_*() >; - using _result_provider = detail::get_last_if; + using _result_provider = detail::get_last_if; // A select can be used as a pseudo table if // - at least one column is selected @@ -150,7 +106,7 @@ namespace sqlpp >::type; using _value_type = typename std::conditional< - detail::make_type_set_if_t::size::value == 0, + detail::none_t::value...>::value, value_type_of<_result_provider>, no_value_t // if a required statement part is missing (columns in a select), then the statement cannot be used as a value >::type; @@ -300,8 +256,6 @@ namespace sqlpp return {{}, get_dynamic_names(), db.prepare_select(*this)}; } - - std::tuple _terms; }; namespace vendor @@ -315,39 +269,51 @@ namespace sqlpp { context << "SELECT "; - interpret_tuple(t._terms, ' ', context); + using swallow = int[]; + (void) swallow{(serialize(static_cast(t), context), 0)...}; return context; } }; } - template - using make_select_t = typename detail::select_policies_t::_statement_t; + template + using blank_select_t = select_t; - make_select_t select() // FIXME: These should be constexpr + + blank_select_t select() // FIXME: These should be constexpr { return { }; } template auto select(Columns... columns) - -> make_select_t> + -> decltype(blank_select_t().columns(detail::make_select_column_list_t(columns...))) { - return { make_select_t(), detail::make_select_column_list_t{std::tuple_cat(detail::as_tuple::_(columns)...)} }; + return blank_select_t().columns(detail::make_select_column_list_t(columns...)); } template - make_select_t dynamic_select(const Database&) + blank_select_t dynamic_select(const Database&) { - return { make_select_t() }; + return { }; } template auto dynamic_select(const Database&, Columns... columns) - -> make_select_t> + -> decltype(blank_select_t().columns(detail::make_select_column_list_t(columns...))) { - return { make_select_t(), detail::make_select_column_list_t(std::tuple_cat(detail::as_tuple::_(columns)...)) }; + return blank_select_t().columns(detail::make_select_column_list_t(columns...)); } } From c81a7d33aeeab64f0ce84e447f0aea27ba15e1d0 Mon Sep 17 00:00:00 2001 From: rbock Date: Tue, 20 May 2014 08:50:55 +0200 Subject: [PATCH 11/65] Cleanup --- .../detail/{arg_selector.h => pick_arg.h} | 27 +++++++---- include/sqlpp11/select.h | 48 +++++-------------- tests/FunctionTest.cpp | 1 - 3 files changed, 30 insertions(+), 46 deletions(-) rename include/sqlpp11/detail/{arg_selector.h => pick_arg.h} (65%) diff --git a/include/sqlpp11/detail/arg_selector.h b/include/sqlpp11/detail/pick_arg.h similarity index 65% rename from include/sqlpp11/detail/arg_selector.h rename to include/sqlpp11/detail/pick_arg.h index e2922920..ca9f5296 100644 --- a/include/sqlpp11/detail/arg_selector.h +++ b/include/sqlpp11/detail/pick_arg.h @@ -24,23 +24,32 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SQLPP_DETAIL_ARG_SELECTOR_H -#define SQLPP_DETAIL_ARG_SELECTOR_H +#ifndef SQLPP_DETAIL_PICK_ARG_H +#define SQLPP_DETAIL_PICK_ARG_H + +#include namespace sqlpp { namespace detail { - template - struct arg_selector + template + Target pick_arg_impl(Statement statement, Term term, const std::true_type&) { - static Target _(Target, Target t) { return t; } + return term; + }; - template - static Target _(X, Target t) { return t; } + template + Target pick_arg_impl(Statement statement, Term term, const std::false_type&) + { + return static_cast(statement); + }; - template - static Target _(Target t, X) { return t; } + // Returns a statement's term either by picking the term from the statement or using the new term + template + Target pick_arg(Statement statement, Term term) + { + return pick_arg_impl(statement, term, std::is_same()); }; } } diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 8d7033a5..8b12a784 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -47,8 +47,9 @@ #include #include -#include +//#include #include +#include namespace sqlpp { @@ -94,20 +95,20 @@ namespace sqlpp _all_provided_tables // Hint: extra_tables are not used here because they are just a helper for dynamic .add_*() >; - using _result_provider = detail::get_last_if; + using _result_type_provider = detail::get_last_if; // A select can be used as a pseudo table if // - at least one column is selected // - the select is complete (leaks no tables) using _can_be_used_as_table = typename std::conditional< - is_select_column_list_t<_result_provider>::value and _required_tables::size::value == 0, + is_select_column_list_t<_result_type_provider>::value and _required_tables::size::value == 0, std::true_type, std::false_type >::type; using _value_type = typename std::conditional< detail::none_t::value...>::value, - value_type_of<_result_provider>, + value_type_of<_result_type_provider>, no_value_t // if a required statement part is missing (columns in a select), then the statement cannot be used as a value >::type; @@ -124,27 +125,6 @@ namespace sqlpp }; } - namespace detail - { - template - Target pick_arg_impl(Statement statement, Term term, const std::true_type&) - { - return term; - }; - - template - Target pick_arg_impl(Statement statement, Term term, const std::false_type&) - { - return static_cast(statement); - }; - - template - Target pick_arg(Statement statement, Term term) - { - return pick_arg_impl(statement, term, std::is_same()); - }; - } - // SELECT template; using _traits = make_traits, ::sqlpp::tag::select>; - using _recursive_traits = typename _policies_t::_recursive_traits; using _database_t = Db; using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; -#warning replace _column_list_t by a more generic name - using _column_list_t = typename _policies_t::_result_provider; + using _result_type_provider = typename _policies_t::_result_type_provider; using _parameter_tuple_t = std::tuple; using _parameter_list_t = typename make_parameter_list_t::type; 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 _result_row_t = typename _result_type_provider::template _result_row_t; + using _dynamic_names_t = typename _result_type_provider::_dynamic_names_t; - using _is_select = std::true_type; using _requires_braces = std::true_type; - using _value_type = typename detail::select_policies_t::_value_type; - using _name_t = typename _column_list_t::_name_t; + using _name_t = typename _result_type_provider::_name_t; // Constructors select_t() @@ -198,7 +174,7 @@ namespace sqlpp template struct _pseudo_table_t { - using table = typename _column_list_t::template _pseudo_table_t; + using table = typename _result_type_provider::template _pseudo_table_t; using alias = typename table::template _alias_t; }; @@ -212,7 +188,7 @@ namespace sqlpp const _dynamic_names_t& get_dynamic_names() const { - return static_cast(*this)._dynamic_columns._dynamic_expression_names; + return static_cast(*this)._dynamic_columns._dynamic_expression_names; } static constexpr size_t _get_static_no_of_parameters() @@ -227,7 +203,7 @@ namespace sqlpp size_t get_no_of_result_columns() const { - return _column_list_t::static_size() + get_dynamic_names().size(); + return _result_type_provider::static_size() + get_dynamic_names().size(); } void _check_consistency() const diff --git a/tests/FunctionTest.cpp b/tests/FunctionTest.cpp index bc02891b..e668a668 100644 --- a/tests/FunctionTest.cpp +++ b/tests/FunctionTest.cpp @@ -190,7 +190,6 @@ int main() { using S = decltype(select(t.alpha).from(t)); static_assert(sqlpp::is_numeric_t::value, "type requirement"); - static_assert(sqlpp::is_numeric_t::value, "type requirement"); using TI = decltype(any(select(t.alpha).from(t))); using TT = decltype(any(select(t.beta).from(t))); From c4a02d931c7cceddf7784f9ee7649a3184f8cec2 Mon Sep 17 00:00:00 2001 From: rbock Date: Tue, 20 May 2014 21:22:55 +0200 Subject: [PATCH 12/65] SelectTypeTests compile again! --- include/sqlpp11/alias.h | 2 +- include/sqlpp11/multi_column.h | 2 +- include/sqlpp11/select.h | 17 +++++---- include/sqlpp11/sort_order.h | 5 ++- include/sqlpp11/table_alias.h | 3 +- include/sqlpp11/tvin.h | 38 ++++++++++---------- include/sqlpp11/type_traits.h | 9 +++-- include/sqlpp11/vendor/expression_fwd.h | 32 ++++++++--------- include/sqlpp11/vendor/field.h | 4 ++- include/sqlpp11/vendor/from.h | 3 +- include/sqlpp11/vendor/group_by.h | 4 ++- include/sqlpp11/vendor/having.h | 4 ++- include/sqlpp11/vendor/limit.h | 6 ++-- include/sqlpp11/vendor/offset.h | 6 ++-- include/sqlpp11/vendor/order_by.h | 4 ++- include/sqlpp11/vendor/select_column_list.h | 4 ++- include/sqlpp11/vendor/select_flag_list.h | 4 ++- include/sqlpp11/vendor/select_pseudo_table.h | 5 ++- include/sqlpp11/vendor/where.h | 4 ++- tests/CMakeLists.txt | 2 +- tests/SelectTypeTest.cpp | 26 +++++++------- 21 files changed, 109 insertions(+), 75 deletions(-) diff --git a/include/sqlpp11/alias.h b/include/sqlpp11/alias.h index b9d6e25a..c280c893 100644 --- a/include/sqlpp11/alias.h +++ b/include/sqlpp11/alias.h @@ -35,7 +35,7 @@ namespace sqlpp template struct expression_alias_t { - using _traits = make_traits, tag::named_expression>; + using _traits = make_traits, tag::named_expression, tag::alias>; using _recursive_traits = make_recursive_traits; static_assert(is_expression_t::value, "invalid argument for an expression alias"); diff --git a/include/sqlpp11/multi_column.h b/include/sqlpp11/multi_column.h index d61c2aaf..650e1bc7 100644 --- a/include/sqlpp11/multi_column.h +++ b/include/sqlpp11/multi_column.h @@ -76,7 +76,7 @@ namespace sqlpp template struct multi_column_alias_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; static_assert(detail::all_t::value...>::value, "multi_column parameters need to be named expressions"); diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 8b12a784..95e319be 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -109,9 +109,14 @@ namespace sqlpp using _value_type = typename std::conditional< detail::none_t::value...>::value, value_type_of<_result_type_provider>, - no_value_t // if a required statement part is missing (columns in a select), then the statement cannot be used as a value + no_value_t // if a required statement part is missing (e.g. columns in a select), then the statement cannot be used as a value >::type; + using _is_expression = typename std::conditional< + std::is_same<_value_type, no_value_t>::value, + std::false_type, + std::true_type>::type; + using _traits = make_traits<_value_type>; struct _recursive_traits @@ -136,7 +141,7 @@ namespace sqlpp { using _policies_t = typename detail::select_policies_t; - using _traits = make_traits, ::sqlpp::tag::select>; + using _traits = make_traits, ::sqlpp::tag::select, tag::expression_if, tag::named_expression_if>; using _recursive_traits = typename _policies_t::_recursive_traits; using _database_t = Db; @@ -274,9 +279,9 @@ namespace sqlpp template auto select(Columns... columns) - -> decltype(blank_select_t().columns(detail::make_select_column_list_t(columns...))) + -> decltype(blank_select_t().columns(columns...)) { - return blank_select_t().columns(detail::make_select_column_list_t(columns...)); + return blank_select_t().columns(columns...); } template @@ -287,9 +292,9 @@ namespace sqlpp template auto dynamic_select(const Database&, Columns... columns) - -> decltype(blank_select_t().columns(detail::make_select_column_list_t(columns...))) + -> decltype(blank_select_t().columns(columns...)) { - return blank_select_t().columns(detail::make_select_column_list_t(columns...)); + return blank_select_t().columns(columns...); } } diff --git a/include/sqlpp11/sort_order.h b/include/sqlpp11/sort_order.h index 8f70b3c8..7ef6c238 100644 --- a/include/sqlpp11/sort_order.h +++ b/include/sqlpp11/sort_order.h @@ -40,9 +40,8 @@ namespace sqlpp template struct sort_order_t { - using _is_sort_order = std::true_type; - using _provided_tables = detail::type_set<>; - using _required_tables = typename Expression::_required_tables; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; Expression _expression; }; diff --git a/include/sqlpp11/table_alias.h b/include/sqlpp11/table_alias.h index 7ac78868..754ec175 100644 --- a/include/sqlpp11/table_alias.h +++ b/include/sqlpp11/table_alias.h @@ -47,7 +47,8 @@ namespace sqlpp { using _parameters = std::tuple<>; using _required_tables = detail::type_set<>; - using _provided_tables = detail::type_set
; + using _provided_tables = detail::type_set; + using _extra_tables = detail::type_set<>; }; static_assert(required_tables_of
::size::value == 0, "table aliases must not depend on external tables"); diff --git a/include/sqlpp11/tvin.h b/include/sqlpp11/tvin.h index a838296e..1a517714 100644 --- a/include/sqlpp11/tvin.h +++ b/include/sqlpp11/tvin.h @@ -73,18 +73,19 @@ namespace sqlpp }; } - template + template struct maybe_tvin_t { - using _provided_tables = detail::type_set<>; - using _required_tables = typename T::_required_tables; + using _traits = make_traits, tag::expression>; + using _recursive_traits = make_recursive_traits; + static constexpr bool _is_trivial() { return false; } - maybe_tvin_t(T t): - _value(t) + maybe_tvin_t(Operand operand): + _value(operand) {} maybe_tvin_t(const maybe_tvin_t&) = default; maybe_tvin_t(maybe_tvin_t&&) = default; @@ -92,21 +93,22 @@ namespace sqlpp maybe_tvin_t& operator=(maybe_tvin_t&&) = default; ~maybe_tvin_t() = default; - T _value; + Operand _value; }; - template - struct maybe_tvin_t> + template + struct maybe_tvin_t> { - using _provided_tables = detail::type_set<>; - using _required_tables = typename T::_required_tables; + using _traits = make_traits, tag::expression>; + using _recursive_traits = make_recursive_traits; + bool _is_trivial() const { return _value._is_trivial(); }; - maybe_tvin_t(tvin_t t): - _value(t._value) + maybe_tvin_t(tvin_t operand): + _value(operand._value) {} maybe_tvin_t(const maybe_tvin_t&) = default; maybe_tvin_t(maybe_tvin_t&&) = default; @@ -114,7 +116,7 @@ namespace sqlpp maybe_tvin_t& operator=(maybe_tvin_t&&) = default; ~maybe_tvin_t() = default; - typename tvin_t::_operand_t _value; + typename tvin_t::_operand_t _value; }; namespace vendor @@ -139,13 +141,13 @@ namespace sqlpp }; } - template - auto tvin(T t) -> tvin_t::type> + template + auto tvin(Operand operand) -> tvin_t::type> { - using _operand_t = typename vendor::wrap_operand::type; + using _operand_t = typename vendor::wrap_operand::type; static_assert(std::is_same<_operand_t, vendor::text_operand>::value - or not std::is_same<_operand_t, T>::value, "tvin() used with invalid type (only string and primitive types allowed)"); - return {{t}}; + or not std::is_same<_operand_t, Operand>::value, "tvin() used with invalid type (only string and primitive types allowed)"); + return {{operand}}; } } diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index a1f231c5..dc94412f 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -92,8 +92,13 @@ namespace sqlpp SQLPP_IS_VALUE_TRAIT_GENERATOR(named_expression); namespace tag { - template - using named_expression_if = typename std::conditional::type; + template + using named_expression_if = typename std::conditional::type; + } + namespace tag + { + template + using expression_if = typename std::conditional::type; } SQLPP_IS_VALUE_TRAIT_GENERATOR(multi_expression); SQLPP_IS_VALUE_TRAIT_GENERATOR(alias); diff --git a/include/sqlpp11/vendor/expression_fwd.h b/include/sqlpp11/vendor/expression_fwd.h index b6529e8b..374a4265 100644 --- a/include/sqlpp11/vendor/expression_fwd.h +++ b/include/sqlpp11/vendor/expression_fwd.h @@ -35,99 +35,99 @@ namespace sqlpp { struct less { - using _value_type = ::sqlpp::detail::boolean; + using _traits = make_traits<::sqlpp::detail::boolean>; static constexpr const char* _name = "<"; }; struct less_equal { - using _value_type = ::sqlpp::detail::boolean; + using _traits = make_traits<::sqlpp::detail::boolean>; static constexpr const char* _name = "<="; }; struct equal_to { - using _value_type = ::sqlpp::detail::boolean; + using _traits = make_traits<::sqlpp::detail::boolean>; }; struct not_equal_to { - using _value_type = ::sqlpp::detail::boolean; + using _traits = make_traits<::sqlpp::detail::boolean>; }; struct greater_equal { - using _value_type = ::sqlpp::detail::boolean; + using _traits = make_traits<::sqlpp::detail::boolean>; static constexpr const char* _name = ">="; }; struct greater { - using _value_type = ::sqlpp::detail::boolean; + using _traits = make_traits<::sqlpp::detail::boolean>; static constexpr const char* _name = ">"; }; struct logical_or { - using _value_type = ::sqlpp::detail::boolean; + using _traits = make_traits<::sqlpp::detail::boolean>; static constexpr const char* _name = " OR "; }; struct logical_and { - using _value_type = ::sqlpp::detail::boolean; + using _traits = make_traits<::sqlpp::detail::boolean>; static constexpr const char* _name = " AND "; }; struct logical_not { - using _value_type = ::sqlpp::detail::boolean; + using _traits = make_traits<::sqlpp::detail::boolean>; }; template struct plus { - using _value_type = ValueType; + using _traits = make_traits; static constexpr const char* _name = "+"; }; template struct minus { - using _value_type = ValueType; + using _traits = make_traits; static constexpr const char* _name = "-"; }; template struct multiplies { - using _value_type = ValueType; + using _traits = make_traits; static constexpr const char* _name = "*"; }; struct divides { - using _value_type = ::sqlpp::detail::floating_point; + using _traits = make_traits<::sqlpp::detail::floating_point>; static constexpr const char* _name = "/"; }; struct modulus { - using _value_type = ::sqlpp::detail::integral; + using _traits = make_traits<::sqlpp::detail::integral>; static constexpr const char* _name = "%"; }; template struct unary_minus { - using _value_type = ValueType; + using _traits = make_traits; static constexpr const char* _name = "-"; }; template struct unary_plus { - using _value_type = ValueType; + using _traits = make_traits; static constexpr const char* _name = "+"; }; } diff --git a/include/sqlpp11/vendor/field.h b/include/sqlpp11/vendor/field.h index caf93c78..b843dc8d 100644 --- a/include/sqlpp11/vendor/field.h +++ b/include/sqlpp11/vendor/field.h @@ -36,8 +36,10 @@ namespace sqlpp template struct field_t { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; + using _name_t = NameType; - using _value_type = ValueType; static constexpr bool _trivial_value_is_null = TrivialValueIsNull; }; diff --git a/include/sqlpp11/vendor/from.h b/include/sqlpp11/vendor/from.h index 3e30ea33..2a82b4e0 100644 --- a/include/sqlpp11/vendor/from.h +++ b/include/sqlpp11/vendor/from.h @@ -55,6 +55,7 @@ namespace sqlpp static_assert(required_tables_of::size::value == 0, "at least one table depends on another table"); + from_t& _from() { return *this; } from_t(Tables... tables): _tables(tables...) @@ -84,7 +85,7 @@ namespace sqlpp template void _add_from_impl(Table table, const std::true_type&) { - return static_cast(this)->_from._dynamic_tables.emplace_back(table); + return static_cast(this)->_from()._dynamic_tables.emplace_back(table); } template diff --git a/include/sqlpp11/vendor/group_by.h b/include/sqlpp11/vendor/group_by.h index 51fb4f11..3766c66c 100644 --- a/include/sqlpp11/vendor/group_by.h +++ b/include/sqlpp11/vendor/group_by.h @@ -54,6 +54,8 @@ namespace sqlpp static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an expression in group_by()"); + group_by_t& _group_by() { return *this; } + group_by_t(Expressions... expressions): _expressions(expressions...) {} @@ -89,7 +91,7 @@ namespace sqlpp template void _add_group_by_impl(Expression expression, const std::true_type&) { - return static_cast(this)->_group_by._dynamic_expressions.emplace_back(expression); + return static_cast(this)->_group_by()._dynamic_expressions.emplace_back(expression); } template diff --git a/include/sqlpp11/vendor/having.h b/include/sqlpp11/vendor/having.h index fa15285f..8f85eab9 100644 --- a/include/sqlpp11/vendor/having.h +++ b/include/sqlpp11/vendor/having.h @@ -50,6 +50,8 @@ namespace sqlpp static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression argument required in having()"); static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an expression in having()"); + having_t& _having() { return *this; } + having_t(Expressions... expressions): _expressions(expressions...) {} @@ -85,7 +87,7 @@ namespace sqlpp template void _add_having_impl(Expression expression, const std::true_type&) { - return static_cast(this)->_having._dynamic_expressions.emplace_back(expression); + return static_cast(this)->_having()._dynamic_expressions.emplace_back(expression); } template diff --git a/include/sqlpp11/vendor/limit.h b/include/sqlpp11/vendor/limit.h index 62e94916..b5b2ec89 100644 --- a/include/sqlpp11/vendor/limit.h +++ b/include/sqlpp11/vendor/limit.h @@ -68,6 +68,8 @@ namespace sqlpp using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; + dynamic_limit_t& _limit() { return *this; } + dynamic_limit_t(): _value(noop()) { @@ -94,8 +96,8 @@ namespace sqlpp { // FIXME: Make sure that Limit does not require external tables? Need to read up on SQL using arg_t = typename wrap_operand::type; - static_cast(this)->_limit._value = arg_t{value}; - static_cast(this)->_limit._initialized = true; + static_cast(this)->_limit()._value = arg_t{value}; + static_cast(this)->_limit()._initialized = true; } }; diff --git a/include/sqlpp11/vendor/offset.h b/include/sqlpp11/vendor/offset.h index 83cacd95..dca7fd16 100644 --- a/include/sqlpp11/vendor/offset.h +++ b/include/sqlpp11/vendor/offset.h @@ -68,6 +68,8 @@ namespace sqlpp using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; + dynamic_offset_t& _offset() { return *this; } + dynamic_offset_t(): _value(noop()) { @@ -94,8 +96,8 @@ namespace sqlpp { // FIXME: Make sure that Offset does not require external tables? Need to read up on SQL using arg_t = typename wrap_operand::type; - static_cast(this)->_offset._value = arg_t{value}; - static_cast(this)->_offset._initialized = true; + static_cast(this)->_offset()._value = arg_t{value}; + static_cast(this)->_offset()._initialized = true; } }; diff --git a/include/sqlpp11/vendor/order_by.h b/include/sqlpp11/vendor/order_by.h index a6d4a5ad..f60537eb 100644 --- a/include/sqlpp11/vendor/order_by.h +++ b/include/sqlpp11/vendor/order_by.h @@ -53,6 +53,8 @@ namespace sqlpp static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a sort order expression in order_by()"); + order_by_t& _order_by() { return *this; } + order_by_t(Expressions... expressions): _expressions(expressions...) {} @@ -88,7 +90,7 @@ namespace sqlpp template void _add_order_by_impl(Expression expression, const std::true_type&) { - return static_cast(this)->_order_by._dynamic_expressions.emplace_back(expression); + return static_cast(this)->_order_by()._dynamic_expressions.emplace_back(expression); } template diff --git a/include/sqlpp11/vendor/select_column_list.h b/include/sqlpp11/vendor/select_column_list.h index ce98c227..ef3ad4e2 100644 --- a/include/sqlpp11/vendor/select_column_list.h +++ b/include/sqlpp11/vendor/select_column_list.h @@ -164,6 +164,8 @@ namespace sqlpp template using _dynamic_t = select_column_list_t>; + select_column_list_t& _select_column_list() { return *this; } + select_column_list_t(std::tuple columns): _columns(columns) {} @@ -213,7 +215,7 @@ namespace sqlpp template void _add_column_impl(NamedExpression namedExpression, const std::true_type&) { - return static_cast(this)->_column_list._dynamic_columns.emplace_back(namedExpression); + return static_cast(this)->_select_column_list()._dynamic_columns.emplace_back(namedExpression); } template diff --git a/include/sqlpp11/vendor/select_flag_list.h b/include/sqlpp11/vendor/select_flag_list.h index 85303440..5a7e2cf9 100644 --- a/include/sqlpp11/vendor/select_flag_list.h +++ b/include/sqlpp11/vendor/select_flag_list.h @@ -51,6 +51,8 @@ namespace sqlpp static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a select flag in select flag list"); + select_flag_list_t& _select_flag_list() { return *this; } + select_flag_list_t(Flags... flags): _flags(flags...) {} @@ -86,7 +88,7 @@ namespace sqlpp template void _add_flag_impl(Flag flag, const std::true_type&) { - return static_cast(this)->_flag_list._dynamic_flags.emplace_back(flag); + return static_cast(this)->_select_flag_list()._dynamic_flags.emplace_back(flag); } template diff --git a/include/sqlpp11/vendor/select_pseudo_table.h b/include/sqlpp11/vendor/select_pseudo_table.h index a63c4d63..eae7ce5a 100644 --- a/include/sqlpp11/vendor/select_pseudo_table.h +++ b/include/sqlpp11/vendor/select_pseudo_table.h @@ -35,8 +35,11 @@ namespace sqlpp template struct select_column_spec_t { + using _traits = make_traits>; + using _recursive_traits = make_recursive_traits<>; + using _value_type = value_type_of; // FIXME: column specs probably should use _traits, too + using _name_t = typename Expr::_name_t; - using _value_type = typename Expr::_value_type; struct _column_type { using _must_not_insert = std::true_type; diff --git a/include/sqlpp11/vendor/where.h b/include/sqlpp11/vendor/where.h index 01557cdd..9c77059f 100644 --- a/include/sqlpp11/vendor/where.h +++ b/include/sqlpp11/vendor/where.h @@ -51,6 +51,8 @@ namespace sqlpp static_assert(sqlpp::detail::none_t::value...>::value, "at least one argument is an assignment in where()"); static_assert(sqlpp::detail::all_t::value...>::value, "at least one argument is not valid expression in where()"); + where_t& _where() { return *this; } + where_t(Expressions... expressions): _expressions(expressions...) {} @@ -86,7 +88,7 @@ namespace sqlpp template void _add_where_impl(Expression expression, const std::true_type&) { - return static_cast(this)->_where._dynamic_expressions.emplace_back(expression); + return static_cast(this)->_where()._dynamic_expressions.emplace_back(expression); } template diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 71771eee..98f12e6e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -11,7 +11,7 @@ endmacro () #build_and_run(RemoveTest) #build_and_run(UpdateTest) #build_and_run(SelectTest) -#build_and_run(SelectTypeTest) +build_and_run(SelectTypeTest) build_and_run(FunctionTest) #build_and_run(PreparedTest) diff --git a/tests/SelectTypeTest.cpp b/tests/SelectTypeTest.cpp index 12cf9c56..8e1784de 100644 --- a/tests/SelectTypeTest.cpp +++ b/tests/SelectTypeTest.cpp @@ -158,10 +158,10 @@ int main() // Test a select of a single column without a from { - using T = decltype(select(t.alpha)); // Hint: The current rule is pretty crude (a from is required), but certainly better than nothing - static_assert(not sqlpp::is_numeric_t::value, "type requirement"); - static_assert(not sqlpp::is_expression_t::value, "type requirement"); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + using T = decltype(select(t.alpha)); + static_assert(sqlpp::is_numeric_t::value, "type requirement"); + static_assert(sqlpp::is_expression_t::value, "type requirement"); + static_assert(sqlpp::is_named_expression_t::value, "type requirement"); static_assert(not sqlpp::require_insert_t::value, "type requirement"); static_assert(not sqlpp::must_not_insert_t::value, "type requirement"); static_assert(not sqlpp::must_not_update_t::value, "type requirement"); @@ -175,8 +175,8 @@ int main() // Test a select of a single numeric table column { using T = decltype(select(t.alpha).from(t)); - static_assert(sqlpp::is_select_column_list_t::value, "Must not be noop"); - static_assert(sqlpp::is_from_t::value, "Must not be noop"); + //static_assert(sqlpp::is_select_column_list_t::value, "Must not be noop"); + //static_assert(sqlpp::is_from_t::value, "Must not be noop"); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(sqlpp::is_expression_t::value, "type requirement"); static_assert(sqlpp::is_named_expression_t::value, "type requirement"); @@ -290,7 +290,7 @@ int main() { auto m = multi_column(t.alpha, t.beta).as(alias::a); auto a = select(m).from(t).as(alias::b).a; - static_assert(not sqlpp::is_value_t::value, "a multi_column is not a value"); + // FIXME: Do we really need that test? multi_column is a no_value static_assert(not sqlpp::is_expression_t::value, "a multi_column is not a value"); } // Test that result sets with identical name/value combinations have identical types { @@ -299,8 +299,8 @@ int main() 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"); + sqlpp::value_type_of, + sqlpp::value_type_of>::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"); } @@ -339,9 +339,8 @@ int main() static_assert(sqlpp::is_select_flag_t::value, "sqlpp::all has to be a select_flag"); using T = sqlpp::vendor::wrap_operand::type; static_assert(sqlpp::is_regular::value, "type requirement"); - static_assert(T::_is_expression, "T has to be an expression"); - static_assert(std::is_same::value, "T has to be a numeric"); - static_assert(sqlpp::is_numeric_t::value, "T has to be a numeric"); + static_assert(sqlpp::is_expression_t::value, "T has to be an expression"); + static_assert(sqlpp::is_numeric_t::value, "T has to be numeric"); static_assert(sqlpp::is_numeric_t::value, "TabBar.alpha has to be a numeric"); ((t.alpha + 7) + 4).asc(); static_assert(sqlpp::is_boolean_t::value, "Comparison expression have to be boolean"); @@ -353,7 +352,6 @@ int main() static_assert(sqlpp::must_not_insert_t::value, "alpha must not be inserted"); serialize(t.alpha, printer).str(); std::cerr << "\n" << sizeof(test::TabBar) << std::endl; - static_assert(std::is_same::value, "alpha should be a named expression"); static_assert(sqlpp::is_named_expression_t::value, "alpha should be a named expression"); static_assert(sqlpp::is_named_expression_t::value, "an alias of alpha should be a named expression"); static_assert(sqlpp::is_alias_t::value, "an alias of alpha should be an alias"); @@ -366,6 +364,7 @@ int main() auto s = select(r.a).from(r); using RA = decltype(r.a); using S = decltype(s); + /* using SCL = typename S::_column_list_t; using SF = typename S::_from_t; static_assert(sqlpp::is_select_column_list_t::value, "no column list"); @@ -375,6 +374,7 @@ int main() static_assert(SCL_T::size::value == 1, "unexpected table_set in column_list"); static_assert(SF_T::size::value == 1, "unexpected table_set in from"); static_assert(std::is_same::value, "should be the same"); + */ static_assert(sqlpp::is_boolean_t::value, "select(bool) has to be a bool"); auto s1 = sqlpp::select().flags(sqlpp::distinct, sqlpp::straight_join).columns(l.alpha, l.beta, select(r.a).from(r)) .from(r,t,l) From 22e1e7c531240ed24623d527a9fe382e5d1e1314 Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 22 May 2014 22:53:08 +0200 Subject: [PATCH 13/65] Migrated insert to be truly variadic --- include/sqlpp11/column.h | 4 +- include/sqlpp11/insert.h | 93 +++++++++++----------- include/sqlpp11/select.h | 1 - include/sqlpp11/type_traits.h | 1 + include/sqlpp11/vendor/assignment.h | 2 +- include/sqlpp11/vendor/insert_value.h | 8 +- include/sqlpp11/vendor/insert_value_list.h | 55 +++++++------ include/sqlpp11/vendor/single_table.h | 31 ++++++-- include/sqlpp11/vendor/where.h | 2 +- tests/CMakeLists.txt | 6 +- 10 files changed, 115 insertions(+), 88 deletions(-) diff --git a/include/sqlpp11/column.h b/include/sqlpp11/column.h index 383f94cc..47f764f1 100644 --- a/include/sqlpp11/column.h +++ b/include/sqlpp11/column.h @@ -81,12 +81,12 @@ namespace sqlpp } template - auto operator =(T t) const -> vendor::assignment_t::type> + auto operator =(T t) const -> vendor::assignment_t> { using rhs = vendor::wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs operand assignment operand"); - return { *this, {t} }; + return { *this, rhs{t} }; } auto operator =(sqlpp::null_t) const diff --git a/include/sqlpp11/insert.h b/include/sqlpp11/insert.h index c24f236f..78e5d0f9 100644 --- a/include/sqlpp11/insert.h +++ b/include/sqlpp11/insert.h @@ -35,78 +35,86 @@ #include #include #include -#include + +#include +#include namespace sqlpp { - template + template struct insert_t; namespace detail { - template + template struct insert_policies_t { using _database_t = Db; - using _table_t = Table; - using _insert_value_list_t = InsertValueList; - using _statement_t = insert_t; + using _statement_t = insert_t; - struct _methods_t: - public _insert_value_list_t::template _methods_t + struct _methods_t: public Policies::template _methods_t... {}; - template - struct _policies_insert_t + template + struct _policies_update_t { + static_assert(detail::is_element_of>::value, "policies update for non-policy class detected"); using type = insert_t...>; }; template - using _new_statement_t = typename _policies_insert_t::type; + using _new_statement_t = typename _policies_update_t::type; - using _table_set = typename _table_t::_table_set; + using _all_required_tables = detail::make_joined_set_t...>; + using _all_provided_tables = detail::make_joined_set_t...>; + using _all_extra_tables = detail::make_joined_set_t...>; - using _known_tables = detail::make_joined_set_t; + using _known_tables = detail::make_joined_set_t<_all_provided_tables, _all_extra_tables>; template - using _no_unknown_tables = detail::is_subset_of; + using _no_unknown_tables = detail::is_subset_of, _known_tables>; + + // The tables not covered by the from. + using _required_tables = detail::make_difference_set_t< + _all_required_tables, + _all_provided_tables // Hint: extra_tables are not used here because they are just a helper for dynamic .add_*() + >; + + using _traits = make_traits; // FIXME + + struct _recursive_traits + { + using _parameters = std::tuple<>; // FIXME + using _required_tables = _required_tables; + using _provided_tables = detail::type_set<>; + using _extra_tables = detail::type_set<>; + }; }; } // INSERT - template + template struct insert_t: + public Policies..., public detail::insert_policies_t::_methods_t { using _policies_t = typename detail::insert_policies_t; using _database_t = typename _policies_t::_database_t; - using _table_t = typename _policies_t::_table_t; - using _insert_value_list_t = typename _policies_t::_insert_value_list_t; using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; using _parameter_tuple_t = std::tuple; using _parameter_list_t = typename make_parameter_list_t::type; - static_assert(::sqlpp::detail::is_superset_of::value, "columns do not match the table they are to be inserted into"); // Constructors insert_t() {} template - insert_t(Statement s, T t): - _table(detail::arg_selector<_table_t>::_(s._table, t)), - _insert_value_list(detail::arg_selector<_insert_value_list_t>::_(s._insert_value_list, t)) + insert_t(Statement statement, T term): + Policies(detail::pick_arg(statement, term))... {} insert_t(const insert_t&) = default; @@ -126,12 +134,6 @@ namespace sqlpp return _parameter_list_t::size::value; } - template - struct is_table_subset_of_table - { - static constexpr bool value = ::sqlpp::detail::is_subset_of::value; - }; - void _check_consistency() const { // FIXME: Read up on what is allowed/prohibited in INSERT @@ -154,9 +156,6 @@ namespace sqlpp return {{}, db.prepare_insert(*this)}; } - - _insert_value_list_t _insert_value_list; - _table_t _table; }; namespace vendor @@ -169,30 +168,32 @@ namespace sqlpp static Context& _(const T& t, Context& context) { context << "INSERT INTO "; - serialize(t._table, context); - serialize(t._insert_value_list, context); + + using swallow = int[]; + (void) swallow{(serialize(static_cast(t), context), 0)...}; return context; } }; } - template - using make_insert_t = typename detail::insert_policies_t::_statement_t; + template + using blank_insert_t = insert_t; template constexpr auto insert_into(Table table) - -> make_insert_t> + -> decltype(blank_insert_t().into(table)) { - return { make_insert_t(), vendor::single_table_t{table} }; + return { blank_insert_t().into(table) }; } template constexpr auto dynamic_insert_into(const Database&, Table table) - -> make_insert_t> + -> decltype(blank_insert_t().into(table)) { - return { make_insert_t(), vendor::single_table_t{table} }; + return { blank_insert_t().into(table) }; } - } #endif diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 95e319be..6292e21c 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -47,7 +47,6 @@ #include #include -//#include #include #include diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index dc94412f..a195f1c0 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -121,6 +121,7 @@ namespace sqlpp SQLPP_IS_VALUE_TRAIT_GENERATOR(select_flag_list); SQLPP_IS_VALUE_TRAIT_GENERATOR(select_column_list); SQLPP_IS_VALUE_TRAIT_GENERATOR(from); + SQLPP_IS_VALUE_TRAIT_GENERATOR(single_table); SQLPP_IS_VALUE_TRAIT_GENERATOR(extra_tables); SQLPP_IS_VALUE_TRAIT_GENERATOR(on); SQLPP_IS_VALUE_TRAIT_GENERATOR(dynamic); diff --git a/include/sqlpp11/vendor/assignment.h b/include/sqlpp11/vendor/assignment.h index 52ad3c75..1899a393 100644 --- a/include/sqlpp11/vendor/assignment.h +++ b/include/sqlpp11/vendor/assignment.h @@ -69,7 +69,7 @@ namespace sqlpp using _recursive_traits = make_recursive_traits; using _column_t = Lhs; - using _value_t = Lhs; + using _value_t = Rhs; static_assert(can_be_null_t<_column_t>::value ? true : not std::is_same<_value_t, null_t>::value, "column must not be null"); diff --git a/include/sqlpp11/vendor/insert_value.h b/include/sqlpp11/vendor/insert_value.h index ddf54f7e..b0f4dfea 100644 --- a/include/sqlpp11/vendor/insert_value.h +++ b/include/sqlpp11/vendor/insert_value.h @@ -44,8 +44,6 @@ namespace sqlpp struct type_if { using type = Type; - using _provided_tables = detail::type_set<>; - using _required_tables = typename Type::_required_tables; }; template @@ -53,8 +51,8 @@ namespace sqlpp { struct type { - using _provided_tables = detail::type_set<>; - using _required_tables = sqlpp::detail::type_set<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; }; }; } @@ -63,7 +61,7 @@ namespace sqlpp struct insert_value_t { using _is_insert_value = std::true_type; - using _pure_value_t = typename Column::_value_type::_cpp_value_type; + using _pure_value_t = typename value_type_of::_cpp_value_type; using _wrapped_value_t = typename wrap_operand<_pure_value_t>::type; using _tvin_t = typename detail::type_if, can_be_null_t::value>::type; // static asserts and SFINAE do not work together using _null_t = typename detail::type_if::value>::type; // static asserts and SFINAE do not work together diff --git a/include/sqlpp11/vendor/insert_value_list.h b/include/sqlpp11/vendor/insert_value_list.h index e23dc9f0..9cebe8d1 100644 --- a/include/sqlpp11/vendor/insert_value_list.h +++ b/include/sqlpp11/vendor/insert_value_list.h @@ -42,8 +42,8 @@ namespace sqlpp // COLUMN AND VALUE LIST struct insert_default_values_t { - using _required_tables = ::sqlpp::detail::type_set<>; - using _is_dynamic = std::false_type; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; template struct _methods_t @@ -53,29 +53,36 @@ namespace sqlpp template struct insert_list_t { - using _is_insert_list = std::true_type; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - using _parameter_tuple_t = std::tuple; + template class Target> using copy_assignments_t = Target; // FIXME: Nice idea to copy variadic template arguments? template class Target, template class Wrap> using copy_wrapped_assignments_t = Target...>; - static_assert(_is_dynamic::value or sizeof...(Assignments), "at least one select expression required in set()"); + static_assert(_is_dynamic::value or sizeof...(Assignments), "at least one assignment required in set()"); static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in set()"); static_assert(sqlpp::detail::all_t::value...>::value, "at least one argument is not an assignment in set()"); - static_assert(sqlpp::detail::none_t::value...>::value, "at least one assignment is prohibited by its column definition in set()"); + static_assert(sqlpp::detail::none_t::value...>::value, "at least one assignment is prohibited by its column definition in set()"); +#warning: Need to reactivate these checks + /* using _column_required_tables = typename ::sqlpp::detail::make_joined_set::type; using _value_required_tables = typename ::sqlpp::detail::make_joined_set::type; using _provided_tables = ::sqlpp::detail::type_set<>; using _required_tables = typename ::sqlpp::detail::make_joined_set<_column_required_tables, _value_required_tables>::type; static_assert(sizeof...(Assignments) ? (_column_required_tables::size::value == 1) : true, "set() contains assignments for tables from several columns"); static_assert(::sqlpp::detail::is_subset_of<_value_required_tables, _column_required_tables>::value, "set() contains values from foreign tables"); + */ + insert_list_t& _insert_value_list() { return *this; } + insert_list_t(Assignments... assignment): _assignments(assignment...), _columns({assignment._lhs}...), @@ -92,22 +99,24 @@ namespace sqlpp struct _methods_t { template + void add_set_ntc(Assignment assignment) + { + add_set(assignment); + } + + template void add_set(Assignment assignment) { static_assert(_is_dynamic::value, "add_set must not be called for static from()"); static_assert(is_assignment_t::value, "add_set() arguments require to be assigments"); static_assert(not must_not_insert_t::value, "add_set() argument must not be used in insert"); - using _column_table_set = typename Assignment::_column_t::_table_set; - using _value_table_set = typename Assignment::value_type::_table_set; - static_assert(::sqlpp::detail::is_subset_of<_value_table_set, typename Policies::_table_set>::value, "add_set() contains a column from a foreign table"); - static_assert(::sqlpp::detail::is_subset_of<_column_table_set, typename Policies::_table_set>::value, "add_set() contains a value from a foreign table"); + static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables::value, "add_set() contains a column from a foreign table"); using ok = ::sqlpp::detail::all_t< _is_dynamic::value, is_assignment_t::value, not must_not_insert_t::value, - ::sqlpp::detail::is_subset_of<_value_table_set, typename Policies::_table_set>::value, - ::sqlpp::detail::is_subset_of<_column_table_set, typename Policies::_table_set>::value>; + (not TableCheckRequired::value or Policies::template _no_unknown_tables::value)>; _add_set_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert } @@ -116,8 +125,8 @@ namespace sqlpp template void _add_set_impl(Assignment assignment, const std::true_type&) { - static_cast(this)->_insert_value_list._dynamic_columns.emplace_back(simple_column_t{assignment._lhs}); - static_cast(this)->_insert_value_list._dynamic_values.emplace_back(assignment._rhs); + static_cast(this)->_insert_value_list()._dynamic_columns.emplace_back(simple_column_t{assignment._lhs}); + static_cast(this)->_insert_value_list()._dynamic_values.emplace_back(assignment._rhs); } template @@ -127,7 +136,7 @@ namespace sqlpp std::tuple...> _columns; - std::tuple _values; + std::tuple _values; std::tuple _assignments; // FIXME: Need to replace _columns and _values by _assignments (connector-container requires assignments) typename vendor::interpretable_list_t _dynamic_columns; typename vendor::interpretable_list_t _dynamic_values; @@ -136,8 +145,8 @@ namespace sqlpp template struct column_list_t { - using _is_column_list = std::true_type; - using _parameter_tuple_t = std::tuple; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; static_assert(sizeof...(Columns), "at least one column required in columns()"); @@ -148,9 +157,10 @@ namespace sqlpp static_assert(::sqlpp::detail::none_t::value...>::value, "at least one column argument has a must_not_insert flag in its definition"); using _value_tuple_t = std::tuple...>; - using _table_set = typename ::sqlpp::detail::make_joined_set::type; - static_assert(_table_set::size::value == 1, "columns from multiple tables in columns()"); + static_assert(required_tables_of::size::value == 1, "columns from multiple tables in columns()"); + + column_list_t& _insert_value_list() { return *this; } column_list_t(Columns... columns): _columns(simple_column_t{columns}...) @@ -184,7 +194,7 @@ namespace sqlpp template void _add_values_impl(const std::true_type&, Assignments... assignments) { - return static_cast(this)->_insert_value_list._insert_values.emplace_back(vendor::insert_value_t{assignments}...); + return static_cast(this)->_insert_value_list()._insert_values.emplace_back(vendor::insert_value_t{assignments}...); } template @@ -203,9 +213,8 @@ namespace sqlpp struct no_insert_value_list_t { - using _is_noop = std::true_type; - using _provided_tables = ::sqlpp::detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; template struct _methods_t diff --git a/include/sqlpp11/vendor/single_table.h b/include/sqlpp11/vendor/single_table.h index 583c6562..ddf55c72 100644 --- a/include/sqlpp11/vendor/single_table.h +++ b/include/sqlpp11/vendor/single_table.h @@ -38,12 +38,11 @@ namespace sqlpp template struct single_table_t { - using _is_single_table = std::true_type; - using _required_tables = typename Table::_required_tables; - using _provided_tables = typename Table::_provided_tables; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits
; static_assert(is_table_t
::value, "argument has to be a table"); - static_assert(_required_tables::size::value == 0, "table depends on another table"); + static_assert(required_tables_of
::size::value == 0, "table depends on another table"); single_table_t(Table table): _table(table) @@ -55,13 +54,33 @@ namespace sqlpp single_table_t& operator=(single_table_t&&) = default; ~single_table_t() = default; + template + struct _methods_t + { + }; + Table _table; }; struct no_single_table_t { - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; + + template + struct _methods_t + { + using _database_t = typename Policies::_database_t; + template + using _new_statement_t = typename Policies::template _new_statement_t; + + template + auto into(Args... args) + -> _new_statement_t> + { + return { *static_cast(this), single_table_t{args...} }; + } + }; }; // Interpreters diff --git a/include/sqlpp11/vendor/where.h b/include/sqlpp11/vendor/where.h index 9c77059f..eef81374 100644 --- a/include/sqlpp11/vendor/where.h +++ b/include/sqlpp11/vendor/where.h @@ -77,7 +77,7 @@ namespace sqlpp { static_assert(_is_dynamic::value, "add_where can only be called for dynamic_where"); static_assert(is_expression_t::value, "invalid expression argument in add_where()"); - static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in add_where()"); + static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in add_where()"); using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 98f12e6e..9de5e4e2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,12 +7,12 @@ macro (build_and_run arg) endmacro () #build_and_run(InterpretTest) -#build_and_run(InsertTest) +build_and_run(InsertTest) #build_and_run(RemoveTest) #build_and_run(UpdateTest) #build_and_run(SelectTest) -build_and_run(SelectTypeTest) -build_and_run(FunctionTest) +#build_and_run(SelectTypeTest) +#build_and_run(FunctionTest) #build_and_run(PreparedTest) find_package(PythonInterp REQUIRED) From 2a215905fd24ab22a094a72387bfdc3fd4d0e8ec Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 23 May 2014 20:36:13 +0200 Subject: [PATCH 14/65] Migrated remove to being variadic --- include/sqlpp11/basic_expression_operators.h | 7 +- include/sqlpp11/insert.h | 21 +++- include/sqlpp11/remove.h | 124 ++++++++++--------- include/sqlpp11/vendor/expression_fwd.h | 7 ++ include/sqlpp11/vendor/noop.h | 2 + include/sqlpp11/vendor/single_table.h | 8 ++ include/sqlpp11/vendor/using.h | 17 ++- tests/CMakeLists.txt | 4 +- 8 files changed, 111 insertions(+), 79 deletions(-) diff --git a/include/sqlpp11/basic_expression_operators.h b/include/sqlpp11/basic_expression_operators.h index 9e97a044..e306542d 100644 --- a/include/sqlpp11/basic_expression_operators.h +++ b/include/sqlpp11/basic_expression_operators.h @@ -32,16 +32,11 @@ #include #include #include +#include #include namespace sqlpp { - - namespace detail - { - struct boolean; - } - // basic operators template class IsCorrectValueType> struct basic_expression_operators diff --git a/include/sqlpp11/insert.h b/include/sqlpp11/insert.h index 78e5d0f9..b1141ae8 100644 --- a/include/sqlpp11/insert.h +++ b/include/sqlpp11/insert.h @@ -104,16 +104,14 @@ namespace sqlpp using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - using _parameter_tuple_t = std::tuple; using _parameter_list_t = typename make_parameter_list_t::type; - // Constructors - insert_t() + constexpr insert_t() {} - template - insert_t(Statement statement, T term): + template + insert_t(Statement statement, Term term): Policies(detail::pick_arg(statement, term))... {} @@ -181,6 +179,12 @@ namespace sqlpp vendor::no_single_table_t, vendor::no_insert_value_list_t>; + constexpr auto insert() + -> blank_insert_t + { + return { blank_insert_t() }; + } + template constexpr auto insert_into(Table table) -> decltype(blank_insert_t().into(table)) @@ -188,6 +192,13 @@ namespace sqlpp return { blank_insert_t().into(table) }; } + template + constexpr auto dynamic_insert(const Database&) + -> decltype(blank_insert_t()) + { + return { blank_insert_t() }; + } + template constexpr auto dynamic_insert_into(const Database&, Table table) -> decltype(blank_insert_t().into(table)) diff --git a/include/sqlpp11/remove.h b/include/sqlpp11/remove.h index ed12718f..77349668 100644 --- a/include/sqlpp11/remove.h +++ b/include/sqlpp11/remove.h @@ -31,88 +31,90 @@ #include #include #include +#warning: need to use another table provider, since delete can be used with several tables #include #include #include #include #include -#include + +#include +#include namespace sqlpp { - template + template struct remove_t; namespace detail { - template + template struct remove_policies_t { using _database_t = Db; - using _table_t = Table; - using _using_t = Using; - using _extra_tables_t = ExtraTables; - using _where_t = Where; - using _statement_t = remove_t; + using _statement_t = remove_t; - struct _methods_t: - public _using_t::template _methods_t, - public _extra_tables_t::template _methods_t, - public _where_t::template _methods_t + struct _methods_t: public Policies::template _methods_t... {}; - template + template struct _policies_update_t { + static_assert(detail::is_element_of>::value, "policies update for non-policy class detected"); using type = remove_t...>; }; template - using _new_statement_t = typename _policies_update_t::type; + using _new_statement_t = typename _policies_update_t::type; - using _known_tables = detail::make_joined_set_t; + using _all_required_tables = detail::make_joined_set_t...>; + using _all_provided_tables = detail::make_joined_set_t...>; + using _all_extra_tables = detail::make_joined_set_t...>; + + using _known_tables = detail::make_joined_set_t<_all_provided_tables, _all_extra_tables>; template - using _no_unknown_tables = detail::is_subset_of; + using _no_unknown_tables = detail::is_subset_of, _known_tables>; + + // The tables not covered by the from. + using _required_tables = detail::make_difference_set_t< + _all_required_tables, + _all_provided_tables // Hint: extra_tables are not used here because they are just a helper for dynamic .add_*() + >; + + using _traits = make_traits; // FIXME + + struct _recursive_traits + { + using _parameters = std::tuple<>; // FIXME + using _required_tables = _required_tables; + using _provided_tables = detail::type_set<>; + using _extra_tables = detail::type_set<>; + }; }; } // REMOVE - template + template struct remove_t: + public Policies..., public detail::remove_policies_t::_methods_t { using _policies_t = typename detail::remove_policies_t; using _database_t = typename _policies_t::_database_t; - using _table_t = typename _policies_t::_table_t; - using _using_t = typename _policies_t::_using_t; - using _extra_tables_t = typename _policies_t::_extra_tables_t; - using _where_t = typename _policies_t::_where_t; using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - using _parameter_tuple_t = std::tuple; using _parameter_list_t = typename make_parameter_list_t::type; // Constructors - remove_t() + constexpr remove_t() {} - template - remove_t(Statement s, T t): - _table(detail::arg_selector<_table_t>::_(s._table, t)), - _using(detail::arg_selector<_using_t>::_(s._using, t)), - _where(detail::arg_selector<_where_t>::_(s._where, t)) + template + remove_t(Statement statement, Term term): + Policies(detail::pick_arg(statement, term))... {} remove_t(const remove_t&) = default; @@ -132,18 +134,15 @@ namespace sqlpp return _parameter_list_t::size::value; } - template - struct is_table_subset_of_table - { - static constexpr bool value = ::sqlpp::detail::is_subset_of::value; - }; - void _check_consistency() const { +#warning reactivate checks +#if 0 static_assert(is_where_t<_where_t>::value, "cannot run update without having a where condition, use .where(true) to update all rows"); // FIXME: Read more details about what is allowed and what not in SQL DELETE static_assert(is_table_subset_of_table<_where_t>::value, "where requires additional tables"); +#endif } template @@ -163,10 +162,6 @@ namespace sqlpp return {{}, db.prepare_remove(*this)}; } - - _table_t _table; - _using_t _using; - _where_t _where; }; namespace vendor @@ -179,31 +174,46 @@ namespace sqlpp static Context& _(const T& t, Context& context) { context << "DELETE FROM "; - serialize(t._table, context); - serialize(t._using, context); - serialize(t._where, context); + using swallow = int[]; + (void) swallow{(serialize(static_cast(t), context), 0)...}; return context; } }; } - template - using make_remove_t = typename detail::remove_policies_t::_statement_t; + template + using blank_remove_t = remove_t; + + constexpr auto remove() + -> blank_remove_t + { + return { blank_remove_t() }; + } template constexpr auto remove_from(Table table) - -> make_remove_t> + -> decltype(blank_remove_t().from(table)) { - return { make_remove_t(), vendor::single_table_t{table} }; + return { blank_remove_t().from(table) }; + } + + template + constexpr auto dynamic_remove(const Database&) + -> decltype(blank_remove_t()) + { + return { blank_remove_t() }; } template constexpr auto dynamic_remove_from(const Database&, Table table) - -> make_remove_t> + -> decltype(blank_remove_t().from(table)) { - return { make_remove_t(), vendor::single_table_t{table} }; + return { blank_remove_t().from(table) }; } - } #endif diff --git a/include/sqlpp11/vendor/expression_fwd.h b/include/sqlpp11/vendor/expression_fwd.h index 374a4265..796596e5 100644 --- a/include/sqlpp11/vendor/expression_fwd.h +++ b/include/sqlpp11/vendor/expression_fwd.h @@ -29,6 +29,13 @@ namespace sqlpp { + namespace detail + { + struct boolean; + struct integral; + struct floating_point; + } + namespace vendor { namespace op diff --git a/include/sqlpp11/vendor/noop.h b/include/sqlpp11/vendor/noop.h index 1a7bcfe5..05df9dd9 100644 --- a/include/sqlpp11/vendor/noop.h +++ b/include/sqlpp11/vendor/noop.h @@ -28,6 +28,8 @@ #define SQLPP_NOOP_H #include +#include +#include namespace sqlpp { diff --git a/include/sqlpp11/vendor/single_table.h b/include/sqlpp11/vendor/single_table.h index ddf55c72..57dc7fc0 100644 --- a/include/sqlpp11/vendor/single_table.h +++ b/include/sqlpp11/vendor/single_table.h @@ -80,6 +80,14 @@ namespace sqlpp { return { *static_cast(this), single_table_t{args...} }; } + +#warning: remove can operate on several tables at once, so it should not use single_table anyway + template + auto from(Args... args) + -> _new_statement_t> + { + return { *static_cast(this), single_table_t{args...} }; + } }; }; diff --git a/include/sqlpp11/vendor/using.h b/include/sqlpp11/vendor/using.h index f9094408..7a7d7ccf 100644 --- a/include/sqlpp11/vendor/using.h +++ b/include/sqlpp11/vendor/using.h @@ -41,9 +41,10 @@ namespace sqlpp template struct using_t { - using _is_using = std::true_type; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - using _parameter_tuple_t = std::tuple; static_assert(_is_dynamic::value or sizeof...(Tables), "at least one table argument required in using()"); @@ -51,8 +52,7 @@ namespace sqlpp static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an table in using()"); - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::make_joined_set_t; + using_t& _using() { return *this; } using_t(Tables... tables): _tables(tables...) @@ -82,7 +82,7 @@ namespace sqlpp template void _add_using_impl(Table table, const std::true_type&) { - return static_cast(this)->_using._dynamic_tables.emplace_back(table); + return static_cast(this)->_using()._dynamic_tables.emplace_back(table); } template @@ -90,15 +90,14 @@ namespace sqlpp }; - _parameter_tuple_t _tables; + std::tuple _tables; vendor::interpretable_list_t _dynamic_tables; }; struct no_using_t { - using _is_noop = std::true_type; - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; template struct _methods_t diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9de5e4e2..d7fcb902 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,8 +7,8 @@ macro (build_and_run arg) endmacro () #build_and_run(InterpretTest) -build_and_run(InsertTest) -#build_and_run(RemoveTest) +#build_and_run(InsertTest) +build_and_run(RemoveTest) #build_and_run(UpdateTest) #build_and_run(SelectTest) #build_and_run(SelectTypeTest) From c13d514e95d6af816c0b83c7fad446f7d7b5ecdd Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 23 May 2014 21:42:27 +0200 Subject: [PATCH 15/65] Adjusted update to be variadic --- include/sqlpp11/update.h | 108 +++++++++++++------------- include/sqlpp11/vendor/assignment.h | 4 +- include/sqlpp11/vendor/single_table.h | 2 + include/sqlpp11/vendor/update_list.h | 18 +++-- tests/CMakeLists.txt | 4 +- 5 files changed, 69 insertions(+), 67 deletions(-) diff --git a/include/sqlpp11/update.h b/include/sqlpp11/update.h index 5865651a..1368d6a4 100644 --- a/include/sqlpp11/update.h +++ b/include/sqlpp11/update.h @@ -35,82 +35,84 @@ #include #include #include -#include + +#include +#include namespace sqlpp { - template + template struct update_t; namespace detail { - template + template struct update_policies_t { using _database_t = Db; - using _table_t = Table; - using _update_list_t = UpdateList; - using _where_t = Where; - using _statement_t = update_t; + using _statement_t = update_t; - struct _methods_t: - public _update_list_t::template _methods_t, - public _where_t::template _methods_t + struct _methods_t: public Policies::template _methods_t... {}; - template + template struct _policies_update_t { + static_assert(detail::is_element_of>::value, "policies update for non-policy class detected"); using type = update_t...>; }; template - using _new_statement_t = typename _policies_update_t::type; + using _new_statement_t = typename _policies_update_t::type; - using _known_tables = detail::make_joined_set_t; + using _all_required_tables = detail::make_joined_set_t...>; + using _all_provided_tables = detail::make_joined_set_t...>; + using _all_extra_tables = detail::make_joined_set_t...>; + + using _known_tables = detail::make_joined_set_t<_all_provided_tables, _all_extra_tables>; template - using _no_unknown_tables = detail::is_subset_of; + using _no_unknown_tables = detail::is_subset_of, _known_tables>; + // The tables not covered by the from. + using _required_tables = detail::make_difference_set_t< + _all_required_tables, + _all_provided_tables // Hint: extra_tables are not used here because they are just a helper for dynamic .add_*() + >; + + using _traits = make_traits; // FIXME + + struct _recursive_traits + { + using _parameters = std::tuple<>; // FIXME + using _required_tables = _required_tables; + using _provided_tables = detail::type_set<>; + using _extra_tables = detail::type_set<>; + }; }; } - template + // UPDATE + template struct update_t: + public Policies..., public detail::update_policies_t::_methods_t { using _policies_t = typename detail::update_policies_t; using _database_t = typename _policies_t::_database_t; - using _table_t = typename _policies_t::_table_t; - using _update_list_t = typename _policies_t::_update_list_t; - using _where_t = typename _policies_t::_where_t; using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - using _parameter_tuple_t = std::tuple; using _parameter_list_t = typename make_parameter_list_t::type; - static_assert(::sqlpp::detail::is_superset_of::value, "updated columns do not match the table"); - static_assert(::sqlpp::detail::is_superset_of::value, "where condition does not match updated table"); - // Constructors - update_t() + constexpr update_t() {} - template - update_t(Statement s, T t): - _table(detail::arg_selector<_table_t>::_(s._table, t)), - _update_list(detail::arg_selector<_update_list_t>::_(s._update_list, t)), - _where(detail::arg_selector<_where_t>::_(s._where, t)) + template + update_t(Statement statement, Term term): + Policies(detail::pick_arg(statement, term))... {} update_t(const update_t&) = default; @@ -130,18 +132,15 @@ namespace sqlpp return _parameter_list_t::size::value; } - template - struct is_table_subset_of_table - { - static constexpr bool value = ::sqlpp::detail::is_subset_of::value; - }; - void _check_consistency() const { +#warning reactivate tests + /* static_assert(is_where_t<_where_t>::value, "cannot run update without having a where condition, use .where(true) to update all rows"); static_assert(is_table_subset_of_table<_update_list_t>::value, "updates require additional tables"); static_assert(is_table_subset_of_table<_where_t>::value, "where requires additional tables"); + */ } template @@ -161,10 +160,6 @@ namespace sqlpp return {{}, db.prepare_update(*this)}; } - - _table_t _table; - _update_list_t _update_list; - _where_t _where; }; namespace vendor @@ -177,31 +172,32 @@ namespace sqlpp static Context& _(const T& t, Context& context) { context << "UPDATE "; - serialize(t._table, context); - serialize(t._update_list, context); - serialize(t._where, context); + using swallow = int[]; + (void) swallow{(serialize(static_cast(t), context), 0)...}; return context; } }; } - template - using make_update_t = typename detail::update_policies_t::_statement_t; + template + using blank_update_t = update_t; template constexpr auto update(Table table) - -> make_update_t> + -> decltype(blank_update_t().from(table)) { - return { update_t(), vendor::single_table_t{table} }; + return { blank_update_t().from(table) }; } template constexpr auto dynamic_update(const Database&, Table table) - -> make_update_t> + -> decltype(blank_update_t().from(table)) { - return { update_t(), vendor::single_table_t{table} }; + return { blank_update_t().from(table) }; } - } #endif diff --git a/include/sqlpp11/vendor/assignment.h b/include/sqlpp11/vendor/assignment.h index 1899a393..e74a6da5 100644 --- a/include/sqlpp11/vendor/assignment.h +++ b/include/sqlpp11/vendor/assignment.h @@ -59,7 +59,7 @@ namespace sqlpp template bool is_trivial(const T& t) { - return is_trivial_t>::_(t); + return is_trivial_t::_(t); } template @@ -96,7 +96,7 @@ namespace sqlpp static Context& _(const T& t, Context& context) { if ((trivial_value_is_null_t::value - and is_trivial_t>::_(t._rhs)) + and is_trivial(t._rhs)) or (std::is_same::value)) { serialize(simple_column(t._lhs), context); diff --git a/include/sqlpp11/vendor/single_table.h b/include/sqlpp11/vendor/single_table.h index 57dc7fc0..cb4bbfbf 100644 --- a/include/sqlpp11/vendor/single_table.h +++ b/include/sqlpp11/vendor/single_table.h @@ -28,6 +28,8 @@ #define SQLPP_VENDOR_SINGLE_TABLE_H #include +#include +#include #include namespace sqlpp diff --git a/include/sqlpp11/vendor/update_list.h b/include/sqlpp11/vendor/update_list.h index 2034452a..a4755658 100644 --- a/include/sqlpp11/vendor/update_list.h +++ b/include/sqlpp11/vendor/update_list.h @@ -40,9 +40,9 @@ namespace sqlpp template struct update_list_t { - using _is_update_list = std::true_type; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - using _parameter_tuple_t = std::tuple; static_assert(_is_dynamic::value or sizeof...(Assignments), "at least one assignment expression required in set()"); @@ -52,11 +52,16 @@ namespace sqlpp static_assert(::sqlpp::detail::none_t::value...>::value, "at least one assignment is prohibited by its column definition in set()"); +#warning reactivate tests + /* using _column_table_set = typename ::sqlpp::detail::make_joined_set::type; using _value_table_set = typename ::sqlpp::detail::make_joined_set::type; using _table_set = typename ::sqlpp::detail::make_joined_set<_column_table_set, _value_table_set>::type; static_assert(sizeof...(Assignments) ? (_column_table_set::size::value == 1) : true, "set() contains assignments for tables from several columns"); static_assert(::sqlpp::detail::is_subset_of<_value_table_set, _column_table_set>::value, "set() contains values from foreign tables"); + */ + + update_list_t& _update_list() { return *this; } update_list_t(Assignments... assignments): _assignments(assignments...) @@ -97,7 +102,7 @@ namespace sqlpp template void _add_set_impl(Assignment assignment, const std::true_type&) { - return static_cast(this)->_update_list._dynamic_assignments.emplace_back(assignment); + return static_cast(this)->_update_list()._dynamic_assignments.emplace_back(assignment); } template @@ -105,15 +110,14 @@ namespace sqlpp }; - _parameter_tuple_t _assignments; + std::tuple _assignments; typename vendor::interpretable_list_t _dynamic_assignments; }; struct no_update_list_t { - using _is_noop = std::true_type; - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; template struct _methods_t diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d7fcb902..280fe484 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,8 +8,8 @@ endmacro () #build_and_run(InterpretTest) #build_and_run(InsertTest) -build_and_run(RemoveTest) -#build_and_run(UpdateTest) +#build_and_run(RemoveTest) +build_and_run(UpdateTest) #build_and_run(SelectTest) #build_and_run(SelectTypeTest) #build_and_run(FunctionTest) From d11f529bd8ef9801394dd9dcadc33c24b644d469 Mon Sep 17 00:00:00 2001 From: rbock Date: Mon, 26 May 2014 07:42:59 +0200 Subject: [PATCH 16/65] Minor cleanup. --- include/sqlpp11/remove.h | 1 - include/sqlpp11/select.h | 1 - 2 files changed, 2 deletions(-) diff --git a/include/sqlpp11/remove.h b/include/sqlpp11/remove.h index 77349668..2204212b 100644 --- a/include/sqlpp11/remove.h +++ b/include/sqlpp11/remove.h @@ -52,7 +52,6 @@ namespace sqlpp struct remove_policies_t { using _database_t = Db; - using _statement_t = remove_t; struct _methods_t: public Policies::template _methods_t... diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 6292e21c..defdb5ac 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -56,7 +56,6 @@ namespace sqlpp struct select_t; #warning STEPS: -#warning do the same with insert, update and remove #warning deal with different return types in the connector (select could be a single value, update could be a range of rows) namespace detail { From 45ff16600fced04792b04a4a7596204b791ea879 Mon Sep 17 00:00:00 2001 From: rbock Date: Tue, 27 May 2014 09:16:29 +0200 Subject: [PATCH 17/65] Fixed test --- tests/CMakeLists.txt | 4 ++-- tests/SelectTypeTest.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 280fe484..ad2d430a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,9 +9,9 @@ endmacro () #build_and_run(InterpretTest) #build_and_run(InsertTest) #build_and_run(RemoveTest) -build_and_run(UpdateTest) +#build_and_run(UpdateTest) #build_and_run(SelectTest) -#build_and_run(SelectTypeTest) +build_and_run(SelectTypeTest) #build_and_run(FunctionTest) #build_and_run(PreparedTest) diff --git a/tests/SelectTypeTest.cpp b/tests/SelectTypeTest.cpp index 8e1784de..39aa6b52 100644 --- a/tests/SelectTypeTest.cpp +++ b/tests/SelectTypeTest.cpp @@ -312,7 +312,7 @@ int main() { auto s = dynamic_select(db, all_of(t)).dynamic_from().dynamic_where().dynamic_limit().dynamic_offset(); s.add_from(t); - s.add_where(t.alpha > 7 and t.alpha == any(select(t.alpha).from(t).where(t.alpha < 3))); + s.add_where_ntc(t.alpha > 7 and t.alpha == any(select(t.alpha).from(t).where(t.alpha < 3))); s.set_limit(30); s.set_limit(3); std::cerr << "------------------------\n"; From a5457e93f786a145543fdf3929d2e1dab04f4bd3 Mon Sep 17 00:00:00 2001 From: rbock Date: Tue, 27 May 2014 11:20:03 +0200 Subject: [PATCH 18/65] Started to move statement-specific methods into the result provider classes First method is: select_t::as() --- include/sqlpp11/select.h | 20 ++++---------- include/sqlpp11/vendor/select_column_list.h | 30 +++++++++++++++++++++ tests/CMakeLists.txt | 4 +-- tests/SelectTest.cpp | 3 +++ 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index defdb5ac..55077409 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -95,6 +95,10 @@ namespace sqlpp using _result_type_provider = detail::get_last_if; + struct _result_methods_t: public _result_type_provider::template _result_methods_t + {}; + + // A select can be used as a pseudo table if // - at least one column is selected // - the select is complete (leaks no tables) @@ -135,6 +139,7 @@ namespace sqlpp struct select_t: public Policies..., public detail::select_policies_t::_value_type::template expression_operators>, + public detail::select_policies_t::_result_methods_t, public detail::select_policies_t::_methods_t { using _policies_t = typename detail::select_policies_t; @@ -174,21 +179,6 @@ namespace sqlpp ~select_t() = default; // PseudoTable - template - struct _pseudo_table_t - { - using table = typename _result_type_provider::template _pseudo_table_t; - using alias = typename table::template _alias_t; - }; - - template - typename _pseudo_table_t::alias as(const AliasProvider& aliasProvider) const - { - static_assert(_policies_t::_can_be_used_as_table::value, "select cannot be used as table, incomplete from()"); - return typename _pseudo_table_t::table( - *this).as(aliasProvider); - } - const _dynamic_names_t& get_dynamic_names() const { return static_cast(*this)._dynamic_columns._dynamic_expression_names; diff --git a/include/sqlpp11/vendor/select_column_list.h b/include/sqlpp11/vendor/select_column_list.h index ef3ad4e2..89c25263 100644 --- a/include/sqlpp11/vendor/select_column_list.h +++ b/include/sqlpp11/vendor/select_column_list.h @@ -222,6 +222,32 @@ namespace sqlpp void _add_column_impl(NamedExpression namedExpression, const std::false_type&); }; + template + struct _result_methods_t + { + using _statement_t = typename Policies::_statement_t; + + template + struct _deferred_table_t + { + using table = _pseudo_table_t<_statement_t>; + using alias = typename _pseudo_table_t<_statement_t>::template _alias_t; + }; + + template + using _table_t = typename _deferred_table_t::table; + + template + using _alias_t = typename _deferred_table_t::alias; + + template + _alias_t as(const AliasProvider& aliasProvider) const + { + static_assert(Policies::_can_be_used_as_table::value, "statement cannot be used as table, e.g. due to missing tables"); + return _table_t(static_cast(*this)).as(aliasProvider); + } + }; + const select_column_list_t& _column_list() const { return *this; } std::tuple _columns; @@ -277,6 +303,10 @@ namespace sqlpp return { *static_cast(this), ::sqlpp::detail::make_select_column_list_t<_database_t, Args...>{std::tuple_cat(::sqlpp::detail::as_tuple::_(args)...)} }; } }; + + template + struct _result_methods_t + {}; }; // Interpreters diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ad2d430a..71f89d92 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,8 +10,8 @@ endmacro () #build_and_run(InsertTest) #build_and_run(RemoveTest) #build_and_run(UpdateTest) -#build_and_run(SelectTest) -build_and_run(SelectTypeTest) +build_and_run(SelectTest) +#build_and_run(SelectTypeTest) #build_and_run(FunctionTest) #build_and_run(PreparedTest) diff --git a/tests/SelectTest.cpp b/tests/SelectTest.cpp index c82f1dc2..8d336c65 100644 --- a/tests/SelectTest.cpp +++ b/tests/SelectTest.cpp @@ -83,5 +83,8 @@ int main() int64_t a = row.alpha; } + + auto X = select(all_of(t)).from(t).as(t.alpha); + return 0; } From 76fc2fb3975c1ff85b87ca8fe9706e45ac75e0ba Mon Sep 17 00:00:00 2001 From: rbock Date: Tue, 27 May 2014 18:15:37 +0200 Subject: [PATCH 19/65] Moved select-specific stuff into select_column_list This is a major step towards a generic statements and generic statement policies. --- include/sqlpp11/select.h | 63 ++------------------- include/sqlpp11/vendor/select_column_list.h | 45 +++++++++++++++ 2 files changed, 51 insertions(+), 57 deletions(-) diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 55077409..4cdef8de 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -129,6 +129,12 @@ namespace sqlpp using _extra_tables = detail::type_set<>; }; + static void _check_consistency() + { +#warning check for missing terms here, and for missing tables + static_assert(not required_tables_of::size::value, "one sub expression requires tables which are otherwise not known in the statement"); + } + }; } @@ -147,18 +153,8 @@ namespace sqlpp using _traits = make_traits, ::sqlpp::tag::select, tag::expression_if, tag::named_expression_if>; using _recursive_traits = typename _policies_t::_recursive_traits; - using _database_t = Db; - using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - using _result_type_provider = typename _policies_t::_result_type_provider; - using _parameter_tuple_t = std::tuple; - using _parameter_list_t = typename make_parameter_list_t::type; - - template - using _result_row_t = typename _result_type_provider::template _result_row_t; - using _dynamic_names_t = typename _result_type_provider::_dynamic_names_t; - using _requires_braces = std::true_type; using _name_t = typename _result_type_provider::_name_t; @@ -178,53 +174,6 @@ namespace sqlpp select_t& operator=(select_t&& r) = default; ~select_t() = default; - // PseudoTable - const _dynamic_names_t& get_dynamic_names() const - { - return static_cast(*this)._dynamic_columns._dynamic_expression_names; - } - - static constexpr size_t _get_static_no_of_parameters() - { - return _parameter_list_t::size::value; - } - - size_t _get_no_of_parameters() const - { - return _parameter_list_t::size::value; - } - - size_t get_no_of_result_columns() const - { - return _result_type_provider::static_size() + get_dynamic_names().size(); - } - - void _check_consistency() const - { -#warning check for missing terms here, and for missing tables - static_assert(not required_tables_of<_policies_t>::size::value, "one sub expression contains tables which are not in the from()"); - } - - // Execute - template - auto _run(Database& db) const - -> result_t> - { - _check_consistency(); - static_assert(_get_static_no_of_parameters() == 0, "cannot run select directly with parameters, use prepare instead"); - - return {db.select(*this), get_dynamic_names()}; - } - - // Prepare - template - auto _prepare(Database& db) const - -> prepared_select_t - { - _check_consistency(); - - return {{}, get_dynamic_names(), db.prepare_select(*this)}; - } }; namespace vendor diff --git a/include/sqlpp11/vendor/select_column_list.h b/include/sqlpp11/vendor/select_column_list.h index 89c25263..f5be996f 100644 --- a/include/sqlpp11/vendor/select_column_list.h +++ b/include/sqlpp11/vendor/select_column_list.h @@ -165,6 +165,7 @@ namespace sqlpp using _dynamic_t = select_column_list_t>; select_column_list_t& _select_column_list() { return *this; } + const select_column_list_t& _select_column_list() const { return *this; } select_column_list_t(std::tuple columns): _columns(columns) @@ -246,6 +247,50 @@ namespace sqlpp static_assert(Policies::_can_be_used_as_table::value, "statement cannot be used as table, e.g. due to missing tables"); return _table_t(static_cast(*this)).as(aliasProvider); } + const _dynamic_names_t& get_dynamic_names() const + { + return static_cast(this)->_select_column_list()._dynamic_columns._dynamic_expression_names; + } + + static constexpr size_t _get_static_no_of_parameters() + { +#warning need to fix this + return 0; + } + + size_t _get_no_of_parameters() const + { +#warning need to fix this + return 0; + } + + size_t get_no_of_result_columns() const + { + return static_size() + get_dynamic_names().size(); + } + + // Execute + template + auto _run(Db& db) const + -> result_t())), _result_row_t> + { + Policies::_check_consistency(); + static_assert(_get_static_no_of_parameters() == 0, "cannot run select directly with parameters, use prepare instead"); + + return {db.select(static_cast(*this)), get_dynamic_names()}; + } +#if 0 + + // Prepare + template + auto _prepare(Db& db) const + -> prepared_select_t + { + Policies::_check_consistency(); + + return {{}, get_dynamic_names(), db.prepare_select(*this)}; + } +#endif }; From 408e96af4a7305801c6eb01c0b1372e5e26f5530 Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 30 May 2014 10:40:46 +0200 Subject: [PATCH 20/65] Using _member_t to have variadic named members in statements --- include/sqlpp11/detail/pick_arg.h | 10 +- include/sqlpp11/select.h | 19 +- include/sqlpp11/vendor/from.h | 101 +++++-- include/sqlpp11/vendor/noop.h | 6 + include/sqlpp11/vendor/select_column_list.h | 282 +++++++++++--------- include/sqlpp11/vendor/where.h | 178 ++++++++---- tests/SelectTest.cpp | 2 + 7 files changed, 370 insertions(+), 228 deletions(-) diff --git a/include/sqlpp11/detail/pick_arg.h b/include/sqlpp11/detail/pick_arg.h index ca9f5296..6ec48754 100644 --- a/include/sqlpp11/detail/pick_arg.h +++ b/include/sqlpp11/detail/pick_arg.h @@ -34,22 +34,22 @@ namespace sqlpp namespace detail { template - Target pick_arg_impl(Statement statement, Term term, const std::true_type&) + typename Target::_data_t pick_arg_impl(Statement statement, Term term, const std::true_type&) { return term; }; template - Target pick_arg_impl(Statement statement, Term term, const std::false_type&) + typename Target::_data_t pick_arg_impl(Statement statement, Term term, const std::false_type&) { - return static_cast(statement); + return static_cast>(statement)()._data; }; // Returns a statement's term either by picking the term from the statement or using the new term template - Target pick_arg(Statement statement, Term term) + typename Target::_data_t pick_arg(Statement statement, Term term) { - return pick_arg_impl(statement, term, std::is_same()); + return pick_arg_impl(statement, term, std::is_same()); }; } } diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 4cdef8de..6fe927a3 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -93,7 +93,7 @@ namespace sqlpp _all_provided_tables // Hint: extra_tables are not used here because they are just a helper for dynamic .add_*() >; - using _result_type_provider = detail::get_last_if; + using _result_type_provider = detail::get_last_if; struct _result_methods_t: public _result_type_provider::template _result_methods_t {}; @@ -143,7 +143,7 @@ namespace sqlpp typename... Policies > struct select_t: - public Policies..., + public Policies::template _member_t..., public detail::select_policies_t::_value_type::template expression_operators>, public detail::select_policies_t::_result_methods_t, public detail::select_policies_t::_methods_t @@ -165,7 +165,7 @@ namespace sqlpp template select_t(Statement statement, Term term): - Policies(detail::pick_arg(statement, term))... + Policies::template _member_t{{detail::pick_arg(statement, term)}}... {} select_t(const select_t& r) = default; @@ -173,7 +173,6 @@ namespace sqlpp select_t& operator=(const select_t& r) = default; select_t& operator=(select_t&& r) = default; ~select_t() = default; - }; namespace vendor @@ -188,7 +187,7 @@ namespace sqlpp context << "SELECT "; using swallow = int[]; - (void) swallow{(serialize(static_cast(t), context), 0)...}; + (void) swallow{(serialize(static_cast(t)._data, context), 0)...}; return context; } @@ -197,16 +196,16 @@ namespace sqlpp template using blank_select_t = select_t; + vendor::no_offset_t*/>; blank_select_t select() // FIXME: These should be constexpr diff --git a/include/sqlpp11/vendor/from.h b/include/sqlpp11/vendor/from.h index 2a82b4e0..7dfecbb1 100644 --- a/include/sqlpp11/vendor/from.h +++ b/include/sqlpp11/vendor/from.h @@ -37,6 +37,24 @@ namespace sqlpp { namespace vendor { + // FROM DATA + template + struct from_data_t + { + from_data_t(Tables... tables): + _tables(tables...) + {} + + from_data_t(const from_data_t&) = default; + from_data_t(from_data_t&&) = default; + from_data_t& operator=(const from_data_t&) = default; + from_data_t& operator=(from_data_t&&) = default; + ~from_data_t() = default; + + std::tuple _tables; + vendor::interpretable_list_t _dynamic_tables; + }; + // FROM template struct from_t @@ -55,45 +73,52 @@ namespace sqlpp static_assert(required_tables_of::size::value == 0, "at least one table depends on another table"); - from_t& _from() { return *this; } - - from_t(Tables... tables): - _tables(tables...) - {} - - from_t(const from_t&) = default; - from_t(from_t&&) = default; - from_t& operator=(const from_t&) = default; - from_t& operator=(from_t&&) = default; - ~from_t() = default; + // Data + using _data_t = from_data_t; + // Member implementation with data and methods template - struct _methods_t + struct _impl_t { template - void add_from(Table table) + void _add_t(Table table) { - static_assert(_is_dynamic::value, "add_from must not be called for static from()"); - static_assert(is_table_t
::value, "invalid table argument in add_from()"); + static_assert(_is_dynamic::value, "from::add() must not be called for static from()"); + static_assert(is_table_t
::value, "invalid table argument in from::add()"); using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_table_t
::value>; - _add_from_impl(table, ok()); // dispatch to prevent compile messages after the static_assert + _add_impl(table, ok()); // dispatch to prevent compile messages after the static_assert } private: template - void _add_from_impl(Table table, const std::true_type&) + void _add_impl(Table table, const std::true_type&) { - return static_cast(this)->_from()._dynamic_tables.emplace_back(table); + return _data._dynamic_tables.emplace_back(table); } template - void _add_from_impl(Table table, const std::false_type&); + void _add_impl(Table table, const std::false_type&); + + public: + _data_t _data; }; - std::tuple _tables; - vendor::interpretable_list_t _dynamic_tables; + // Member template for adding the named member to a statement + template + struct _member_t + { + _impl_t no_from; + _impl_t& operator()() { return no_from; } + const _impl_t& operator()() const { return no_from; } + }; + + // Additional methods for the statement + template + struct _methods_t + { + }; }; struct no_from_t @@ -101,18 +126,40 @@ namespace sqlpp using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; + // Data + struct _data_t + { + }; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + _impl_t no_from; + _impl_t& operator()() { return no_from; } + const _impl_t& operator()() const { return no_from; } + }; + + // Additional methods for the statement template struct _methods_t { using _database_t = typename Policies::_database_t; template - using _new_statement_t = typename Policies::template _new_statement_t; + using _new_statement_t = typename Policies::template _new_statement_t; template auto from(Args... args) -> _new_statement_t> { - return { *static_cast(this), from_t{args...} }; + return { *static_cast(this), from_data_t{args...} }; } template @@ -120,14 +167,14 @@ namespace sqlpp -> _new_statement_t> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_from must not be called in a static statement"); - return { *static_cast(this), vendor::from_t<_database_t, Args...>{args...} }; + return { *static_cast(this), from_data_t<_database_t, Args...>{args...} }; } }; }; // Interpreters template - struct serializer_t> + struct serializer_t> { using T = from_t; @@ -145,9 +192,9 @@ namespace sqlpp }; template - struct serializer_t + struct serializer_t { - using T = no_from_t; + using T = no_from_t::_data_t; static Context& _(const T& t, Context& context) { diff --git a/include/sqlpp11/vendor/noop.h b/include/sqlpp11/vendor/noop.h index 05df9dd9..aab95d61 100644 --- a/include/sqlpp11/vendor/noop.h +++ b/include/sqlpp11/vendor/noop.h @@ -39,6 +39,12 @@ namespace sqlpp { using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; + + struct _name_t {}; + + template + struct _result_methods_t + {}; }; template diff --git a/include/sqlpp11/vendor/select_column_list.h b/include/sqlpp11/vendor/select_column_list.h index f5be996f..b31367b8 100644 --- a/include/sqlpp11/vendor/select_column_list.h +++ b/include/sqlpp11/vendor/select_column_list.h @@ -44,18 +44,18 @@ namespace sqlpp { namespace detail { - template - struct get_first_argument_if_unique + template + struct select_traits { using _traits = make_traits; struct _name_t {}; }; - template - struct get_first_argument_if_unique + template + struct select_traits { - using _traits = make_traits, tag::select_column_list, tag::return_value, tag::expression, tag::named_expression>; - using _name_t = typename T::_name_t; + using _traits = make_traits, tag::select_column_list, tag::return_value, tag::expression, tag::named_expression>; + using _name_t = typename Column::_name_t; }; } @@ -127,67 +127,54 @@ namespace sqlpp } }; + // SELECTED COLUMNS DATA + template + struct select_column_list_data_t + { + select_column_list_data_t(Columns... columns): + _columns(columns...) + {} - // SELECT COLUMNS + select_column_list_data_t(std::tuple columns): + _columns(columns) + {} + + select_column_list_data_t(const select_column_list_data_t&) = default; + select_column_list_data_t(select_column_list_data_t&&) = default; + select_column_list_data_t& operator=(const select_column_list_data_t&) = default; + select_column_list_data_t& operator=(select_column_list_data_t&&) = default; + ~select_column_list_data_t() = default; + + std::tuple _columns; + dynamic_select_column_list _dynamic_columns; + }; + + + // SELECTED COLUMNS template struct select_column_list_t { - // get_first_argument_if_unique is kind of ugly - using _traits = typename ::sqlpp::detail::get_first_argument_if_unique::_traits; + using _traits = typename ::sqlpp::detail::select_traits::_traits; using _recursive_traits = make_recursive_traits; - using _name_t = typename ::sqlpp::detail::get_first_argument_if_unique::_name_t; + using _name_t = typename ::sqlpp::detail::select_traits::_name_t; using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected"); - template - using is_valid_expression_t = std::integral_constant::value or is_multi_column_t::value>; - static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a named expression"); + static_assert(::sqlpp::detail::all_t<(is_named_expression_t::value or is_multi_column_t::value)...>::value, "at least one argument is not a named expression"); static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate name detected"); struct _column_type {}; + // Data + using _data_t = select_column_list_data_t; - template - using _result_row_t = typename std::conditional<_is_dynamic::value, - dynamic_result_row_t...>, - result_row_t...>>::type; - - using _dynamic_names_t = typename dynamic_select_column_list::_names_t; - - template - using _pseudo_table_t = select_pseudo_table_t; - - template - using _dynamic_t = select_column_list_t>; - - select_column_list_t& _select_column_list() { return *this; } - const select_column_list_t& _select_column_list() const { return *this; } - - select_column_list_t(std::tuple columns): - _columns(columns) - {} - - select_column_list_t(Columns... columns): - _columns(columns...) - {} - - select_column_list_t(const select_column_list_t&) = default; - select_column_list_t(select_column_list_t&&) = default; - select_column_list_t& operator=(const select_column_list_t&) = default; - select_column_list_t& operator=(select_column_list_t&&) = default; - ~select_column_list_t() = default; - - static constexpr size_t static_size() - { - return sizeof...(Columns); - } - + // Member implementation with data and methods template - struct _methods_t + struct _impl_t { template void add_column_ntc(NamedExpression namedExpression) @@ -205,98 +192,126 @@ namespace sqlpp static_assert(not ::sqlpp::detail::is_element_of::value, "a column of this name is present in the select already"); using ok = ::sqlpp::detail::all_t< - _is_dynamic::value, - is_named_expression_t::value - >; + _is_dynamic::value, + is_named_expression_t::value + >; _add_column_impl(namedExpression, ok()); // dispatch to prevent compile messages after the static_assert } - private: + //private: template void _add_column_impl(NamedExpression namedExpression, const std::true_type&) { - return static_cast(this)->_select_column_list()._dynamic_columns.emplace_back(namedExpression); + return _data._dynamic_columns.emplace_back(namedExpression); } template void _add_column_impl(NamedExpression namedExpression, const std::false_type&); + + public: + _data_t _data; }; + // Member template for adding the named member to a statement template - struct _result_methods_t - { - using _statement_t = typename Policies::_statement_t; + struct _member_t + { + _impl_t selected_columns; + _impl_t& operator()() { return selected_columns; } + const _impl_t& operator()() const { return selected_columns; } + }; - template - struct _deferred_table_t + // Additional methods for the statement + template + struct _methods_t + { + }; + + // Result methods + template + struct _result_methods_t + { + using _statement_t = typename Policies::_statement_t; + + const _statement_t& _get_statement() const { - using table = _pseudo_table_t<_statement_t>; - using alias = typename _pseudo_table_t<_statement_t>::template _alias_t; - }; - - template - using _table_t = typename _deferred_table_t::table; - - template - using _alias_t = typename _deferred_table_t::alias; - - template - _alias_t as(const AliasProvider& aliasProvider) const - { - static_assert(Policies::_can_be_used_as_table::value, "statement cannot be used as table, e.g. due to missing tables"); - return _table_t(static_cast(*this)).as(aliasProvider); + return static_cast(*this); } - const _dynamic_names_t& get_dynamic_names() const - { - return static_cast(this)->_select_column_list()._dynamic_columns._dynamic_expression_names; - } - static constexpr size_t _get_static_no_of_parameters() - { + template + using _result_row_t = typename std::conditional<_is_dynamic::value, + dynamic_result_row_t...>, + result_row_t...>>::type; + + using _dynamic_names_t = typename dynamic_select_column_list::_names_t; + + template + struct _deferred_table_t + { + using table = select_pseudo_table_t<_statement_t, Columns...>; + using alias = typename table::template _alias_t; + }; + + template + using _table_t = typename _deferred_table_t::table; + + template + using _alias_t = typename _deferred_table_t::alias; + + template + _alias_t as(const AliasProvider& aliasProvider) const + { + static_assert(Policies::_can_be_used_as_table::value, "statement cannot be used as table, e.g. due to missing tables"); + return _table_t(_get_statement()).as(aliasProvider); + } + + const _dynamic_names_t& get_dynamic_names() const + { + return _get_statement().selected_columns._data._dynamic_columns._dynamic_expression_names; + } + + static constexpr size_t _get_static_no_of_parameters() + { #warning need to fix this - return 0; - } + return 0; + } - size_t _get_no_of_parameters() const - { + size_t _get_no_of_parameters() const + { #warning need to fix this - return 0; - } + return 0; + } - size_t get_no_of_result_columns() const - { - return static_size() + get_dynamic_names().size(); - } + size_t get_no_of_result_columns() const + { + return sizeof...(Columns) + get_dynamic_names().size(); + } - // Execute - template - auto _run(Db& db) const - -> result_t())), _result_row_t> - { - Policies::_check_consistency(); - static_assert(_get_static_no_of_parameters() == 0, "cannot run select directly with parameters, use prepare instead"); + // Execute + template + auto _run(Db& db) const + -> result_t> + { + Policies::_check_consistency(); + static_assert(_get_static_no_of_parameters() == 0, "cannot run select directly with parameters, use prepare instead"); - return {db.select(static_cast(*this)), get_dynamic_names()}; - } + return {db.select(_get_statement()), get_dynamic_names()}; + } #if 0 - // Prepare - template - auto _prepare(Db& db) const - -> prepared_select_t - { - Policies::_check_consistency(); + // Prepare + template + auto _prepare(Db& db) const + -> prepared_select_t + { + Policies::_check_consistency(); - return {{}, get_dynamic_names(), db.prepare_select(*this)}; - } + return {{}, get_dynamic_names(), db.prepare_select(*this)}; + } #endif - }; + }; - - const select_column_list_t& _column_list() const { return *this; } - std::tuple _columns; - dynamic_select_column_list _dynamic_columns; }; } @@ -315,29 +330,42 @@ namespace sqlpp using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; - template - using _result_row_t = ::sqlpp::result_row_t; - using _dynamic_names_t = typename dynamic_select_column_list::_names_t; struct _name_t {}; - template - struct _pseudo_table_t + // Data + struct _data_t + { + }; + + // Member implementation with data and methods + template + struct _impl_t { - static_assert(wrong_t::value, "Cannot use a select as a table when no columns have been selected yet"); + _data_t _data; }; + // Member template for adding the named member to a statement + template + struct _member_t + { + _impl_t no_selected_columns; + _impl_t& operator()() { return no_selected_columns; } + const _impl_t& operator()() const { return no_selected_columns; } + }; + + // Additional methods for the statement template struct _methods_t { using _database_t = typename Policies::_database_t; template - using _new_statement_t = typename Policies::template _new_statement_t; + using _new_statement_t = typename Policies::template _new_statement_t; template auto columns(Args... args) -> _new_statement_t<::sqlpp::detail::make_select_column_list_t> { - return { *static_cast(this), ::sqlpp::detail::make_select_column_list_t{std::tuple_cat(::sqlpp::detail::as_tuple::_(args)...)} }; + return { *static_cast(this), typename ::sqlpp::detail::make_select_column_list_t::_data_t{std::tuple_cat(::sqlpp::detail::as_tuple::_(args)...)} }; } template @@ -345,20 +373,16 @@ namespace sqlpp -> _new_statement_t<::sqlpp::detail::make_select_column_list_t<_database_t, Args...>> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_columns must not be called in a static statement"); - return { *static_cast(this), ::sqlpp::detail::make_select_column_list_t<_database_t, Args...>{std::tuple_cat(::sqlpp::detail::as_tuple::_(args)...)} }; + return { *static_cast(this), typename ::sqlpp::detail::make_select_column_list_t<_database_t, Args...>::_data_t{std::tuple_cat(::sqlpp::detail::as_tuple::_(args)...)} }; } }; - - template - struct _result_methods_t - {}; }; // Interpreters template - struct serializer_t> + struct serializer_t> { - using T = select_column_list_t; + using T = select_column_list_data_t; static Context& _(const T& t, Context& context) { @@ -374,9 +398,9 @@ namespace sqlpp }; template - struct serializer_t + struct serializer_t { - using T = no_select_column_list_t; + using T = typename no_select_column_list_t::_data_t; static Context& _(const T& t, Context& context) { diff --git a/include/sqlpp11/vendor/where.h b/include/sqlpp11/vendor/where.h index eef81374..08687359 100644 --- a/include/sqlpp11/vendor/where.h +++ b/include/sqlpp11/vendor/where.h @@ -38,96 +38,160 @@ namespace sqlpp { namespace vendor { - // WHERE + template + struct where_data_t + { + where_data_t(Expressions... expressions): + _expressions(expressions...) + {} + + where_data_t(const where_data_t&) = default; + where_data_t(where_data_t&&) = default; + where_data_t& operator=(const where_data_t&) = default; + where_data_t& operator=(where_data_t&&) = default; + ~where_data_t() = default; + + std::tuple _expressions; + vendor::interpretable_list_t _dynamic_expressions; + }; + + // WHERE(EXPR) template struct where_t { using _traits = make_traits; using _recursive_traits = make_recursive_traits; +#warning: is_dynamic should be using a template alias (making it easier to replace the logic) using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression argument required in where()"); static_assert(sqlpp::detail::none_t::value...>::value, "at least one argument is an assignment in where()"); static_assert(sqlpp::detail::all_t::value...>::value, "at least one argument is not valid expression in where()"); - where_t& _where() { return *this; } + // Data + using _data_t = where_data_t; - where_t(Expressions... expressions): - _expressions(expressions...) - {} + // Member implementation with data and methods + template + struct _impl_t + { + template + void add_ntc(Expression expression) + { + add(expression); + } - where_t(const where_t&) = default; - where_t(where_t&&) = default; - where_t& operator=(const where_t&) = default; - where_t& operator=(where_t&&) = default; - ~where_t() = default; + template + void add(Expression expression) + { + static_assert(_is_dynamic::value, "where::add() can only be called for dynamic_where"); + static_assert(is_expression_t::value, "invalid expression argument in where::add()"); + static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in where::add()"); + using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; + + _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert + } + + private: + template + void _add_impl(Expression expression, const std::true_type&) + { + return _data._dynamic_expressions.emplace_back(expression); + } + + template + void _add_impl(Expression expression, const std::false_type&); + + public: + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + _impl_t where; + _impl_t& operator()() { return where; } + const _impl_t& operator()() const { return where; } + }; + + // Additional methods for the statement template struct _methods_t { - template - void add_where_ntc(Expression expression) - { - add_where(expression); - } - - template - void add_where(Expression expression) - { - static_assert(_is_dynamic::value, "add_where can only be called for dynamic_where"); - static_assert(is_expression_t::value, "invalid expression argument in add_where()"); - static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in add_where()"); - - using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; - - _add_where_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert - } - - private: - template - void _add_where_impl(Expression expression, const std::true_type&) - { - return static_cast(this)->_where()._dynamic_expressions.emplace_back(expression); - } - - template - void _add_where_impl(Expression expression, const std::false_type&); }; - - std::tuple _expressions; - vendor::interpretable_list_t _dynamic_expressions; }; + template<> + struct where_data_t + { + bool _condition; + }; + + // WHERE(BOOL) template<> struct where_t { using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; - where_t(bool condition): - _condition(condition) - {} + // Data + using _data_t = where_data_t; - where_t(const where_t&) = default; - where_t(where_t&&) = default; - where_t& operator=(const where_t&) = default; - where_t& operator=(where_t&&) = default; - ~where_t() = default; + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; + // Member template for adding the named member to a statement + template + struct _member_t + { + _impl_t where; + _impl_t& operator()() { return where; } + const _impl_t& operator()() const { return where; } + }; + + // Additional methods for the statement template struct _methods_t { }; - bool _condition; }; + // NO WHERE YET struct no_where_t { using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; + // Data + struct _data_t + { + }; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + _impl_t no_where; + _impl_t& operator()() { return no_where; } + const _impl_t& operator()() const { return no_where; } + }; + + // Additional methods for the statement template struct _methods_t { @@ -139,7 +203,7 @@ namespace sqlpp auto where(Args... args) -> _new_statement_t> { - return { *static_cast(this), where_t{args...} }; + return { *static_cast(this), where_data_t{args...} }; } template @@ -147,16 +211,16 @@ namespace sqlpp -> _new_statement_t> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_where must not be called in a static statement"); - return { *static_cast(this), vendor::where_t<_database_t, Args...>{args...} }; + return { *static_cast(this), where_data_t<_database_t, Args...>{args...} }; } }; }; // Interpreters template - struct serializer_t> + struct serializer_t> { - using T = where_t; + using T = where_data_t; static Context& _(const T& t, Context& context) { @@ -172,9 +236,9 @@ namespace sqlpp }; template - struct serializer_t> + struct serializer_t> { - using T = where_t; + using T = where_data_t; static Context& _(const T& t, Context& context) { @@ -185,9 +249,9 @@ namespace sqlpp }; template - struct serializer_t + struct serializer_t { - using T = no_where_t; + using T = typename no_where_t::_data_t; static Context& _(const T& t, Context& context) { diff --git a/tests/SelectTest.cpp b/tests/SelectTest.cpp index 8d336c65..34b675db 100644 --- a/tests/SelectTest.cpp +++ b/tests/SelectTest.cpp @@ -55,6 +55,7 @@ int main() const std::string b = row.beta; } +#if 0 for (const auto& row : db(select(all_of(t).as(t)).from(t).where(true))) { int64_t a = row.tabBar.alpha; @@ -85,6 +86,7 @@ int main() auto X = select(all_of(t)).from(t).as(t.alpha); +#endif return 0; } From 98bb9a7db7ec715e212f1874fad5ca1c747cb100 Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 30 May 2014 12:48:51 +0200 Subject: [PATCH 21/65] Added policies into members What a fight... --- include/sqlpp11/detail/pick_arg.h | 2 +- include/sqlpp11/select.h | 14 ++- include/sqlpp11/vendor/extra_tables.h | 69 +++++++++-- include/sqlpp11/vendor/from.h | 40 ++++--- include/sqlpp11/vendor/noop.h | 14 +++ include/sqlpp11/vendor/select_column_list.h | 46 +++---- include/sqlpp11/vendor/select_flag_list.h | 125 ++++++++++++++------ include/sqlpp11/vendor/where.h | 91 +++++++------- tests/SelectTest.cpp | 23 ++-- 9 files changed, 279 insertions(+), 145 deletions(-) diff --git a/include/sqlpp11/detail/pick_arg.h b/include/sqlpp11/detail/pick_arg.h index 6ec48754..10cd512b 100644 --- a/include/sqlpp11/detail/pick_arg.h +++ b/include/sqlpp11/detail/pick_arg.h @@ -42,7 +42,7 @@ namespace sqlpp template typename Target::_data_t pick_arg_impl(Statement statement, Term term, const std::false_type&) { - return static_cast>(statement)()._data; + return Target::_get_member(statement)._data; }; // Returns a statement's term either by picking the term from the statement or using the new term diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 6fe927a3..2a9561f2 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -143,7 +143,7 @@ namespace sqlpp typename... Policies > struct select_t: - public Policies::template _member_t..., + public Policies::template _member_t>..., public detail::select_policies_t::_value_type::template expression_operators>, public detail::select_policies_t::_result_methods_t, public detail::select_policies_t::_methods_t @@ -165,7 +165,11 @@ namespace sqlpp template select_t(Statement statement, Term term): - Policies::template _member_t{{detail::pick_arg(statement, term)}}... + Policies::template _member_t<_policies_t>{ + typename Policies::template _impl_t<_policies_t>{ + detail::pick_arg>(statement, term) + }}... + //Policies::template _member_t<_policies_t>{{detail::pick_arg>(statement, term)}}... {} select_t(const select_t& r) = default; @@ -196,10 +200,10 @@ namespace sqlpp template using blank_select_t = select_t + struct extra_tables_data_t + { + extra_tables_data_t() + {} + + extra_tables_data_t(const extra_tables_data_t&) = default; + extra_tables_data_t(extra_tables_data_t&&) = default; + extra_tables_data_t& operator=(const extra_tables_data_t&) = default; + extra_tables_data_t& operator=(extra_tables_data_t&&) = default; + ~extra_tables_data_t() = default; + + }; + // EXTRA_TABLES template struct extra_tables_t @@ -56,26 +70,59 @@ namespace sqlpp static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in extra_tables()"); static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a table or join in extra_tables()"); - extra_tables_t() - {} + // Data + using _data_t = extra_tables_data_t; - extra_tables_t(const extra_tables_t&) = default; - extra_tables_t(extra_tables_t&&) = default; - extra_tables_t& operator=(const extra_tables_t&) = default; - extra_tables_t& operator=(extra_tables_t&&) = default; - ~extra_tables_t() = default; + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; + // Member template for adding the named member to a statement + template + struct _member_t + { + _impl_t extra_tables; + _impl_t& operator()() { return extra_tables; } + const _impl_t& operator()() const { return extra_tables; } + }; + + // Additional methods for the statement template struct _methods_t { }; }; + // NO EXTRA TABLES YET struct no_extra_tables_t { using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; + // Data + struct _data_t + { + }; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + _impl_t no_extra_tables_t; + _impl_t& operator()() { return no_extra_tables_t; } + const _impl_t& operator()() const { return no_extra_tables_t; } + }; + template struct _methods_t { @@ -86,14 +133,14 @@ namespace sqlpp auto extra_tables(Args...) -> _new_statement_t> { - return { *static_cast(this), extra_tables_t{} }; + return { *static_cast(this), extra_tables_data_t{} }; } }; }; // Interpreters template - struct serializer_t> + struct serializer_t> { using T = extra_tables_t; @@ -104,9 +151,9 @@ namespace sqlpp }; template - struct serializer_t + struct serializer_t { - using T = no_extra_tables_t; + using T = typename no_extra_tables_t::_data_t; static Context& _(const T& t, Context& context) { diff --git a/include/sqlpp11/vendor/from.h b/include/sqlpp11/vendor/from.h index 7dfecbb1..0c3fb76a 100644 --- a/include/sqlpp11/vendor/from.h +++ b/include/sqlpp11/vendor/from.h @@ -81,10 +81,11 @@ namespace sqlpp struct _impl_t { template - void _add_t(Table table) + void add(Table table) { static_assert(_is_dynamic::value, "from::add() must not be called for static from()"); static_assert(is_table_t
::value, "invalid table argument in from::add()"); +#warning need to check if table is already known using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_table_t
::value>; @@ -109,9 +110,17 @@ namespace sqlpp template struct _member_t { - _impl_t no_from; - _impl_t& operator()() { return no_from; } - const _impl_t& operator()() const { return no_from; } + using _data_t = from_data_t; + + _impl_t from; + _impl_t& operator()() { return from; } + const _impl_t& operator()() const { return from; } + + template + static auto _get_member(T t) -> decltype(t.from) + { + return t.from; + } }; // Additional methods for the statement @@ -127,9 +136,7 @@ namespace sqlpp using _recursive_traits = make_recursive_traits<>; // Data - struct _data_t - { - }; + using _data_t = no_data_t; // Member implementation with data and methods template @@ -142,9 +149,17 @@ namespace sqlpp template struct _member_t { + using _data_t = no_data_t; + _impl_t no_from; _impl_t& operator()() { return no_from; } const _impl_t& operator()() const { return no_from; } + + template + static auto _get_member(T t) -> decltype(t.no_from) + { + return t.no_from; + } }; // Additional methods for the statement @@ -191,17 +206,6 @@ namespace sqlpp } }; - template - struct serializer_t - { - using T = no_from_t::_data_t; - - static Context& _(const T& t, Context& context) - { - return context; - } - }; - } } diff --git a/include/sqlpp11/vendor/noop.h b/include/sqlpp11/vendor/noop.h index aab95d61..8ed22a75 100644 --- a/include/sqlpp11/vendor/noop.h +++ b/include/sqlpp11/vendor/noop.h @@ -35,6 +35,20 @@ namespace sqlpp { namespace vendor { +#warning: Need extra include file for no_data + struct no_data_t {}; + + template + struct serializer_t + { + using T = no_data_t; + + static Context& _(const T& t, Context& context) + { + return context; + } + }; + struct noop { using _traits = make_traits; diff --git a/include/sqlpp11/vendor/select_column_list.h b/include/sqlpp11/vendor/select_column_list.h index b31367b8..42c8a722 100644 --- a/include/sqlpp11/vendor/select_column_list.h +++ b/include/sqlpp11/vendor/select_column_list.h @@ -177,17 +177,17 @@ namespace sqlpp struct _impl_t { template - void add_column_ntc(NamedExpression namedExpression) + void add_ntc(NamedExpression namedExpression) { - add_column(namedExpression); + add(namedExpression); } template - void add_column(NamedExpression namedExpression) + void add(NamedExpression namedExpression) { - static_assert(_is_dynamic::value, "add_column can only be called for dynamic_column"); - static_assert(is_named_expression_t::value, "invalid named expression argument in add_column()"); - static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "named expression uses tables unknown to this statement in add_column()"); + static_assert(_is_dynamic::value, "selected_columns::add() can only be called for dynamic_column"); + static_assert(is_named_expression_t::value, "invalid named expression argument in selected_columns::add()"); + static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "named expression uses tables unknown to this statement in selected_columns::add()"); using column_names = ::sqlpp::detail::make_type_set_t; static_assert(not ::sqlpp::detail::is_element_of::value, "a column of this name is present in the select already"); @@ -196,12 +196,12 @@ namespace sqlpp is_named_expression_t::value >; - _add_column_impl(namedExpression, ok()); // dispatch to prevent compile messages after the static_assert + _add_impl(namedExpression, ok()); // dispatch to prevent compile messages after the static_assert } //private: template - void _add_column_impl(NamedExpression namedExpression, const std::true_type&) + void _add_impl(NamedExpression namedExpression, const std::true_type&) { return _data._dynamic_columns.emplace_back(namedExpression); } @@ -217,9 +217,17 @@ namespace sqlpp template struct _member_t { + using _data_t = select_column_list_data_t; + _impl_t selected_columns; _impl_t& operator()() { return selected_columns; } const _impl_t& operator()() const { return selected_columns; } + + template + static auto _get_member(T t) -> decltype(t.selected_columns) + { + return t.selected_columns; + } }; // Additional methods for the statement @@ -333,9 +341,7 @@ namespace sqlpp struct _name_t {}; // Data - struct _data_t - { - }; + using _data_t = no_data_t; // Member implementation with data and methods template @@ -348,9 +354,17 @@ namespace sqlpp template struct _member_t { + using _data_t = no_data_t; + _impl_t no_selected_columns; _impl_t& operator()() { return no_selected_columns; } const _impl_t& operator()() const { return no_selected_columns; } + + template + static auto _get_member(T t) -> decltype(t.no_selected_columns) + { + return t.no_selected_columns; + } }; // Additional methods for the statement @@ -397,16 +411,6 @@ namespace sqlpp } }; - template - struct serializer_t - { - using T = typename no_select_column_list_t::_data_t; - - static Context& _(const T& t, Context& context) - { - return context; - } - }; } } diff --git a/include/sqlpp11/vendor/select_flag_list.h b/include/sqlpp11/vendor/select_flag_list.h index 5a7e2cf9..111d24ee 100644 --- a/include/sqlpp11/vendor/select_flag_list.h +++ b/include/sqlpp11/vendor/select_flag_list.h @@ -38,6 +38,24 @@ namespace sqlpp { namespace vendor { + // SELECTED COLUMNS DATA + template + struct select_flag_list_data_t + { + select_flag_list_data_t(Flags... flags): + _flags(flags...) + {} + + select_flag_list_data_t(const select_flag_list_data_t&) = default; + select_flag_list_data_t(select_flag_list_data_t&&) = default; + select_flag_list_data_t& operator=(const select_flag_list_data_t&) = default; + select_flag_list_data_t& operator=(select_flag_list_data_t&&) = default; + ~select_flag_list_data_t() = default; + + std::tuple _flags; + vendor::interpretable_list_t _dynamic_flags; + }; + // SELECT FLAGS template struct select_flag_list_t @@ -51,53 +69,67 @@ namespace sqlpp static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a select flag in select flag list"); - select_flag_list_t& _select_flag_list() { return *this; } - - select_flag_list_t(Flags... flags): - _flags(flags...) - {} - - select_flag_list_t(const select_flag_list_t&) = default; - select_flag_list_t(select_flag_list_t&&) = default; - select_flag_list_t& operator=(const select_flag_list_t&) = default; - select_flag_list_t& operator=(select_flag_list_t&&) = default; - ~select_flag_list_t() = default; + // Data + using _data_t = select_flag_list_data_t; + // Member implementation with data and methods template - struct _methods_t + struct _impl_t { template - void add_flag_ntc(Flag flag) + void add_ntc(Flag flag) { - add_flag(flag); + add(flag); } template - void add_flag(Flag flag) + void add(Flag flag) { - static_assert(_is_dynamic::value, "add_flag must not be called for static select flags"); - static_assert(is_select_flag_t::value, "invalid select flag argument in add_flag()"); - static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "flag uses tables unknown to this statement in add_flag()"); + static_assert(_is_dynamic::value, "select_flags::add() must not be called for static select flags"); + static_assert(is_select_flag_t::value, "invalid select flag argument in select_flags::add()"); + static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "flag uses tables unknown to this statement in select_flags::add()"); using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_select_flag_t::value>; - _add_flag_impl(flag, ok()); // dispatch to prevent compile messages after the static_assert + _add_impl(flag, ok()); // dispatch to prevent compile messages after the static_assert } private: template - void _add_flag_impl(Flag flag, const std::true_type&) + void _add_impl(Flag flag, const std::true_type&) { return static_cast(this)->_select_flag_list()._dynamic_flags.emplace_back(flag); } template - void _add_flag_impl(Flag flag, const std::false_type&); + void _add_impl(Flag flag, const std::false_type&); + public: + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = select_flag_list_data_t; + + _impl_t select_flags; + _impl_t& operator()() { return select_flags; } + const _impl_t& operator()() const { return select_flags; } + + template + static auto _get_member(T t) -> decltype(t.select_flags) + { + return t.select_flags; + } + }; + + // Additional methods for the statement + template + struct _methods_t + { }; - const select_flag_list_t& _flag_list() const { return *this; } - std::tuple _flags; - vendor::interpretable_list_t _dynamic_flags; }; struct no_select_flag_list_t @@ -105,6 +137,33 @@ namespace sqlpp using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; + + _impl_t no_select_flags; + _impl_t& operator()() { return no_select_flags; } + const _impl_t& operator()() const { return no_select_flags; } + + template + static auto _get_member(T t) -> decltype(t.no_select_flags) + { + return t.no_select_flags; + } + }; + template struct _methods_t { @@ -116,7 +175,7 @@ namespace sqlpp auto flags(Args... args) -> _new_statement_t> { - return { *static_cast(this), select_flag_list_t{args...} }; + return { *static_cast(this), select_flag_list_data_t{args...} }; } template @@ -124,7 +183,7 @@ namespace sqlpp -> _new_statement_t> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_flags must not be called in a static statement"); - return { *static_cast(this), vendor::select_flag_list_t<_database_t, Args...>{args...} }; + return { *static_cast(this), select_flag_list_data_t<_database_t, Args...>{args...} }; } }; }; @@ -132,9 +191,9 @@ namespace sqlpp // Interpreters template - struct serializer_t> + struct serializer_t> { - using T = select_flag_list_t; + using T = select_flag_list_data_t; static Context& _(const T& t, Context& context) { @@ -148,16 +207,6 @@ namespace sqlpp } }; - template - struct serializer_t - { - using T = no_select_flag_list_t; - - static Context& _(const T& t, Context& context) - { - return context; - } - }; } } diff --git a/include/sqlpp11/vendor/where.h b/include/sqlpp11/vendor/where.h index 08687359..4c164b34 100644 --- a/include/sqlpp11/vendor/where.h +++ b/include/sqlpp11/vendor/where.h @@ -75,38 +75,40 @@ namespace sqlpp // Member implementation with data and methods template struct _impl_t - { - template - void add_ntc(Expression expression) - { - add(expression); - } + { + using _data_t = where_data_t; - template - void add(Expression expression) - { - static_assert(_is_dynamic::value, "where::add() can only be called for dynamic_where"); - static_assert(is_expression_t::value, "invalid expression argument in where::add()"); - static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in where::add()"); + template + void add_ntc(Expression expression) + { + add(expression); + } - using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; + template + void add(Expression expression) + { + static_assert(_is_dynamic::value, "where::add() can only be called for dynamic_where"); + static_assert(is_expression_t::value, "invalid expression argument in where::add()"); + static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in where::add()"); - _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert - } + using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; - private: - template - void _add_impl(Expression expression, const std::true_type&) - { - return _data._dynamic_expressions.emplace_back(expression); - } + _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert + } - template - void _add_impl(Expression expression, const std::false_type&); + private: + template + void _add_impl(Expression expression, const std::true_type&) + { + return _data._dynamic_expressions.emplace_back(expression); + } - public: - _data_t _data; - }; + template + void _add_impl(Expression expression, const std::false_type&); + + public: + _data_t _data; + }; // Member template for adding the named member to a statement template @@ -115,6 +117,12 @@ namespace sqlpp _impl_t where; _impl_t& operator()() { return where; } const _impl_t& operator()() const { return where; } + + template + static auto _get_member(T t) -> decltype(t.where) + { + return t.where; + } }; // Additional methods for the statement @@ -151,9 +159,17 @@ namespace sqlpp template struct _member_t { + using _data_t = where_data_t; + _impl_t where; _impl_t& operator()() { return where; } const _impl_t& operator()() const { return where; } + + template + static auto _get_member(T t) -> decltype(t.where) + { + return t.where; + } }; // Additional methods for the statement @@ -171,9 +187,7 @@ namespace sqlpp using _recursive_traits = make_recursive_traits<>; // Data - struct _data_t - { - }; + using _data_t = no_data_t; // Member implementation with data and methods template @@ -186,9 +200,17 @@ namespace sqlpp template struct _member_t { + using _data_t = no_data_t; + _impl_t no_where; _impl_t& operator()() { return no_where; } const _impl_t& operator()() const { return no_where; } + + template + static auto _get_member(T t) -> decltype(t.no_where) + { + return t.no_where; + } }; // Additional methods for the statement @@ -248,17 +270,6 @@ namespace sqlpp } }; - template - struct serializer_t - { - using T = typename no_where_t::_data_t; - - static Context& _(const T& t, Context& context) - { - return context; - } - }; - } } diff --git a/tests/SelectTest.cpp b/tests/SelectTest.cpp index 34b675db..efa7e67a 100644 --- a/tests/SelectTest.cpp +++ b/tests/SelectTest.cpp @@ -49,13 +49,14 @@ int main() test::TabFoo f; test::TabBar t; + sqlpp::select(t.alpha).flags(sqlpp::all).from(t); for (const auto& row : db(select(all_of(t)).from(t).where(true))) { int64_t a = row.alpha; const std::string b = row.beta; } - #if 0 + for (const auto& row : db(select(all_of(t).as(t)).from(t).where(true))) { int64_t a = row.tabBar.alpha; @@ -69,16 +70,16 @@ int main() const bool g = row.gamma; } - auto s = dynamic_select(db).dynamic_columns(all_of(t)).dynamic_flags().dynamic_from(t).extra_tables(f,t).dynamic_where().dynamic_group_by(t.alpha).dynamic_order_by().dynamic_having(t.gamma).dynamic_limit().dynamic_offset(); - s.add_flag(sqlpp::distinct); - s.add_column(f.omega); - s.add_from(f); - s.add_where(t.alpha > 7); - s.add_having(t.alpha > 7); - s.set_limit(3); - s.set_offset(3); - s.add_group_by(t.beta); - s.add_order_by(t.beta.asc()); + auto s = dynamic_select(db).dynamic_columns(all_of(t)).dynamic_flags().dynamic_from(t).extra_tables(f,t).dynamic_where()/*.dynamic_group_by(t.alpha).dynamic_order_by().dynamic_having(t.gamma).dynamic_limit().dynamic_offset()*/; + s.select_flags.add(sqlpp::distinct); + s.selected_columns.add(f.omega); + s.from.add(f); + s.where.add(t.alpha > 7); + s.having.add(t.alpha > 7); + s.limit.set(3); + s.offset.set(3); + s.group_by.add(t.beta); + s.order_by.add(t.beta.asc()); for (const auto& row : db(s)) { int64_t a = row.alpha; From b00fe51fed892bbaa027adb9cb13d2b649639b47 Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 30 May 2014 13:43:59 +0200 Subject: [PATCH 22/65] Adjusted remaining select parts --- include/sqlpp11/select.h | 6 +- include/sqlpp11/vendor/extra_tables.h | 37 +++-- include/sqlpp11/vendor/group_by.h | 128 ++++++++++----- include/sqlpp11/vendor/having.h | 131 ++++++++++----- include/sqlpp11/vendor/limit.h | 180 +++++++++++++++------ include/sqlpp11/vendor/offset.h | 165 ++++++++++++++----- include/sqlpp11/vendor/order_by.h | 186 ++++++++++++++-------- include/sqlpp11/vendor/select_flag_list.h | 2 +- include/sqlpp11/vendor/where.h | 1 + 9 files changed, 573 insertions(+), 263 deletions(-) diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 2a9561f2..28f31c01 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -203,13 +203,13 @@ namespace sqlpp vendor::no_select_flag_list_t, vendor::no_select_column_list_t, vendor::no_from_t, - //vendor::no_extra_tables_t, - vendor::no_where_t/*, + vendor::no_extra_tables_t, + vendor::no_where_t, vendor::no_group_by_t, vendor::no_having_t, vendor::no_order_by_t, vendor::no_limit_t, - vendor::no_offset_t*/>; + vendor::no_offset_t>; blank_select_t select() // FIXME: These should be constexpr diff --git a/include/sqlpp11/vendor/extra_tables.h b/include/sqlpp11/vendor/extra_tables.h index 94f68328..5496518c 100644 --- a/include/sqlpp11/vendor/extra_tables.h +++ b/include/sqlpp11/vendor/extra_tables.h @@ -84,9 +84,17 @@ namespace sqlpp template struct _member_t { + using _data_t = extra_tables_data_t; + _impl_t extra_tables; _impl_t& operator()() { return extra_tables; } const _impl_t& operator()() const { return extra_tables; } + + template + static auto _get_member(T t) -> decltype(t.extra_tables) + { + return t.extra_tables; + } }; // Additional methods for the statement @@ -103,9 +111,7 @@ namespace sqlpp using _recursive_traits = make_recursive_traits<>; // Data - struct _data_t - { - }; + using _data_t = no_data_t; // Member implementation with data and methods template @@ -118,9 +124,17 @@ namespace sqlpp template struct _member_t { - _impl_t no_extra_tables_t; - _impl_t& operator()() { return no_extra_tables_t; } - const _impl_t& operator()() const { return no_extra_tables_t; } + using _data_t = no_data_t; + + _impl_t no_extra_tables; + _impl_t& operator()() { return no_extra_tables; } + const _impl_t& operator()() const { return no_extra_tables; } + + template + static auto _get_member(T t) -> decltype(t.no_extra_tables) + { + return t.no_extra_tables; + } }; template @@ -150,17 +164,6 @@ namespace sqlpp } }; - template - struct serializer_t - { - using T = typename no_extra_tables_t::_data_t; - - static Context& _(const T& t, Context& context) - { - return context; - } - }; - } } diff --git a/include/sqlpp11/vendor/group_by.h b/include/sqlpp11/vendor/group_by.h index 3766c66c..caadc8db 100644 --- a/include/sqlpp11/vendor/group_by.h +++ b/include/sqlpp11/vendor/group_by.h @@ -39,6 +39,24 @@ namespace sqlpp { namespace vendor { + // GROUP BY DATA + template + struct group_by_data_t + { + group_by_data_t(Expressions... expressions): + _expressions(expressions...) + {} + + group_by_data_t(const group_by_data_t&) = default; + group_by_data_t(group_by_data_t&&) = default; + group_by_data_t& operator=(const group_by_data_t&) = default; + group_by_data_t& operator=(group_by_data_t&&) = default; + ~group_by_data_t() = default; + + std::tuple _expressions; + vendor::interpretable_list_t _dynamic_expressions; + }; + // GROUP BY template struct group_by_t @@ -54,60 +72,100 @@ namespace sqlpp static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an expression in group_by()"); - group_by_t& _group_by() { return *this; } - - group_by_t(Expressions... expressions): - _expressions(expressions...) - {} - - group_by_t(const group_by_t&) = default; - group_by_t(group_by_t&&) = default; - group_by_t& operator=(const group_by_t&) = default; - group_by_t& operator=(group_by_t&&) = default; - ~group_by_t() = default; + // Data + using _data_t = select_flag_list_data_t; + // Member implementation with data and methods template - struct _methods_t + struct _impl_t { template - void add_group_by_ntc(Expression expression) + void add_ntc(Expression expression) { - add_group_by(expression); + add(expression); } template - void add_group_by(Expression expression) + void add(Expression expression) { - static_assert(_is_dynamic::value, "add_group_by must not be called for static group_by"); - static_assert(is_expression_t::value, "invalid expression argument in add_group_by()"); - static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in add_group_by()"); + static_assert(_is_dynamic::value, "add() must not be called for static group_by"); + static_assert(is_expression_t::value, "invalid expression argument in group_by::add()"); + static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in group_by::add()"); using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; - _add_group_by_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert + _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert } private: template - void _add_group_by_impl(Expression expression, const std::true_type&) + void _add_impl(Expression expression, const std::true_type&) { - return static_cast(this)->_group_by()._dynamic_expressions.emplace_back(expression); + return _data._dynamic_expressions.emplace_back(expression); } template - void _add_group_by_impl(Expression expression, const std::false_type&); + void _add_impl(Expression expression, const std::false_type&); + public: + _data_t _data; }; - const group_by_t& _group_by() const { return *this; } - std::tuple _expressions; - vendor::interpretable_list_t _dynamic_expressions; + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = group_by_data_t; + + _impl_t group_by; + _impl_t& operator()() { return group_by; } + const _impl_t& operator()() const { return group_by; } + + template + static auto _get_member(T t) -> decltype(t.group_by) + { + return t.group_by; + } + }; + + template + struct _methods_t + { + }; }; + // NO GROUP BY YET struct no_group_by_t { using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; + + _impl_t no_group_by; + _impl_t& operator()() { return no_group_by; } + const _impl_t& operator()() const { return no_group_by; } + + template + static auto _get_member(T t) -> decltype(t.no_group_by) + { + return t.no_group_by; + } + }; + template struct _methods_t { @@ -119,7 +177,7 @@ namespace sqlpp auto group_by(Args... args) -> _new_statement_t> { - return { *static_cast(this), group_by_t{args...} }; + return { *static_cast(this), group_by_data_t{args...} }; } template @@ -127,16 +185,16 @@ namespace sqlpp -> _new_statement_t> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_group_by must not be called in a static statement"); - return { *static_cast(this), vendor::group_by_t<_database_t, Args...>{args...} }; + return { *static_cast(this), group_by_data_t<_database_t, Args...>{args...} }; } }; }; // Interpreters template - struct serializer_t> + struct serializer_t> { - using T = group_by_t; + using T = group_by_data_t; static Context& _(const T& t, Context& context) { @@ -150,18 +208,6 @@ namespace sqlpp return context; } }; - - template - struct serializer_t - { - using T = no_group_by_t; - - static Context& _(const T& t, Context& context) - { - return context; - } - }; - } } diff --git a/include/sqlpp11/vendor/having.h b/include/sqlpp11/vendor/having.h index 8f85eab9..0abdcb72 100644 --- a/include/sqlpp11/vendor/having.h +++ b/include/sqlpp11/vendor/having.h @@ -38,6 +38,24 @@ namespace sqlpp { namespace vendor { + // HAVING DATA + template + struct having_data_t + { + having_data_t(Expressions... expressions): + _expressions(expressions...) + {} + + having_data_t(const having_data_t&) = default; + having_data_t(having_data_t&&) = default; + having_data_t& operator=(const having_data_t&) = default; + having_data_t& operator=(having_data_t&&) = default; + ~having_data_t() = default; + + std::tuple _expressions; + vendor::interpretable_list_t _dynamic_expressions; + }; + // HAVING template struct having_t @@ -50,59 +68,102 @@ namespace sqlpp static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression argument required in having()"); static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an expression in having()"); - having_t& _having() { return *this; } + // Data + using _data_t = having_data_t; - having_t(Expressions... expressions): - _expressions(expressions...) - {} - - having_t(const having_t&) = default; - having_t(having_t&&) = default; - having_t& operator=(const having_t&) = default; - having_t& operator=(having_t&&) = default; - ~having_t() = default; - - template - struct _methods_t + // Member implementation with data and methods + template + struct _impl_t { template - void add_having_ntc(Expression expression) + void add_ntc(Expression expression) { - add_having(expression); + add(expression); } template - void add_having(Expression expression) + void add(Expression expression) { - static_assert(_is_dynamic::value, "add_having must not be called for static having"); - static_assert(is_expression_t::value, "invalid expression argument in add_having()"); - static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in add_having()"); + static_assert(_is_dynamic::value, "having::add() can only be called for dynamic_having"); + static_assert(is_expression_t::value, "invalid expression argument in having::add()"); + static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in having::add()"); using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; - _add_having_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert + _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert } private: template - void _add_having_impl(Expression expression, const std::true_type&) + void _add_impl(Expression expression, const std::true_type&) { - return static_cast(this)->_having()._dynamic_expressions.emplace_back(expression); + return _data._dynamic_expressions.emplace_back(expression); } template - void _add_having_impl(Expression expression, const std::false_type&); + void _add_impl(Expression expression, const std::false_type&); + + public: + _data_t _data; }; - std::tuple _expressions; - vendor::interpretable_list_t _dynamic_expressions; + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = having_data_t; + + _impl_t having; + _impl_t& operator()() { return having; } + const _impl_t& operator()() const { return having; } + + template + static auto _get_member(T t) -> decltype(t.having) + { + return t.having; + } + }; + + // Additional methods for the statement + template + struct _methods_t + { + }; }; + // NO HAVING YET struct no_having_t { using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; + + _impl_t no_having; + _impl_t& operator()() { return no_having; } + const _impl_t& operator()() const { return no_having; } + + template + static auto _get_member(T t) -> decltype(t.no_having) + { + return t.no_having; + } + }; + template struct _methods_t { @@ -114,7 +175,7 @@ namespace sqlpp auto having(Args... args) -> _new_statement_t> { - return { *static_cast(this), having_t{args...} }; + return { *static_cast(this), having_data_t{args...} }; } template @@ -122,16 +183,16 @@ namespace sqlpp -> _new_statement_t> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_having must not be called in a static statement"); - return { *static_cast(this), vendor::having_t<_database_t, Args...>{args...} }; + return { *static_cast(this), having_data_t<_database_t, Args...>{args...} }; } }; }; // Interpreters template - struct serializer_t> + struct serializer_t> { - using T = having_t; + using T = having_data_t; static Context& _(const T& t, Context& context) { @@ -145,18 +206,6 @@ namespace sqlpp return context; } }; - - template - struct serializer_t - { - using T = no_having_t; - - static Context& _(const T& t, Context& context) - { - return context; - } - }; - } } diff --git a/include/sqlpp11/vendor/limit.h b/include/sqlpp11/vendor/limit.h index b5b2ec89..62310324 100644 --- a/include/sqlpp11/vendor/limit.h +++ b/include/sqlpp11/vendor/limit.h @@ -35,6 +35,23 @@ namespace sqlpp { namespace vendor { + // LIMIT DATA + template + struct limit_data_t + { + limit_data_t(Limit value): + _value(value) + {} + + limit_data_t(const limit_data_t&) = default; + limit_data_t(limit_data_t&&) = default; + limit_data_t& operator=(const limit_data_t&) = default; + limit_data_t& operator=(limit_data_t&&) = default; + ~limit_data_t() = default; + + Limit _value; + }; + // LIMIT template struct limit_t @@ -44,65 +61,109 @@ namespace sqlpp static_assert(is_integral_t::value, "limit requires an integral value or integral parameter"); - limit_t(Limit value): - _value(value) - {} + // Data + using _data_t = limit_data_t; - limit_t(const limit_t&) = default; - limit_t(limit_t&&) = default; - limit_t& operator=(const limit_t&) = default; - limit_t& operator=(limit_t&&) = default; - ~limit_t() = default; + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + _impl_t limit; + _impl_t& operator()() { return limit; } + const _impl_t& operator()() const { return limit; } + + template + static auto _get_member(T t) -> decltype(t.limit) + { + return t.limit; + } + }; template struct _methods_t { }; - - Limit _value; }; + // DYNAMIC LIMIT DATA + template + struct dynamic_limit_data_t + { + dynamic_limit_data_t(): + _value(noop()) + { + } + + template + dynamic_limit_data_t(Limit value): + _initialized(true), + _value(typename wrap_operand::type(value)) + { + } + + dynamic_limit_data_t(const dynamic_limit_data_t&) = default; + dynamic_limit_data_t(dynamic_limit_data_t&&) = default; + dynamic_limit_data_t& operator=(const dynamic_limit_data_t&) = default; + dynamic_limit_data_t& operator=(dynamic_limit_data_t&&) = default; + ~dynamic_limit_data_t() = default; + + bool _initialized = false; + interpretable_t _value; + }; + + // DYNAMIC LIMIT template struct dynamic_limit_t { using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; - dynamic_limit_t& _limit() { return *this; } + // Data + using _data_t = limit_data_t; - dynamic_limit_t(): - _value(noop()) - { - } - - template - dynamic_limit_t(Limit value): - _initialized(true), - _value(typename wrap_operand::type(value)) - { - } - - dynamic_limit_t(const dynamic_limit_t&) = default; - dynamic_limit_t(dynamic_limit_t&&) = default; - dynamic_limit_t& operator=(const dynamic_limit_t&) = default; - dynamic_limit_t& operator=(dynamic_limit_t&&) = default; - ~dynamic_limit_t() = default; - - template - struct _methods_t + // Member implementation with data and methods + template + struct _impl_t { template - void set_limit(Limit value) + void set(Limit value) { // FIXME: Make sure that Limit does not require external tables? Need to read up on SQL using arg_t = typename wrap_operand::type; - static_cast(this)->_limit()._value = arg_t{value}; - static_cast(this)->_limit()._initialized = true; + _data._value = arg_t{value}; + _data._initialized = true; + } + public: + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + _impl_t limit; + _impl_t& operator()() { return limit; } + const _impl_t& operator()() const { return limit; } + + template + static auto _get_member(T t) -> decltype(t.limit) + { + return t.limit; } }; - bool _initialized = false; - interpretable_t _value; + // Additional methods for the statement + template + struct _methods_t + { + }; }; struct no_limit_t @@ -110,6 +171,33 @@ namespace sqlpp using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; + + _impl_t no_limit; + _impl_t& operator()() { return no_limit; } + const _impl_t& operator()() const { return no_limit; } + + template + static auto _get_member(T t) -> decltype(t.no_limit) + { + return t.no_limit; + } + }; + template struct _methods_t { @@ -121,23 +209,23 @@ namespace sqlpp auto limit(Arg arg) -> _new_statement_t::type>> { - return { *static_cast(this), limit_t::type>{{arg}} }; + return { *static_cast(this), limit_data_t::type>{{arg}} }; } auto dynamic_limit() -> _new_statement_t> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_limit must not be called in a static statement"); - return { *static_cast(this), dynamic_limit_t<_database_t>{} }; + return { *static_cast(this), dynamic_limit_data_t<_database_t>{} }; } }; }; // Interpreters template - struct serializer_t> + struct serializer_t> { - using T = dynamic_limit_t; + using T = dynamic_limit_data_t; static Context& _(const T& t, Context& context) { @@ -162,18 +250,6 @@ namespace sqlpp return context; } }; - - template - struct serializer_t - { - using T = no_limit_t; - - static Context& _(const T& t, Context& context) - { - return context; - } - }; - } } diff --git a/include/sqlpp11/vendor/offset.h b/include/sqlpp11/vendor/offset.h index dca7fd16..fd42d846 100644 --- a/include/sqlpp11/vendor/offset.h +++ b/include/sqlpp11/vendor/offset.h @@ -35,6 +35,23 @@ namespace sqlpp { namespace vendor { + // OFFSET DATA + template + struct offset_data_t + { + offset_data_t(Offset value): + _value(value) + {} + + offset_data_t(const offset_data_t&) = default; + offset_data_t(offset_data_t&&) = default; + offset_data_t& operator=(const offset_data_t&) = default; + offset_data_t& operator=(offset_data_t&&) = default; + ~offset_data_t() = default; + + Offset _value; + }; + // OFFSET template struct offset_t @@ -44,49 +61,103 @@ namespace sqlpp static_assert(is_integral_t::value, "offset requires an integral value or integral parameter"); - offset_t(Offset value): - _value(value) - {} + // Data + using _data_t = offset_data_t; - offset_t(const offset_t&) = default; - offset_t(offset_t&&) = default; - offset_t& operator=(const offset_t&) = default; - offset_t& operator=(offset_t&&) = default; - ~offset_t() = default; + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + _impl_t offset; + _impl_t& operator()() { return offset; } + const _impl_t& operator()() const { return offset; } + + template + static auto _get_member(T t) -> decltype(t.offset) + { + return t.offset; + } + }; template struct _methods_t { }; - - Offset _value; }; + // DYNAMIC OFFSET DATA + template + struct dynamic_offset_data_t + { + dynamic_offset_data_t(): + _value(noop()) + { + } + + template + dynamic_offset_data_t(Offset value): + _initialized(true), + _value(typename wrap_operand::type(value)) + { + } + + dynamic_offset_data_t(const dynamic_offset_data_t&) = default; + dynamic_offset_data_t(dynamic_offset_data_t&&) = default; + dynamic_offset_data_t& operator=(const dynamic_offset_data_t&) = default; + dynamic_offset_data_t& operator=(dynamic_offset_data_t&&) = default; + ~dynamic_offset_data_t() = default; + + bool _initialized = false; + interpretable_t _value; + }; + + // DYNAMIC OFFSET template struct dynamic_offset_t { using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; - dynamic_offset_t& _offset() { return *this; } + // Data + using _data_t = offset_data_t; - dynamic_offset_t(): - _value(noop()) - { - } + // Member implementation with data and methods + template + struct _impl_t + { + template + void set(Offset value) + { + // FIXME: Make sure that Offset does not require external tables? Need to read up on SQL + using arg_t = typename wrap_operand::type; + _data._value = arg_t{value}; + _data._initialized = true; + } + public: + _data_t _data; + }; - template - dynamic_offset_t(Offset value): - _initialized(true), - _value(typename wrap_operand::type(value)) - { - } + // Member template for adding the named member to a statement + template + struct _member_t + { + _impl_t offset; + _impl_t& operator()() { return offset; } + const _impl_t& operator()() const { return offset; } - dynamic_offset_t(const dynamic_offset_t&) = default; - dynamic_offset_t(dynamic_offset_t&&) = default; - dynamic_offset_t& operator=(const dynamic_offset_t&) = default; - dynamic_offset_t& operator=(dynamic_offset_t&&) = default; - ~dynamic_offset_t() = default; + template + static auto _get_member(T t) -> decltype(t.offset) + { + return t.offset; + } + }; template struct _methods_t @@ -110,6 +181,33 @@ namespace sqlpp using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; + + _impl_t no_offset; + _impl_t& operator()() { return no_offset; } + const _impl_t& operator()() const { return no_offset; } + + template + static auto _get_member(T t) -> decltype(t.no_offset) + { + return t.no_offset; + } + }; + template struct _methods_t { @@ -121,14 +219,14 @@ namespace sqlpp auto offset(Arg arg) -> _new_statement_t::type>> { - return { *static_cast(this), offset_t::type>{{arg}} }; + return { *static_cast(this), offset_data_t::type>{{arg}} }; } auto dynamic_offset() -> _new_statement_t> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_offset must not be called in a static statement"); - return { *static_cast(this), dynamic_offset_t<_database_t>{} }; + return { *static_cast(this), dynamic_offset_data_t<_database_t>{} }; } }; }; @@ -162,17 +260,6 @@ namespace sqlpp return context; } }; - - template - struct serializer_t - { - using T = no_offset_t; - - static Context& _(const T& t, Context& context) - { - return context; - } - }; } } diff --git a/include/sqlpp11/vendor/order_by.h b/include/sqlpp11/vendor/order_by.h index f60537eb..cd9e89d6 100644 --- a/include/sqlpp11/vendor/order_by.h +++ b/include/sqlpp11/vendor/order_by.h @@ -39,73 +39,133 @@ namespace sqlpp { namespace vendor { - template - struct order_by_t + // ORDER BY DATA + template + struct order_by_data_t { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits; - - using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - - static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one sort-order expression required in order_by()"); - - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in order_by()"); - - static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a sort order expression in order_by()"); - - order_by_t& _order_by() { return *this; } - - order_by_t(Expressions... expressions): + order_by_data_t(Expressions... expressions): _expressions(expressions...) {} - order_by_t(const order_by_t&) = default; - order_by_t(order_by_t&&) = default; - order_by_t& operator=(const order_by_t&) = default; - order_by_t& operator=(order_by_t&&) = default; - ~order_by_t() = default; - - template - struct _methods_t - { - template - void add_order_by_ntc(Expression expression) - { - add_order_by(expression); - } - - template - void add_order_by(Expression expression) - { - static_assert(_is_dynamic::value, "add_order_by must not be called for static order_by"); - static_assert(is_sort_order_t::value, "invalid expression argument in add_order_by()"); - static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in add_order_by()"); - - using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_sort_order_t::value>; - - _add_order_by_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert - } - - private: - template - void _add_order_by_impl(Expression expression, const std::true_type&) - { - return static_cast(this)->_order_by()._dynamic_expressions.emplace_back(expression); - } - - template - void _add_order_by_impl(Expression expression, const std::false_type&); - }; + order_by_data_t(const order_by_data_t&) = default; + order_by_data_t(order_by_data_t&&) = default; + order_by_data_t& operator=(const order_by_data_t&) = default; + order_by_data_t& operator=(order_by_data_t&&) = default; + ~order_by_data_t() = default; std::tuple _expressions; vendor::interpretable_list_t _dynamic_expressions; }; + // ORDER BY + template + struct order_by_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + + using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; + + static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression (e.g. a column) required in order_by()"); + + static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in order_by()"); + + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an expression in order_by()"); + + // Data + using _data_t = select_flag_list_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + template + void add_ntc(Expression expression) + { + add(expression); + } + + template + void add(Expression expression) + { + static_assert(_is_dynamic::value, "add() must not be called for static order_by"); + static_assert(is_expression_t::value, "invalid expression argument in order_by::add()"); + static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in order_by::add()"); + + using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; + + _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert + } + + private: + template + void _add_impl(Expression expression, const std::true_type&) + { + return _data._dynamic_expressions.emplace_back(expression); + } + + template + void _add_impl(Expression expression, const std::false_type&); + public: + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = order_by_data_t; + + _impl_t order_by; + _impl_t& operator()() { return order_by; } + const _impl_t& operator()() const { return order_by; } + + template + static auto _get_member(T t) -> decltype(t.order_by) + { + return t.order_by; + } + }; + + template + struct _methods_t + { + }; + }; + + // NO ORDER BY YET struct no_order_by_t { using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; + + _impl_t no_order_by; + _impl_t& operator()() { return no_order_by; } + const _impl_t& operator()() const { return no_order_by; } + + template + static auto _get_member(T t) -> decltype(t.no_order_by) + { + return t.no_order_by; + } + }; + template struct _methods_t { @@ -117,7 +177,7 @@ namespace sqlpp auto order_by(Args... args) -> _new_statement_t> { - return { *static_cast(this), order_by_t{args...} }; + return { *static_cast(this), order_by_data_t{args...} }; } template @@ -125,16 +185,16 @@ namespace sqlpp -> _new_statement_t> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_order_by must not be called in a static statement"); - return { *static_cast(this), vendor::order_by_t<_database_t, Args...>{args...} }; + return { *static_cast(this), order_by_data_t<_database_t, Args...>{args...} }; } }; }; // Interpreters template - struct serializer_t> + struct serializer_t> { - using T = order_by_t; + using T = order_by_data_t; static Context& _(const T& t, Context& context) { @@ -148,18 +208,6 @@ namespace sqlpp return context; } }; - - template - struct serializer_t - { - using T = no_order_by_t; - - static Context& _(const T& t, Context& context) - { - return context; - } - }; - } } diff --git a/include/sqlpp11/vendor/select_flag_list.h b/include/sqlpp11/vendor/select_flag_list.h index 111d24ee..735e29e8 100644 --- a/include/sqlpp11/vendor/select_flag_list.h +++ b/include/sqlpp11/vendor/select_flag_list.h @@ -38,7 +38,7 @@ namespace sqlpp { namespace vendor { - // SELECTED COLUMNS DATA + // SELECTED FLAGS DATA template struct select_flag_list_data_t { diff --git a/include/sqlpp11/vendor/where.h b/include/sqlpp11/vendor/where.h index 4c164b34..b865a38e 100644 --- a/include/sqlpp11/vendor/where.h +++ b/include/sqlpp11/vendor/where.h @@ -38,6 +38,7 @@ namespace sqlpp { namespace vendor { + // WHERE DATA template struct where_data_t { From 3fb6c6c246af83dc662bbf31c48d4ebb741aed88 Mon Sep 17 00:00:00 2001 From: rbock Date: Mon, 2 Jun 2014 06:40:22 +0200 Subject: [PATCH 23/65] SelectTest compiles again --- include/sqlpp11/select.h | 1 + include/sqlpp11/vendor/group_by.h | 2 +- include/sqlpp11/vendor/limit.h | 6 +++++- include/sqlpp11/vendor/offset.h | 6 +++++- include/sqlpp11/vendor/order_by.h | 2 +- include/sqlpp11/vendor/select_flag_list.h | 2 +- include/sqlpp11/vendor/where.h | 4 ++-- tests/SelectTest.cpp | 6 ++---- 8 files changed, 18 insertions(+), 11 deletions(-) diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 28f31c01..a111c3cb 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -62,6 +62,7 @@ namespace sqlpp template struct select_policies_t { +#warning need to check policies' signature, e.g. a _data_t in _member_t template using _database_t = Db; using _statement_t = select_t; diff --git a/include/sqlpp11/vendor/group_by.h b/include/sqlpp11/vendor/group_by.h index caadc8db..a3732a5b 100644 --- a/include/sqlpp11/vendor/group_by.h +++ b/include/sqlpp11/vendor/group_by.h @@ -73,7 +73,7 @@ namespace sqlpp static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an expression in group_by()"); // Data - using _data_t = select_flag_list_data_t; + using _data_t = group_by_data_t; // Member implementation with data and methods template diff --git a/include/sqlpp11/vendor/limit.h b/include/sqlpp11/vendor/limit.h index 62310324..cd5884c4 100644 --- a/include/sqlpp11/vendor/limit.h +++ b/include/sqlpp11/vendor/limit.h @@ -75,6 +75,8 @@ namespace sqlpp template struct _member_t { + using _data_t = limit_data_t; + _impl_t limit; _impl_t& operator()() { return limit; } const _impl_t& operator()() const { return limit; } @@ -126,7 +128,7 @@ namespace sqlpp using _recursive_traits = make_recursive_traits<>; // Data - using _data_t = limit_data_t; + using _data_t = dynamic_limit_data_t; // Member implementation with data and methods template @@ -148,6 +150,8 @@ namespace sqlpp template struct _member_t { + using _data_t = dynamic_limit_data_t; + _impl_t limit; _impl_t& operator()() { return limit; } const _impl_t& operator()() const { return limit; } diff --git a/include/sqlpp11/vendor/offset.h b/include/sqlpp11/vendor/offset.h index fd42d846..9ace773f 100644 --- a/include/sqlpp11/vendor/offset.h +++ b/include/sqlpp11/vendor/offset.h @@ -75,6 +75,8 @@ namespace sqlpp template struct _member_t { + using _data_t = offset_data_t; + _impl_t offset; _impl_t& operator()() { return offset; } const _impl_t& operator()() const { return offset; } @@ -126,7 +128,7 @@ namespace sqlpp using _recursive_traits = make_recursive_traits<>; // Data - using _data_t = offset_data_t; + using _data_t = dynamic_offset_data_t; // Member implementation with data and methods template @@ -148,6 +150,8 @@ namespace sqlpp template struct _member_t { + using _data_t = dynamic_offset_data_t; + _impl_t offset; _impl_t& operator()() { return offset; } const _impl_t& operator()() const { return offset; } diff --git a/include/sqlpp11/vendor/order_by.h b/include/sqlpp11/vendor/order_by.h index cd9e89d6..37e84724 100644 --- a/include/sqlpp11/vendor/order_by.h +++ b/include/sqlpp11/vendor/order_by.h @@ -73,7 +73,7 @@ namespace sqlpp static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an expression in order_by()"); // Data - using _data_t = select_flag_list_data_t; + using _data_t = order_by_data_t; // Member implementation with data and methods template diff --git a/include/sqlpp11/vendor/select_flag_list.h b/include/sqlpp11/vendor/select_flag_list.h index 735e29e8..c458ad6e 100644 --- a/include/sqlpp11/vendor/select_flag_list.h +++ b/include/sqlpp11/vendor/select_flag_list.h @@ -98,7 +98,7 @@ namespace sqlpp template void _add_impl(Flag flag, const std::true_type&) { - return static_cast(this)->_select_flag_list()._dynamic_flags.emplace_back(flag); + return _data._dynamic_flags.emplace_back(flag); } template diff --git a/include/sqlpp11/vendor/where.h b/include/sqlpp11/vendor/where.h index b865a38e..0dcbd9c2 100644 --- a/include/sqlpp11/vendor/where.h +++ b/include/sqlpp11/vendor/where.h @@ -77,8 +77,6 @@ namespace sqlpp template struct _impl_t { - using _data_t = where_data_t; - template void add_ntc(Expression expression) { @@ -115,6 +113,8 @@ namespace sqlpp template struct _member_t { + using _data_t = where_data_t; + _impl_t where; _impl_t& operator()() { return where; } const _impl_t& operator()() const { return where; } diff --git a/tests/SelectTest.cpp b/tests/SelectTest.cpp index efa7e67a..e00312fc 100644 --- a/tests/SelectTest.cpp +++ b/tests/SelectTest.cpp @@ -55,7 +55,6 @@ int main() int64_t a = row.alpha; const std::string b = row.beta; } -#if 0 for (const auto& row : db(select(all_of(t).as(t)).from(t).where(true))) { @@ -70,7 +69,8 @@ int main() const bool g = row.gamma; } - auto s = dynamic_select(db).dynamic_columns(all_of(t)).dynamic_flags().dynamic_from(t).extra_tables(f,t).dynamic_where()/*.dynamic_group_by(t.alpha).dynamic_order_by().dynamic_having(t.gamma).dynamic_limit().dynamic_offset()*/; + auto stat = sqlpp::select().columns(all_of(t)).flags(sqlpp::all).from(t).extra_tables(f,t).where(t.alpha > 0).group_by(t.alpha).order_by(t.gamma.asc()).having(t.gamma).limit(7).offset(19); + auto s = dynamic_select(db).dynamic_columns(all_of(t)).dynamic_flags().dynamic_from(t).extra_tables(f,t).dynamic_where().dynamic_group_by(t.alpha).dynamic_order_by().dynamic_having(t.gamma).dynamic_limit().dynamic_offset(); s.select_flags.add(sqlpp::distinct); s.selected_columns.add(f.omega); s.from.add(f); @@ -85,9 +85,7 @@ int main() int64_t a = row.alpha; } - auto X = select(all_of(t)).from(t).as(t.alpha); -#endif return 0; } From 7e32a0a3ea3e40cf18155b6d1b0ca3a6fd7d73ac Mon Sep 17 00:00:00 2001 From: rbock Date: Mon, 2 Jun 2014 07:48:05 +0200 Subject: [PATCH 24/65] Cleaned up minor as() method mess plus some oversights --- include/sqlpp11/avg.h | 3 ++- include/sqlpp11/basic_expression_operators.h | 4 ++++ include/sqlpp11/count.h | 3 ++- include/sqlpp11/exists.h | 3 ++- include/sqlpp11/functions.h | 3 ++- include/sqlpp11/max.h | 3 ++- include/sqlpp11/min.h | 3 ++- include/sqlpp11/select.h | 3 ++- include/sqlpp11/sum.h | 3 ++- include/sqlpp11/vendor/concat.h | 3 ++- include/sqlpp11/vendor/expression.h | 15 ++++++++++----- include/sqlpp11/vendor/extra_tables.h | 2 +- include/sqlpp11/vendor/from.h | 2 +- include/sqlpp11/vendor/in.h | 3 ++- include/sqlpp11/vendor/is_null.h | 3 ++- include/sqlpp11/vendor/like.h | 3 ++- include/sqlpp11/vendor/offset.h | 8 ++++---- include/sqlpp11/vendor/select_column_list.h | 2 ++ tests/CMakeLists.txt | 4 ++-- tests/SelectTypeTest.cpp | 11 +++++------ 20 files changed, 53 insertions(+), 31 deletions(-) diff --git a/include/sqlpp11/avg.h b/include/sqlpp11/avg.h index 2854a8d6..50ca491c 100644 --- a/include/sqlpp11/avg.h +++ b/include/sqlpp11/avg.h @@ -34,7 +34,8 @@ namespace sqlpp namespace vendor { template - struct avg_t: public floating_point::template expression_operators> + struct avg_t: public floating_point::template expression_operators>, + public alias_operators> { using _traits = make_traits; using _recursive_traits = make_recursive_traits; diff --git a/include/sqlpp11/basic_expression_operators.h b/include/sqlpp11/basic_expression_operators.h index e306542d..d1f06749 100644 --- a/include/sqlpp11/basic_expression_operators.h +++ b/include/sqlpp11/basic_expression_operators.h @@ -139,7 +139,11 @@ namespace sqlpp static_assert(detail::all_t<_is_valid_comparison_operand>::value...>::value, "at least one operand of in() is not valid"); return { *static_cast(this), vendor::wrap_operand_t{t}... }; } + }; + template + struct alias_operators + { template expression_alias_t as(const alias_provider&) { diff --git a/include/sqlpp11/count.h b/include/sqlpp11/count.h index eec747be..838189a6 100644 --- a/include/sqlpp11/count.h +++ b/include/sqlpp11/count.h @@ -35,7 +35,8 @@ namespace sqlpp namespace vendor { template - struct count_t: public sqlpp::detail::integral::template expression_operators> + struct count_t: public sqlpp::detail::integral::template expression_operators>, + public alias_operators> { using _traits = make_traits<::sqlpp::detail::integral, ::sqlpp::tag::expression, ::sqlpp::tag::named_expression>; using _recursive_traits = make_recursive_traits; diff --git a/include/sqlpp11/exists.h b/include/sqlpp11/exists.h index 7469af47..8d767754 100644 --- a/include/sqlpp11/exists.h +++ b/include/sqlpp11/exists.h @@ -34,7 +34,8 @@ namespace sqlpp namespace vendor { template - struct exists_t: public boolean::template expression_operators> + struct exists_t: public boolean::template expression_operators>, + public alias_operators> { using _traits = make_traits; using _recursive_traits = make_recursive_traits
; static_assert(is_table_t
::value, "argument has to be a table"); static_assert(required_tables_of
::size::value == 0, "table depends on another table"); - single_table_t(Table table): - _table(table) - {} + using _data_t = single_table_data_t; - single_table_t(const single_table_t&) = default; - single_table_t(single_table_t&&) = default; - single_table_t& operator=(const single_table_t&) = default; - single_table_t& operator=(single_table_t&&) = default; - ~single_table_t() = default; + struct _name_t {}; + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = single_table_data_t; + + _impl_t into; + _impl_t& operator()() { return into; } + const _impl_t& operator()() const { return into; } + + template + static auto _get_member(T t) -> decltype(t.into) + { + return t.into; + } + }; + + // Additional methods for the statement template struct _methods_t { }; - Table _table; + template + struct _result_methods_t + { + using _statement_t = typename Policies::_statement_t; + + const _statement_t& _get_statement() const + { + return static_cast(*this); + } + + static constexpr size_t _get_static_no_of_parameters() + { +#warning need to fix this + return 0; + //return _parameter_list_t::size::value; + } + + size_t _get_no_of_parameters() const + { +#warning need to fix this + return 0; + //return _parameter_list_t::size::value; + } + + void _check_consistency() const + { + // FIXME: Read up on what is allowed/prohibited in INSERT + } + + template + auto _run(Db& db) const -> decltype(db.insert(_get_statement())) + { + _check_consistency(); + + static_assert(_get_static_no_of_parameters() == 0, "cannot run insert directly with parameters, use prepare instead"); + return db.insert(*this); + } + + /* + template + auto _prepare(Db& db) const + -> prepared_insert_t + { + _check_consistency(); + + return {{}, db.prepare_insert(*this)}; + } + */ + }; }; + // NO INTO YET struct no_single_table_t { using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; + + _impl_t no_into; + _impl_t& operator()() { return no_into; } + const _impl_t& operator()() const { return no_into; } + + template + static auto _get_member(T t) -> decltype(t.no_into) + { + return t.no_into; + } + }; + template struct _methods_t { @@ -80,7 +192,7 @@ namespace sqlpp auto into(Args... args) -> _new_statement_t> { - return { *static_cast(this), single_table_t{args...} }; + return { *static_cast(this), single_table_data_t{args...} }; } #warning: remove can operate on several tables at once, so it should not use single_table anyway @@ -88,16 +200,16 @@ namespace sqlpp auto from(Args... args) -> _new_statement_t> { - return { *static_cast(this), single_table_t{args...} }; + return { *static_cast(this), single_table_data_t{args...} }; } }; }; // Interpreters template - struct serializer_t> + struct serializer_t> { - using T = single_table_t; + using T = single_table_data_t; static Context& _(const T& t, Context& context) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ad2d430a..9de5e4e2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,11 +7,11 @@ macro (build_and_run arg) endmacro () #build_and_run(InterpretTest) -#build_and_run(InsertTest) +build_and_run(InsertTest) #build_and_run(RemoveTest) #build_and_run(UpdateTest) #build_and_run(SelectTest) -build_and_run(SelectTypeTest) +#build_and_run(SelectTypeTest) #build_and_run(FunctionTest) #build_and_run(PreparedTest) diff --git a/tests/InsertTest.cpp b/tests/InsertTest.cpp index 67e2efe7..683ed401 100644 --- a/tests/InsertTest.cpp +++ b/tests/InsertTest.cpp @@ -67,10 +67,10 @@ int main() serialize(insert_into(t).set(t.beta = "kirschauflauf"), printer).str(); serialize(insert_into(t).columns(t.beta), printer).str(); auto multi_insert = insert_into(t).columns(t.beta, t.delta); - multi_insert.add_values(t.beta = "cheesecake", t.delta = 1); - multi_insert.add_values(t.beta = sqlpp::default_value, t.delta = sqlpp::default_value); + multi_insert.column_list.add(t.beta = "cheesecake", t.delta = 1); + multi_insert.column_list.add(t.beta = sqlpp::default_value, t.delta = sqlpp::default_value); auto i = dynamic_insert_into(db, t).dynamic_set(); - i.add_set(t.beta = "kirschauflauf"); + i.insert_list.add(t.beta = "kirschauflauf"); serialize(i, printer).str(); db(multi_insert); From c866f31ea5edff8559d353cbc3627723adb96416 Mon Sep 17 00:00:00 2001 From: rbock Date: Tue, 3 Jun 2014 09:12:27 +0200 Subject: [PATCH 26/65] Turned remove into a generic statement --- include/sqlpp11/insert.h | 102 --------------------- include/sqlpp11/parameter_list.h | 1 + include/sqlpp11/remove.h | 153 ++----------------------------- include/sqlpp11/statement.h | 2 + include/sqlpp11/vendor/using.h | 123 +++++++++++++++++-------- tests/CMakeLists.txt | 4 +- tests/RemoveTest.cpp | 4 +- 7 files changed, 100 insertions(+), 289 deletions(-) diff --git a/include/sqlpp11/insert.h b/include/sqlpp11/insert.h index 587906e2..7ed0e7e2 100644 --- a/include/sqlpp11/insert.h +++ b/include/sqlpp11/insert.h @@ -38,108 +38,6 @@ namespace sqlpp { -#if 0 - template - struct insert_t; - - namespace detail - { - template - struct insert_policies_t - { - using _database_t = Db; - - using _statement_t = insert_t; - - struct _methods_t: public Policies::template _methods_t... - {}; - - template - struct _policies_update_t - { - static_assert(detail::is_element_of>::value, "policies update for non-policy class detected"); - using type = insert_t...>; - }; - - template - using _new_statement_t = typename _policies_update_t::type; - - using _all_required_tables = detail::make_joined_set_t...>; - using _all_provided_tables = detail::make_joined_set_t...>; - using _all_extra_tables = detail::make_joined_set_t...>; - - using _known_tables = detail::make_joined_set_t<_all_provided_tables, _all_extra_tables>; - - template - using _no_unknown_tables = detail::is_subset_of, _known_tables>; - - // The tables not covered by the from. - using _required_tables = detail::make_difference_set_t< - _all_required_tables, - _all_provided_tables // Hint: extra_tables are not used here because they are just a helper for dynamic .add_*() - >; - - using _traits = make_traits; // FIXME - - struct _recursive_traits - { - using _parameters = std::tuple<>; // FIXME - using _required_tables = _required_tables; - using _provided_tables = detail::type_set<>; - using _extra_tables = detail::type_set<>; - }; - }; - } - - // INSERT - template - struct insert_t: - public Policies..., - public detail::insert_policies_t::_methods_t - { - using _policies_t = typename detail::insert_policies_t; - using _database_t = typename _policies_t::_database_t; - - using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - - using _parameter_list_t = typename make_parameter_list_t::type; - - // Constructors - constexpr insert_t() - {} - - template - insert_t(Statement statement, Term term): - Policies(detail::pick_arg(statement, term))... - {} - - insert_t(const insert_t&) = default; - insert_t(insert_t&&) = default; - insert_t& operator=(const insert_t&) = default; - insert_t& operator=(insert_t&&) = default; - ~insert_t() = default; - - }; - - namespace vendor - { - template - struct serializer_t> - { - using T = insert_t; - - static Context& _(const T& t, Context& context) - { - context << "INSERT INTO "; - - using swallow = int[]; - (void) swallow{(serialize(static_cast(t), context), 0)...}; - return context; - } - }; - } -#endif - template using blank_insert_t = statement_t +#include #include #include diff --git a/include/sqlpp11/remove.h b/include/sqlpp11/remove.h index 2204212b..305af315 100644 --- a/include/sqlpp11/remove.h +++ b/include/sqlpp11/remove.h @@ -27,6 +27,7 @@ #ifndef SQLPP_REMOVE_H #define SQLPP_REMOVE_H +#include #include #include #include @@ -36,179 +37,39 @@ #include #include #include -#include - -#include -#include namespace sqlpp { - template - struct remove_t; - - namespace detail - { - template - struct remove_policies_t - { - using _database_t = Db; - using _statement_t = remove_t; - - struct _methods_t: public Policies::template _methods_t... - {}; - - template - struct _policies_update_t - { - static_assert(detail::is_element_of>::value, "policies update for non-policy class detected"); - using type = remove_t...>; - }; - - template - using _new_statement_t = typename _policies_update_t::type; - - using _all_required_tables = detail::make_joined_set_t...>; - using _all_provided_tables = detail::make_joined_set_t...>; - using _all_extra_tables = detail::make_joined_set_t...>; - - using _known_tables = detail::make_joined_set_t<_all_provided_tables, _all_extra_tables>; - - template - using _no_unknown_tables = detail::is_subset_of, _known_tables>; - - // The tables not covered by the from. - using _required_tables = detail::make_difference_set_t< - _all_required_tables, - _all_provided_tables // Hint: extra_tables are not used here because they are just a helper for dynamic .add_*() - >; - - using _traits = make_traits; // FIXME - - struct _recursive_traits - { - using _parameters = std::tuple<>; // FIXME - using _required_tables = _required_tables; - using _provided_tables = detail::type_set<>; - using _extra_tables = detail::type_set<>; - }; - }; - } - - // REMOVE - template - struct remove_t: - public Policies..., - public detail::remove_policies_t::_methods_t - { - using _policies_t = typename detail::remove_policies_t; - using _database_t = typename _policies_t::_database_t; - - using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - - using _parameter_list_t = typename make_parameter_list_t::type; - - // Constructors - constexpr remove_t() - {} - - template - remove_t(Statement statement, Term term): - Policies(detail::pick_arg(statement, term))... - {} - - remove_t(const remove_t&) = default; - remove_t(remove_t&&) = default; - remove_t& operator=(const remove_t&) = default; - remove_t& operator=(remove_t&&) = default; - ~remove_t() = default; - - // run and prepare - static constexpr size_t _get_static_no_of_parameters() - { - return _parameter_list_t::size::value; - } - - size_t _get_no_of_parameters() const - { - return _parameter_list_t::size::value; - } - - void _check_consistency() const - { -#warning reactivate checks -#if 0 - static_assert(is_where_t<_where_t>::value, "cannot run update without having a where condition, use .where(true) to update all rows"); - - // FIXME: Read more details about what is allowed and what not in SQL DELETE - static_assert(is_table_subset_of_table<_where_t>::value, "where requires additional tables"); -#endif - } - - template - std::size_t _run(Database& db) const - { - _check_consistency(); - - static_assert(_get_static_no_of_parameters() == 0, "cannot run remove directly with parameters, use prepare instead"); - return db.remove(*this); - } - - template - auto _prepare(Database& db) const - -> prepared_remove_t - { - _check_consistency(); - - return {{}, db.prepare_remove(*this)}; - } - }; - - namespace vendor - { - template - struct serializer_t> - { - using T = remove_t; - - static Context& _(const T& t, Context& context) - { - context << "DELETE FROM "; - using swallow = int[]; - (void) swallow{(serialize(static_cast(t), context), 0)...}; - return context; - } - }; - } - template - using blank_remove_t = remove_t; - constexpr auto remove() + auto remove() -> blank_remove_t { return { blank_remove_t() }; } template - constexpr auto remove_from(Table table) + auto remove_from(Table table) -> decltype(blank_remove_t().from(table)) { return { blank_remove_t().from(table) }; } template - constexpr auto dynamic_remove(const Database&) + auto dynamic_remove(const Database&) -> decltype(blank_remove_t()) { return { blank_remove_t() }; } template - constexpr auto dynamic_remove_from(const Database&, Table table) + auto dynamic_remove_from(const Database&, Table table) -> decltype(blank_remove_t().from(table)) { return { blank_remove_t().from(table) }; diff --git a/include/sqlpp11/statement.h b/include/sqlpp11/statement.h index db442faa..d6f87d84 100644 --- a/include/sqlpp11/statement.h +++ b/include/sqlpp11/statement.h @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include diff --git a/include/sqlpp11/vendor/using.h b/include/sqlpp11/vendor/using.h index 7a7d7ccf..3731c3c0 100644 --- a/include/sqlpp11/vendor/using.h +++ b/include/sqlpp11/vendor/using.h @@ -37,6 +37,24 @@ namespace sqlpp { namespace vendor { + // USING DATA + template + struct using_data_t + { + using_data_t(Tables... tables): + _tables(tables...) + {} + + using_data_t(const using_data_t&) = default; + using_data_t(using_data_t&&) = default; + using_data_t& operator=(const using_data_t&) = default; + using_data_t& operator=(using_data_t&&) = default; + ~using_data_t() = default; + + std::tuple _tables; + vendor::interpretable_list_t _dynamic_tables; + }; + // USING template struct using_t @@ -52,53 +70,95 @@ namespace sqlpp static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an table in using()"); - using_t& _using() { return *this; } + // Data + using _data_t = using_data_t; - using_t(Tables... tables): - _tables(tables...) - {} - - using_t(const using_t&) = default; - using_t(using_t&&) = default; - using_t& operator=(const using_t&) = default; - using_t& operator=(using_t&&) = default; - ~using_t() = default; - - template - struct _methods_t + // Member implementation with data and methods + template + struct _impl_t { template - void add_using(Table table) + void add(Table table) { - static_assert(_is_dynamic::value, "add_using must not be called for static using()"); - static_assert(is_table_t
::value, "invalid table argument in add_using()"); + static_assert(_is_dynamic::value, "add must not be called for static using()"); + static_assert(is_table_t
::value, "invalid table argument in add()"); using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_table_t
::value>; - _add_using_impl(table, ok()); // dispatch to prevent compile messages after the static_assert + _add_impl(table, ok()); // dispatch to prevent compile messages after the static_assert } private: template - void _add_using_impl(Table table, const std::true_type&) + void _add_impl(Table table, const std::true_type&) { - return static_cast(this)->_using()._dynamic_tables.emplace_back(table); + return _data._dynamic_tables.emplace_back(table); } template - void _add_using_impl(Table table, const std::false_type&); + void _add_impl(Table table, const std::false_type&); + + public: + _data_t _data; }; + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = using_data_t; - std::tuple _tables; - vendor::interpretable_list_t _dynamic_tables; + _impl_t using_; + _impl_t& operator()() { return using_; } + const _impl_t& operator()() const { return using_; } + + template + static auto _get_member(T t) -> decltype(t.using_) + { + return t.using_; + } + }; + + // Additional methods for the statement + template + struct _methods_t + { + }; }; + // NO USING YET struct no_using_t { using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; + + _impl_t no_using; + _impl_t& operator()() { return no_using; } + const _impl_t& operator()() const { return no_using; } + + template + static auto _get_member(T t) -> decltype(t.no_using) + { + return t.no_using; + } + }; + template struct _methods_t { @@ -110,7 +170,7 @@ namespace sqlpp auto using_(Args... args) -> _new_statement_t> { - return { *static_cast(this), using_t{args...} }; + return { *static_cast(this), using_data_t{args...} }; } template @@ -118,16 +178,16 @@ namespace sqlpp -> _new_statement_t> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_using must not be called in a static statement"); - return { *static_cast(this), vendor::using_t<_database_t, Args...>{args...} }; + return { *static_cast(this), using_data_t<_database_t, Args...>{args...} }; } }; }; // Interpreters template - struct serializer_t> + struct serializer_t> { - using T = using_t; + using T = using_data_t; static Context& _(const T& t, Context& context) { @@ -141,17 +201,6 @@ namespace sqlpp return context; } }; - - template - struct serializer_t - { - using T = no_using_t; - - static Context& _(const T& t, Context& context) - { - return context; - } - }; } } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9de5e4e2..d7fcb902 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,8 +7,8 @@ macro (build_and_run arg) endmacro () #build_and_run(InterpretTest) -build_and_run(InsertTest) -#build_and_run(RemoveTest) +#build_and_run(InsertTest) +build_and_run(RemoveTest) #build_and_run(UpdateTest) #build_and_run(SelectTest) #build_and_run(SelectTypeTest) diff --git a/tests/RemoveTest.cpp b/tests/RemoveTest.cpp index f4ce1302..777e944e 100644 --- a/tests/RemoveTest.cpp +++ b/tests/RemoveTest.cpp @@ -60,8 +60,8 @@ int main() serialize(remove_from(t).where(t.beta != "transparent"), printer).str(); serialize(remove_from(t).using_(t), printer).str(); auto r = dynamic_remove_from(db, t).dynamic_using().dynamic_where(); - r.add_using(t); - r.add_where(t.beta != "transparent"); + r.using_.add(t); + r.where.add(t.beta != "transparent"); serialize(r, printer).str(); db(r); From d36037472fb97bfdc5f5783b0eed38550560fee5 Mon Sep 17 00:00:00 2001 From: rbock Date: Wed, 4 Jun 2014 09:26:10 +0200 Subject: [PATCH 27/65] Migrated update to generic statement --- include/sqlpp11/update.h | 10 +-- include/sqlpp11/vendor/update_list.h | 130 ++++++++++++++++++--------- tests/CMakeLists.txt | 4 +- tests/UpdateTest.cpp | 4 +- 4 files changed, 97 insertions(+), 51 deletions(-) diff --git a/include/sqlpp11/update.h b/include/sqlpp11/update.h index 1368d6a4..7c9ab963 100644 --- a/include/sqlpp11/update.h +++ b/include/sqlpp11/update.h @@ -27,6 +27,8 @@ #ifndef SQLPP_UPDATE_H #define SQLPP_UPDATE_H +#include + #include #include #include @@ -34,13 +36,10 @@ #include #include #include -#include - -#include -#include namespace sqlpp { +#if 0 template struct update_t; @@ -178,9 +177,10 @@ namespace sqlpp } }; } +#endif template - using blank_update_t = update_t; diff --git a/include/sqlpp11/vendor/update_list.h b/include/sqlpp11/vendor/update_list.h index a4755658..8cd99bea 100644 --- a/include/sqlpp11/vendor/update_list.h +++ b/include/sqlpp11/vendor/update_list.h @@ -36,6 +36,24 @@ namespace sqlpp { namespace vendor { + // UPDATE ASSIGNMENTS DATA + template + struct update_list_data_t + { + update_list_data_t(Assignments... assignments): + _assignments(assignments...) + {} + + update_list_data_t(const update_list_data_t&) = default; + update_list_data_t(update_list_data_t&&) = default; + update_list_data_t& operator=(const update_list_data_t&) = default; + update_list_data_t& operator=(update_list_data_t&&) = default; + ~update_list_data_t() = default; + + std::tuple _assignments; + typename vendor::interpretable_list_t _dynamic_assignments; + }; + // UPDATE ASSIGNMENTS template struct update_list_t @@ -61,57 +79,70 @@ namespace sqlpp static_assert(::sqlpp::detail::is_subset_of<_value_table_set, _column_table_set>::value, "set() contains values from foreign tables"); */ - update_list_t& _update_list() { return *this; } + // Data + using _data_t = update_list_data_t; - update_list_t(Assignments... assignments): - _assignments(assignments...) - {} - - update_list_t(const update_list_t&) = default; - update_list_t(update_list_t&&) = default; - update_list_t& operator=(const update_list_t&) = default; - update_list_t& operator=(update_list_t&&) = default; - ~update_list_t() = default; - - template - struct _methods_t + // Member implementation with data and methods + template + struct _impl_t { template - void add_set_ntc(Assignment assignment) + void add_ntc(Assignment assignment) { - add_set(assignment); + add(assignment); } template - void add_set(Assignment assignment) + void add(Assignment assignment) { - static_assert(_is_dynamic::value, "add_set must not be called for static from()"); - static_assert(is_assignment_t::value, "invalid assignment argument in add_set()"); - static_assert(sqlpp::detail::not_t::value, "add_set() argument must not be updated"); - static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "assignment uses tables unknown to this statement in add_set()"); + static_assert(_is_dynamic::value, "add must not be called for static from()"); + static_assert(is_assignment_t::value, "invalid assignment argument in add()"); + static_assert(sqlpp::detail::not_t::value, "add() argument must not be updated"); + static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "assignment uses tables unknown to this statement in add()"); using ok = ::sqlpp::detail::all_t< _is_dynamic::value, is_assignment_t::value, not must_not_update_t::value>; - _add_set_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert + _add_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert } private: template - void _add_set_impl(Assignment assignment, const std::true_type&) + void _add_impl(Assignment assignment, const std::true_type&) { - return static_cast(this)->_update_list()._dynamic_assignments.emplace_back(assignment); + return _data._dynamic_assignments.emplace_back(assignment); } template - void _add_set_impl(Assignment assignment, const std::false_type&); + void _add_impl(Assignment assignment, const std::false_type&); + public: + _data_t _data; }; + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = update_list_data_t; - std::tuple _assignments; - typename vendor::interpretable_list_t _dynamic_assignments; + _impl_t assignments; + _impl_t& operator()() { return assignments; } + const _impl_t& operator()() const { return assignments; } + + template + static auto _get_member(T t) -> decltype(t.assignments) + { + return t.assignments; + } + }; + + // Additional methods for the statement + template + struct _methods_t + { + }; }; struct no_update_list_t @@ -119,6 +150,33 @@ namespace sqlpp using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; + + _impl_t no_assignments; + _impl_t& operator()() { return no_assignments; } + const _impl_t& operator()() const { return no_assignments; } + + template + static auto _get_member(T t) -> decltype(t.no_assignments) + { + return t.no_assignments; + } + }; + template struct _methods_t { @@ -130,7 +188,7 @@ namespace sqlpp auto set(Args... args) -> _new_statement_t> { - return { *static_cast(this), update_list_t{args...} }; + return { *static_cast(this), update_list_data_t{args...} }; } template @@ -138,16 +196,16 @@ namespace sqlpp -> _new_statement_t> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_set must not be called in a static statement"); - return { *static_cast(this), vendor::update_list_t<_database_t, Args...>{args...} }; + return { *static_cast(this), vendor::update_list_data_t<_database_t, Args...>{args...} }; } }; }; // Interpreters template - struct serializer_t> + struct serializer_t> { - using T = update_list_t; + using T = update_list_data_t; static Context& _(const T& t, Context& context) { @@ -159,18 +217,6 @@ namespace sqlpp return context; } }; - - template - struct serializer_t - { - using T = no_update_list_t; - - static Context& _(const T& t, Context& context) - { - return context; - } - }; - } } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d7fcb902..280fe484 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,8 +8,8 @@ endmacro () #build_and_run(InterpretTest) #build_and_run(InsertTest) -build_and_run(RemoveTest) -#build_and_run(UpdateTest) +#build_and_run(RemoveTest) +build_and_run(UpdateTest) #build_and_run(SelectTest) #build_and_run(SelectTypeTest) #build_and_run(FunctionTest) diff --git a/tests/UpdateTest.cpp b/tests/UpdateTest.cpp index fcf0c6d3..cc75f897 100644 --- a/tests/UpdateTest.cpp +++ b/tests/UpdateTest.cpp @@ -61,8 +61,8 @@ int main() serialize(update(t).set(t.gamma = false).where(t.beta != "transparent"), printer).str(); serialize(update(t).set(t.beta = "opaque").where(t.beta != t.beta), printer).str(); auto u = dynamic_update(db, t).dynamic_set(t.gamma = false).dynamic_where(); - u.add_set(t.gamma = false); - u.add_where(t.gamma != false); + u.assignments.add(t.gamma = false); + u.where.add(t.gamma != false); serialize(u, printer).str(); db(u); From 067740d24ebcceb0dfc5b85144fb778cf96f5bb4 Mon Sep 17 00:00:00 2001 From: rbock Date: Wed, 4 Jun 2014 18:35:25 +0200 Subject: [PATCH 28/65] InterpretTest compiles again --- include/sqlpp11/functions.h | 4 ++-- include/sqlpp11/integral.h | 1 + include/sqlpp11/join.h | 2 +- include/sqlpp11/parameter.h | 4 ++-- include/sqlpp11/table_alias.h | 10 ++++---- include/sqlpp11/tvin.h | 2 ++ include/sqlpp11/type_traits.h | 1 + include/sqlpp11/vendor/expression.h | 2 +- include/sqlpp11/vendor/insert_value_list.h | 10 ++++---- include/sqlpp11/vendor/limit.h | 4 ++-- include/sqlpp11/vendor/select_pseudo_table.h | 4 ++-- include/sqlpp11/vendor/wrap_operand.h | 8 +++---- tests/CMakeLists.txt | 4 ++-- tests/InsertTest.cpp | 4 ++-- tests/InterpretTest.cpp | 24 ++++++++++---------- 15 files changed, 43 insertions(+), 41 deletions(-) diff --git a/include/sqlpp11/functions.h b/include/sqlpp11/functions.h index 16742105..2d8ce0f6 100644 --- a/include/sqlpp11/functions.h +++ b/include/sqlpp11/functions.h @@ -50,7 +50,7 @@ namespace sqlpp { using _provided_tables = detail::type_set<>; using _required_tables = ::sqlpp::detail::type_set<>; - static_assert(not is_expression_t::value, "value() is to be called with non-sql-type like int, or string"); + static_assert(is_wrapped_value_t>::value, "value() is to be called with non-sql-type like int, or string"); return { t }; } @@ -149,7 +149,7 @@ namespace sqlpp template auto value_list(Container c) -> value_list_t { - static_assert(not is_expression_t::value, "value_list() is to be called with a container of non-sql-type like std::vector, or std::list(string)"); + static_assert(is_wrapped_value_t>::value, "value_list() is to be called with a container of non-sql-type like std::vector, or std::list(string)"); return { c }; } diff --git a/include/sqlpp11/integral.h b/include/sqlpp11/integral.h index 34366d85..b5e2ad85 100644 --- a/include/sqlpp11/integral.h +++ b/include/sqlpp11/integral.h @@ -42,6 +42,7 @@ namespace sqlpp // integral value type struct integral { + using _traits = make_traits; using _tag = ::sqlpp::tag::integral; using _cpp_value_type = int64_t; diff --git a/include/sqlpp11/join.h b/include/sqlpp11/join.h index d4f96abf..926de5c2 100644 --- a/include/sqlpp11/join.h +++ b/include/sqlpp11/join.h @@ -85,7 +85,7 @@ namespace sqlpp static_assert(not is_join_t::value, "rhs argument for join must not be a join"); static_assert(vendor::is_noop::value or is_on_t::value, "invalid on expression in join().on()"); - static_assert(::sqlpp::detail::is_disjunct_from::value, "joined tables must not be identical"); + static_assert(::sqlpp::detail::is_disjunct_from, provided_tables_of>::value, "joined tables must not be identical"); static_assert(_recursive_traits::_required_tables::size::value == 0, "joined tables must not depend on other tables"); diff --git a/include/sqlpp11/parameter.h b/include/sqlpp11/parameter.h index b3769639..565f236a 100644 --- a/include/sqlpp11/parameter.h +++ b/include/sqlpp11/parameter.h @@ -74,7 +74,7 @@ namespace sqlpp template auto parameter(const NamedExpr&) - -> parameter_t + -> parameter_t, NamedExpr> { static_assert(is_named_expression_t::value, "not a named expression"); return {}; @@ -82,7 +82,7 @@ namespace sqlpp template auto parameter(const ValueType&, const AliasProvider&) - -> parameter_t + -> parameter_t, AliasProvider> { static_assert(is_expression_t::value, "first argument is not a value type"); static_assert(is_alias_provider_t::value, "second argument is not an alias provider"); diff --git a/include/sqlpp11/table_alias.h b/include/sqlpp11/table_alias.h index 754ec175..e357973c 100644 --- a/include/sqlpp11/table_alias.h +++ b/include/sqlpp11/table_alias.h @@ -35,10 +35,8 @@ namespace sqlpp { - struct table_alias_base_t {}; - template - struct table_alias_t: public table_alias_base_t, public ColumnSpec::_name_t::template _member_t>... + struct table_alias_t: public ColumnSpec::_name_t::template _member_t>... { //FIXME: Need to add join functionality using _traits = make_traits, tag::table, tag::alias, tag::named_expression_if>>; @@ -65,10 +63,10 @@ namespace sqlpp namespace vendor { - template - struct serializer_t::value, void>::type> + template + struct serializer_t> { - using T = X; + using T = table_alias_t; static Context& _(const T& t, Context& context) { diff --git a/include/sqlpp11/tvin.h b/include/sqlpp11/tvin.h index 1a517714..255f9d3e 100644 --- a/include/sqlpp11/tvin.h +++ b/include/sqlpp11/tvin.h @@ -42,6 +42,8 @@ namespace sqlpp using _traits = make_traits, tag::expression>; using _recursive_traits = make_recursive_traits; + using _operand_t = Operand; + tvin_t(Operand operand): _value(operand) {} diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index a195f1c0..f276dea3 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -88,6 +88,7 @@ namespace sqlpp detail::is_element_of::value, detail::is_element_of::value>; SQLPP_IS_VALUE_TRAIT_GENERATOR(text); + SQLPP_IS_VALUE_TRAIT_GENERATOR(wrapped_value); SQLPP_IS_VALUE_TRAIT_GENERATOR(expression); SQLPP_IS_VALUE_TRAIT_GENERATOR(named_expression); namespace tag diff --git a/include/sqlpp11/vendor/expression.h b/include/sqlpp11/vendor/expression.h index 17ef6e9e..e91b2d68 100644 --- a/include/sqlpp11/vendor/expression.h +++ b/include/sqlpp11/vendor/expression.h @@ -203,7 +203,7 @@ namespace sqlpp }; template - struct unary_expression_t: public O::_value_type::template expression_operators>, + struct unary_expression_t: public value_type_of::template expression_operators>, public alias_operators> { using _traits = make_traits, sqlpp::tag::expression>; diff --git a/include/sqlpp11/vendor/insert_value_list.h b/include/sqlpp11/vendor/insert_value_list.h index bd9a1be8..f4cb6794 100644 --- a/include/sqlpp11/vendor/insert_value_list.h +++ b/include/sqlpp11/vendor/insert_value_list.h @@ -282,14 +282,14 @@ namespace sqlpp { using _data_t = column_list_data_t; - _impl_t column_list; - _impl_t& operator()() { return column_list; } - const _impl_t& operator()() const { return column_list; } + _impl_t values; + _impl_t& operator()() { return values; } + const _impl_t& operator()() const { return values; } template - static auto _get_member(T t) -> decltype(t.column_list) + static auto _get_member(T t) -> decltype(t.values) { - return t.column_list; + return t.values; } }; diff --git a/include/sqlpp11/vendor/limit.h b/include/sqlpp11/vendor/limit.h index cd5884c4..588b31ee 100644 --- a/include/sqlpp11/vendor/limit.h +++ b/include/sqlpp11/vendor/limit.h @@ -243,9 +243,9 @@ namespace sqlpp }; template - struct serializer_t> + struct serializer_t> { - using T = limit_t; + using T = limit_data_t; static Context& _(const T& t, Context& context) { diff --git a/include/sqlpp11/vendor/select_pseudo_table.h b/include/sqlpp11/vendor/select_pseudo_table.h index eae7ce5a..86e9e4b9 100644 --- a/include/sqlpp11/vendor/select_pseudo_table.h +++ b/include/sqlpp11/vendor/select_pseudo_table.h @@ -55,8 +55,8 @@ namespace sqlpp Select, NamedExpr...>, select_column_spec_t...> { - using _value_type = no_value_t; - using _is_pseudo_table = std::true_type; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; select_pseudo_table_t(Select select): _select(select) diff --git a/include/sqlpp11/vendor/wrap_operand.h b/include/sqlpp11/vendor/wrap_operand.h index 9012aa98..2a832e07 100644 --- a/include/sqlpp11/vendor/wrap_operand.h +++ b/include/sqlpp11/vendor/wrap_operand.h @@ -45,7 +45,7 @@ namespace sqlpp { struct boolean_operand { - using _traits = make_traits<::sqlpp::detail::boolean, ::sqlpp::tag::expression>; + using _traits = make_traits<::sqlpp::detail::boolean, ::sqlpp::tag::expression, ::sqlpp::tag::wrapped_value>; using _recursive_traits = make_recursive_traits<>; using _value_t = bool; @@ -83,7 +83,7 @@ namespace sqlpp struct integral_operand { - using _traits = make_traits<::sqlpp::detail::integral, ::sqlpp::tag::expression>; + using _traits = make_traits<::sqlpp::detail::integral, ::sqlpp::tag::expression, ::sqlpp::tag::wrapped_value>; using _recursive_traits = make_recursive_traits<>; using _value_t = int64_t; @@ -122,7 +122,7 @@ namespace sqlpp struct floating_point_operand { - using _traits = make_traits<::sqlpp::detail::floating_point, ::sqlpp::tag::expression>; + using _traits = make_traits<::sqlpp::detail::floating_point, ::sqlpp::tag::expression, ::sqlpp::tag::wrapped_value>; using _recursive_traits = make_recursive_traits<>; using _value_t = double; @@ -160,7 +160,7 @@ namespace sqlpp struct text_operand { - using _traits = make_traits<::sqlpp::detail::text, ::sqlpp::tag::expression>; + using _traits = make_traits<::sqlpp::detail::text, ::sqlpp::tag::expression, ::sqlpp::tag::wrapped_value>; using _recursive_traits = make_recursive_traits<>; using _value_t = std::string; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 280fe484..8ebcb6f0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,10 +6,10 @@ macro (build_and_run arg) add_test(${arg} ${arg}) endmacro () -#build_and_run(InterpretTest) +build_and_run(InterpretTest) #build_and_run(InsertTest) #build_and_run(RemoveTest) -build_and_run(UpdateTest) +#build_and_run(UpdateTest) #build_and_run(SelectTest) #build_and_run(SelectTypeTest) #build_and_run(FunctionTest) diff --git a/tests/InsertTest.cpp b/tests/InsertTest.cpp index 683ed401..1bee7ba9 100644 --- a/tests/InsertTest.cpp +++ b/tests/InsertTest.cpp @@ -67,8 +67,8 @@ int main() serialize(insert_into(t).set(t.beta = "kirschauflauf"), printer).str(); serialize(insert_into(t).columns(t.beta), printer).str(); auto multi_insert = insert_into(t).columns(t.beta, t.delta); - multi_insert.column_list.add(t.beta = "cheesecake", t.delta = 1); - multi_insert.column_list.add(t.beta = sqlpp::default_value, t.delta = sqlpp::default_value); + multi_insert.values.add(t.beta = "cheesecake", t.delta = 1); + multi_insert.values.add(t.beta = sqlpp::default_value, t.delta = sqlpp::default_value); auto i = dynamic_insert_into(db, t).dynamic_set(); i.insert_list.add(t.beta = "kirschauflauf"); serialize(i, printer).str(); diff --git a/tests/InterpretTest.cpp b/tests/InterpretTest.cpp index 2fd5c3a3..08c33f94 100644 --- a/tests/InterpretTest.cpp +++ b/tests/InterpretTest.cpp @@ -46,12 +46,12 @@ int main() serialize(insert_into(t).columns(t.beta, t.gamma), printer).str(); { auto i = insert_into(t).columns(t.gamma, t.beta); - i.add_values(t.gamma = true, t.beta = "cheesecake"); + i.values.add(t.gamma = true, t.beta = "cheesecake"); serialize(i, printer).str(); - i.add_values(t.gamma = false, t.beta = sqlpp::tvin("coffee")); - i.add_values(t.gamma = false, t.beta = sqlpp::tvin(std::string())); + i.values.add(t.gamma = false, t.beta = sqlpp::tvin("coffee")); + i.values.add(t.gamma = false, t.beta = sqlpp::tvin(std::string())); serialize(i, printer).str(); - i.add_values(t.gamma = sqlpp::default_value, t.beta = sqlpp::null); + i.values.add(t.gamma = sqlpp::default_value, t.beta = sqlpp::null); serialize(i, printer).str(); } @@ -134,22 +134,22 @@ int main() // dynamic select { auto s = dynamic_select(db).dynamic_flags().dynamic_columns().from(t); - s.add_column(t.beta); - s.add_column(t.gamma); + s.selected_columns.add(t.beta); + s.selected_columns.add(t.gamma); serialize(s, printer).str(); } { auto s = dynamic_select(db).dynamic_flags().dynamic_columns().from(t); - s.add_flag(sqlpp::distinct); - s.add_column(t.beta); - s.add_column(t.gamma); + s.select_flags.add(sqlpp::distinct); + s.selected_columns.add(t.beta); + s.selected_columns.add(t.gamma); serialize(s, printer).str(); } { auto s = dynamic_select(db).dynamic_flags(sqlpp::distinct).dynamic_columns(t.alpha).extra_tables(t); // Would fail to run() - s.add_flag(sqlpp::all); - s.add_column(t.beta); - s.add_column(t.gamma); + s.select_flags.add(sqlpp::all); + s.selected_columns.add(t.beta); + s.selected_columns.add(t.gamma); serialize(s, printer).str(); } From 79aa358624fd96586e3242838cccc12cf4b8e881 Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 5 Jun 2014 08:32:22 +0200 Subject: [PATCH 29/65] Added into member for insert. Update and remove will get table lists with more than one table --- include/sqlpp11/insert.h | 4 +- include/sqlpp11/type_traits.h | 1 + include/sqlpp11/vendor/into.h | 216 ++++++++++++++++++++++++++ include/sqlpp11/vendor/single_table.h | 27 ++-- tests/CMakeLists.txt | 8 +- 5 files changed, 233 insertions(+), 23 deletions(-) create mode 100644 include/sqlpp11/vendor/into.h diff --git a/include/sqlpp11/insert.h b/include/sqlpp11/insert.h index 7ed0e7e2..3a8fdbd7 100644 --- a/include/sqlpp11/insert.h +++ b/include/sqlpp11/insert.h @@ -33,14 +33,14 @@ #include #include #include -#include +#include #include namespace sqlpp { template using blank_insert_t = statement_t; auto insert() diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index f276dea3..6df505f4 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -123,6 +123,7 @@ namespace sqlpp SQLPP_IS_VALUE_TRAIT_GENERATOR(select_column_list); SQLPP_IS_VALUE_TRAIT_GENERATOR(from); SQLPP_IS_VALUE_TRAIT_GENERATOR(single_table); + SQLPP_IS_VALUE_TRAIT_GENERATOR(into); SQLPP_IS_VALUE_TRAIT_GENERATOR(extra_tables); SQLPP_IS_VALUE_TRAIT_GENERATOR(on); SQLPP_IS_VALUE_TRAIT_GENERATOR(dynamic); diff --git a/include/sqlpp11/vendor/into.h b/include/sqlpp11/vendor/into.h new file mode 100644 index 00000000..5d474e9c --- /dev/null +++ b/include/sqlpp11/vendor/into.h @@ -0,0 +1,216 @@ +/* + * Copyright (c) 2013-2014, 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. + */ + +#ifndef SQLPP_VENDOR_INTO_H +#define SQLPP_VENDOR_INTO_H + +#include +#include +#include +#include + +namespace sqlpp +{ + namespace vendor + { + // A SINGLE TABLE DATA + template + struct into_data_t + { + into_data_t(Table table): + _table(table) + {} + + into_data_t(const into_data_t&) = default; + into_data_t(into_data_t&&) = default; + into_data_t& operator=(const into_data_t&) = default; + into_data_t& operator=(into_data_t&&) = default; + ~into_data_t() = default; + + Table _table; + }; + + // A SINGLE TABLE + template + struct into_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits
; + + static_assert(is_table_t
::value, "argument has to be a table"); + static_assert(required_tables_of
::size::value == 0, "table depends on another table"); + + using _data_t = into_data_t; + + struct _name_t {}; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = into_data_t; + + _impl_t into; + _impl_t& operator()() { return into; } + const _impl_t& operator()() const { return into; } + + template + static auto _get_member(T t) -> decltype(t.into) + { + return t.into; + } + }; + + // Additional methods for the statement + template + struct _methods_t + { + }; + + template + struct _result_methods_t + { + using _statement_t = typename Policies::_statement_t; + + const _statement_t& _get_statement() const + { + return static_cast(*this); + } + + static constexpr size_t _get_static_no_of_parameters() + { +#warning need to fix this + return 0; + //return _parameter_list_t::size::value; + } + + size_t _get_no_of_parameters() const + { +#warning need to fix this + return 0; + //return _parameter_list_t::size::value; + } + + void _check_consistency() const + { + // FIXME: Read up on what is allowed/prohibited in INSERT + } + + template + auto _run(Db& db) const -> decltype(db.insert(_get_statement())) + { + _check_consistency(); + + static_assert(_get_static_no_of_parameters() == 0, "cannot run insert directly with parameters, use prepare instead"); + return db.insert(*this); + } + + /* + template + auto _prepare(Db& db) const + -> prepared_insert_t + { + _check_consistency(); + + return {{}, db.prepare_insert(*this)}; + } + */ + }; + }; + + // NO INTO YET + struct no_into_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; + + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; + + _impl_t no_into; + _impl_t& operator()() { return no_into; } + const _impl_t& operator()() const { return no_into; } + + template + static auto _get_member(T t) -> decltype(t.no_into) + { + return t.no_into; + } + }; + + template + struct _methods_t + { + using _database_t = typename Policies::_database_t; + template + using _new_statement_t = typename Policies::template _new_statement_t; + + template + auto into(Args... args) + -> _new_statement_t> + { + return { *static_cast(this), into_data_t{args...} }; + } + }; + }; + + // Interpreters + template + struct serializer_t> + { + using T = into_data_t; + + static Context& _(const T& t, Context& context) + { + serialize(t._table, context); + return context; + } + }; + + } +} + +#endif diff --git a/include/sqlpp11/vendor/single_table.h b/include/sqlpp11/vendor/single_table.h index 7d83c838..9826b35f 100644 --- a/include/sqlpp11/vendor/single_table.h +++ b/include/sqlpp11/vendor/single_table.h @@ -80,14 +80,14 @@ namespace sqlpp { using _data_t = single_table_data_t; - _impl_t into; - _impl_t& operator()() { return into; } - const _impl_t& operator()() const { return into; } + _impl_t from; + _impl_t& operator()() { return from; } + const _impl_t& operator()() const { return from; } template - static auto _get_member(T t) -> decltype(t.into) + static auto _get_member(T t) -> decltype(t.from) { - return t.into; + return t.from; } }; @@ -170,14 +170,14 @@ namespace sqlpp { using _data_t = no_data_t; - _impl_t no_into; - _impl_t& operator()() { return no_into; } - const _impl_t& operator()() const { return no_into; } + _impl_t no_from; + _impl_t& operator()() { return no_from; } + const _impl_t& operator()() const { return no_from; } template - static auto _get_member(T t) -> decltype(t.no_into) + static auto _get_member(T t) -> decltype(t.no_from) { - return t.no_into; + return t.no_from; } }; @@ -188,13 +188,6 @@ namespace sqlpp template using _new_statement_t = typename Policies::template _new_statement_t; - template - auto into(Args... args) - -> _new_statement_t> - { - return { *static_cast(this), single_table_data_t{args...} }; - } - #warning: remove can operate on several tables at once, so it should not use single_table anyway template auto from(Args... args) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8ebcb6f0..a5124694 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,10 +6,10 @@ macro (build_and_run arg) add_test(${arg} ${arg}) endmacro () -build_and_run(InterpretTest) -#build_and_run(InsertTest) -#build_and_run(RemoveTest) -#build_and_run(UpdateTest) +#build_and_run(InterpretTest) +build_and_run(InsertTest) +build_and_run(RemoveTest) +build_and_run(UpdateTest) #build_and_run(SelectTest) #build_and_run(SelectTypeTest) #build_and_run(FunctionTest) From f8e0e9047759eb67f43b61dadf8cabb500312264 Mon Sep 17 00:00:00 2001 From: rbock Date: Mon, 9 Jun 2014 14:06:04 +0200 Subject: [PATCH 30/65] Fixed serializability of statements --- include/sqlpp11/insert.h | 22 +++++ include/sqlpp11/remove.h | 80 +++++++++++++++- include/sqlpp11/select.h | 22 +++++ include/sqlpp11/statement.h | 45 ++++++++- include/sqlpp11/update.h | 166 +++++++++++----------------------- include/sqlpp11/vendor/into.h | 1 + tests/CMakeLists.txt | 2 +- tests/InsertTest.cpp | 3 +- tests/MockDb.h | 2 +- tests/RemoveTest.cpp | 5 +- tests/SelectTest.cpp | 3 + tests/UpdateTest.cpp | 4 +- 12 files changed, 228 insertions(+), 127 deletions(-) diff --git a/include/sqlpp11/insert.h b/include/sqlpp11/insert.h index 3a8fdbd7..fa9320fb 100644 --- a/include/sqlpp11/insert.h +++ b/include/sqlpp11/insert.h @@ -38,8 +38,30 @@ namespace sqlpp { + struct insert_name_t {}; + + struct insert_t: public vendor::statement_name_t + {}; + + namespace vendor + { + template + struct serializer_t + { + using T = insert_name_t; + + static Context& _(const T& t, Context& context) + { + context << "INSERT "; + + return context; + } + }; + } + template using blank_insert_t = statement_t; diff --git a/include/sqlpp11/remove.h b/include/sqlpp11/remove.h index 305af315..753c2539 100644 --- a/include/sqlpp11/remove.h +++ b/include/sqlpp11/remove.h @@ -33,17 +33,91 @@ #include #include #warning: need to use another table provider, since delete can be used with several tables -#include +#include #include #include #include namespace sqlpp { + struct remove_name_t {}; + struct remove_t: public vendor::statement_name_t + { + using _traits = make_traits; + struct _name_t {}; + + template + struct _result_methods_t + { + using _statement_t = typename Policies::_statement_t; + + const _statement_t& _get_statement() const + { + return static_cast(*this); + } + + static constexpr size_t _get_static_no_of_parameters() + { +#warning need to fix this + return 0; + //return _parameter_list_t::size::value; + } + + size_t _get_no_of_parameters() const + { +#warning need to fix this + return 0; + //return _parameter_list_t::size::value; + } + + void _check_consistency() const + { + // FIXME: Read up on what is allowed/prohibited in INSERT + } + + template + auto _run(Db& db) const -> decltype(db.remove(_get_statement())) + { + _check_consistency(); + + static_assert(_get_static_no_of_parameters() == 0, "cannot run remove directly with parameters, use prepare instead"); + return db.remove(*this); + } + + /* + template + auto _prepare(Db& db) const + -> prepared_remove_t + { + _check_consistency(); + + return {{}, db.prepare_remove(*this)}; + } + */ + }; + }; + + + namespace vendor + { + template + struct serializer_t + { + using T = remove_name_t; + + static Context& _(const T& t, Context& context) + { + context << "DELETE"; + + return context; + } + }; + } + template using blank_remove_t = statement_t; diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index a49b0201..bda042f9 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -46,8 +46,30 @@ namespace sqlpp { + struct select_name_t {}; + + struct select_t: public vendor::statement_name_t + {}; + + namespace vendor + { + template + struct serializer_t + { + using T = select_name_t; + + static Context& _(const T& t, Context& context) + { + context << "SELECT "; + + return context; + } + }; + } + template using blank_select_t = statement_t @@ -178,15 +177,53 @@ namespace sqlpp static Context& _(const T& t, Context& context) { -#warning: Need to have a class that provides the "SELECT" or "INSERT", etc - context << "SELECT "; - using swallow = int[]; (void) swallow{(serialize(static_cast&>(t)()._data, context), 0)...}; return context; } }; + + template + struct statement_name_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; + + // Data + using _data_t = NameData; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = NameData; + + _impl_t statement_name; + _impl_t& operator()() { return statement_name; } + const _impl_t& operator()() const { return statement_name; } + + template + static auto _get_member(T t) -> decltype(t.statement_name) + { + return t.statement_name; + } + }; + + // Additional methods for the statement + template + struct _methods_t + { + }; + }; + } } diff --git a/include/sqlpp11/update.h b/include/sqlpp11/update.h index 7c9ab963..d83909b8 100644 --- a/include/sqlpp11/update.h +++ b/include/sqlpp11/update.h @@ -39,148 +39,84 @@ namespace sqlpp { -#if 0 - template - struct update_t; + struct update_name_t {}; - namespace detail + struct update_t: public vendor::statement_name_t { - template - struct update_policies_t + using _traits = make_traits; + struct _name_t {}; + + template + struct _result_methods_t { - using _database_t = Db; + using _statement_t = typename Policies::_statement_t; - using _statement_t = update_t; + const _statement_t& _get_statement() const + { + return static_cast(*this); + } - struct _methods_t: public Policies::template _methods_t... - {}; + static constexpr size_t _get_static_no_of_parameters() + { +#warning need to fix this + return 0; + //return _parameter_list_t::size::value; + } - template - struct _policies_update_t + size_t _get_no_of_parameters() const + { +#warning need to fix this + return 0; + //return _parameter_list_t::size::value; + } + + void _check_consistency() const + { + // FIXME: Read up on what is allowed/prohibited in INSERT + } + + template + auto _run(Db& db) const -> decltype(db.update(_get_statement())) { - static_assert(detail::is_element_of>::value, "policies update for non-policy class detected"); - using type = update_t...>; - }; + _check_consistency(); - template - using _new_statement_t = typename _policies_update_t::type; + static_assert(_get_static_no_of_parameters() == 0, "cannot run update directly with parameters, use prepare instead"); + return db.update(*this); + } - using _all_required_tables = detail::make_joined_set_t...>; - using _all_provided_tables = detail::make_joined_set_t...>; - using _all_extra_tables = detail::make_joined_set_t...>; - - using _known_tables = detail::make_joined_set_t<_all_provided_tables, _all_extra_tables>; - - template - using _no_unknown_tables = detail::is_subset_of, _known_tables>; - - // The tables not covered by the from. - using _required_tables = detail::make_difference_set_t< - _all_required_tables, - _all_provided_tables // Hint: extra_tables are not used here because they are just a helper for dynamic .add_*() - >; - - using _traits = make_traits; // FIXME - - struct _recursive_traits - { - using _parameters = std::tuple<>; // FIXME - using _required_tables = _required_tables; - using _provided_tables = detail::type_set<>; - using _extra_tables = detail::type_set<>; - }; - }; - } - - // UPDATE - template - struct update_t: - public Policies..., - public detail::update_policies_t::_methods_t - { - using _policies_t = typename detail::update_policies_t; - using _database_t = typename _policies_t::_database_t; - - using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - - using _parameter_list_t = typename make_parameter_list_t::type; - - // Constructors - constexpr update_t() - {} - - template - update_t(Statement statement, Term term): - Policies(detail::pick_arg(statement, term))... - {} - - update_t(const update_t&) = default; - update_t(update_t&&) = default; - update_t& operator=(const update_t&) = default; - update_t& operator=(update_t&&) = default; - ~update_t() = default; - - // run and prepare - static constexpr size_t _get_static_no_of_parameters() - { - return _parameter_list_t::size::value; - } - - size_t _get_no_of_parameters() const - { - return _parameter_list_t::size::value; - } - - void _check_consistency() const - { -#warning reactivate tests /* - static_assert(is_where_t<_where_t>::value, "cannot run update without having a where condition, use .where(true) to update all rows"); + template + auto _prepare(Db& db) const + -> prepared_update_t + { + _check_consistency(); - static_assert(is_table_subset_of_table<_update_list_t>::value, "updates require additional tables"); - static_assert(is_table_subset_of_table<_where_t>::value, "where requires additional tables"); - */ - } + return {{}, db.prepare_update(*this)}; + } + */ + }; + }; - template - std::size_t _run(Database& db) const - { - _check_consistency(); - - static_assert(_get_static_no_of_parameters() == 0, "cannot run update directly with parameters, use prepare instead"); - return db.update(*this); - } - - template - auto _prepare(Database& db) const - -> prepared_update_t - { - _check_consistency(); - - return {{}, db.prepare_update(*this)}; - } - }; namespace vendor { - template - struct serializer_t> + template + struct serializer_t { - using T = update_t; + using T = update_name_t; static Context& _(const T& t, Context& context) { context << "UPDATE "; - using swallow = int[]; - (void) swallow{(serialize(static_cast(t), context), 0)...}; + return context; } }; } -#endif template using blank_update_t = statement_t; diff --git a/include/sqlpp11/vendor/into.h b/include/sqlpp11/vendor/into.h index 5d474e9c..f88249c1 100644 --- a/include/sqlpp11/vendor/into.h +++ b/include/sqlpp11/vendor/into.h @@ -205,6 +205,7 @@ namespace sqlpp static Context& _(const T& t, Context& context) { + context << " INTO "; serialize(t._table, context); return context; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a5124694..9ea24a1f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,7 +10,7 @@ endmacro () build_and_run(InsertTest) build_and_run(RemoveTest) build_and_run(UpdateTest) -#build_and_run(SelectTest) +build_and_run(SelectTest) #build_and_run(SelectTypeTest) #build_and_run(FunctionTest) #build_and_run(PreparedTest) diff --git a/tests/InsertTest.cpp b/tests/InsertTest.cpp index 1bee7ba9..7a50f1c4 100644 --- a/tests/InsertTest.cpp +++ b/tests/InsertTest.cpp @@ -71,7 +71,8 @@ int main() multi_insert.values.add(t.beta = sqlpp::default_value, t.delta = sqlpp::default_value); auto i = dynamic_insert_into(db, t).dynamic_set(); i.insert_list.add(t.beta = "kirschauflauf"); - serialize(i, printer).str(); + printer.reset(); + std::cerr << serialize(i, printer).str() << std::endl; db(multi_insert); diff --git a/tests/MockDb.h b/tests/MockDb.h index fd114baf..a80067de 100644 --- a/tests/MockDb.h +++ b/tests/MockDb.h @@ -43,7 +43,7 @@ struct MockDb: public sqlpp::connection void reset() { - _os.clear(); + _os.str(""); } template diff --git a/tests/RemoveTest.cpp b/tests/RemoveTest.cpp index 777e944e..52636a57 100644 --- a/tests/RemoveTest.cpp +++ b/tests/RemoveTest.cpp @@ -62,7 +62,10 @@ int main() auto r = dynamic_remove_from(db, t).dynamic_using().dynamic_where(); r.using_.add(t); r.where.add(t.beta != "transparent"); - serialize(r, printer).str(); + printer.reset(); + std::cerr << serialize(r, printer).str() << std::endl; + printer.reset(); + std::cerr << serialize(remove_from(t).where(true), printer).str() << std::endl; db(r); diff --git a/tests/SelectTest.cpp b/tests/SelectTest.cpp index e00312fc..14979a1d 100644 --- a/tests/SelectTest.cpp +++ b/tests/SelectTest.cpp @@ -85,6 +85,9 @@ int main() int64_t a = row.alpha; } + printer.reset(); + std::cerr << serialize(s, printer).str() << std::endl; + auto X = select(all_of(t)).from(t).as(t.alpha); return 0; diff --git a/tests/UpdateTest.cpp b/tests/UpdateTest.cpp index cc75f897..364d8a33 100644 --- a/tests/UpdateTest.cpp +++ b/tests/UpdateTest.cpp @@ -61,9 +61,11 @@ int main() serialize(update(t).set(t.gamma = false).where(t.beta != "transparent"), printer).str(); serialize(update(t).set(t.beta = "opaque").where(t.beta != t.beta), printer).str(); auto u = dynamic_update(db, t).dynamic_set(t.gamma = false).dynamic_where(); +#warning: This should fail since gamma is set already u.assignments.add(t.gamma = false); u.where.add(t.gamma != false); - serialize(u, printer).str(); + printer.reset(); + std::cerr << serialize(u, printer).str() << std::endl; db(u); From 4d1b60d93a4b3edd1cb4d0f09ae9a6af9d1f1fc1 Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 13 Jun 2014 09:33:08 +0200 Subject: [PATCH 31/65] Cleanup Moved check_consistency call to statement --- include/sqlpp11/remove.h | 23 +--------- include/sqlpp11/statement.h | 28 ++++++++--- include/sqlpp11/update.h | 27 ++--------- include/sqlpp11/vendor/into.h | 51 +++++++-------------- include/sqlpp11/vendor/select_column_list.h | 18 ++------ tests/CMakeLists.txt | 6 +-- 6 files changed, 49 insertions(+), 104 deletions(-) diff --git a/include/sqlpp11/remove.h b/include/sqlpp11/remove.h index 753c2539..671a310f 100644 --- a/include/sqlpp11/remove.h +++ b/include/sqlpp11/remove.h @@ -56,31 +56,12 @@ namespace sqlpp return static_cast(*this); } - static constexpr size_t _get_static_no_of_parameters() - { -#warning need to fix this - return 0; - //return _parameter_list_t::size::value; - } - - size_t _get_no_of_parameters() const - { -#warning need to fix this - return 0; - //return _parameter_list_t::size::value; - } - - void _check_consistency() const - { - // FIXME: Read up on what is allowed/prohibited in INSERT - } - template auto _run(Db& db) const -> decltype(db.remove(_get_statement())) { - _check_consistency(); + _statement_t::_check_consistency(); - static_assert(_get_static_no_of_parameters() == 0, "cannot run remove directly with parameters, use prepare instead"); + static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run remove directly with parameters, use prepare instead"); return db.remove(*this); } diff --git a/include/sqlpp11/statement.h b/include/sqlpp11/statement.h index 7f77803c..2e7f4026 100644 --- a/include/sqlpp11/statement.h +++ b/include/sqlpp11/statement.h @@ -117,13 +117,6 @@ namespace sqlpp using _provided_tables = detail::type_set<>; using _extra_tables = detail::type_set<>; }; - - static void _check_consistency() - { -#warning check for missing terms here, and for missing tables - static_assert(not required_tables_of::size::value, "one sub expression requires tables which are otherwise not known in the statement"); - } - }; } @@ -165,6 +158,27 @@ namespace sqlpp statement_t& operator=(const statement_t& r) = default; statement_t& operator=(statement_t&& r) = default; ~statement_t() = default; + + static constexpr size_t _get_static_no_of_parameters() + { +#warning need to fix this + return 0; + //return _parameter_list_t::size::value; + } + + size_t _get_no_of_parameters() const + { + return _get_static_no_of_parameters(); + } + + static void _check_consistency() + { + // FIXME: Check each "methods" or each member... +#warning check for missing terms here, and for missing tables + static_assert(not required_tables_of<_policies_t>::size::value, "one sub expression requires tables which are otherwise not known in the statement"); + } + + }; namespace vendor diff --git a/include/sqlpp11/update.h b/include/sqlpp11/update.h index d83909b8..9fd1414d 100644 --- a/include/sqlpp11/update.h +++ b/include/sqlpp11/update.h @@ -56,31 +56,12 @@ namespace sqlpp return static_cast(*this); } - static constexpr size_t _get_static_no_of_parameters() - { -#warning need to fix this - return 0; - //return _parameter_list_t::size::value; - } - - size_t _get_no_of_parameters() const - { -#warning need to fix this - return 0; - //return _parameter_list_t::size::value; - } - - void _check_consistency() const - { - // FIXME: Read up on what is allowed/prohibited in INSERT - } - template auto _run(Db& db) const -> decltype(db.update(_get_statement())) { - _check_consistency(); + _statement_t::_check_consistency(); - static_assert(_get_static_no_of_parameters() == 0, "cannot run update directly with parameters, use prepare instead"); + static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run update directly with parameters, use prepare instead"); return db.update(*this); } @@ -89,9 +70,9 @@ namespace sqlpp auto _prepare(Db& db) const -> prepared_update_t { - _check_consistency(); + _statement_t::_check_consistency(); - return {{}, db.prepare_update(*this)}; + return {{}, db.prepare_update(*this)}; } */ }; diff --git a/include/sqlpp11/vendor/into.h b/include/sqlpp11/vendor/into.h index f88249c1..74551017 100644 --- a/include/sqlpp11/vendor/into.h +++ b/include/sqlpp11/vendor/into.h @@ -107,44 +107,25 @@ namespace sqlpp return static_cast(*this); } - static constexpr size_t _get_static_no_of_parameters() - { -#warning need to fix this - return 0; - //return _parameter_list_t::size::value; - } + template + auto _run(Db& db) const -> decltype(db.insert(_get_statement())) + { + _statement_t::_check_consistency(); - size_t _get_no_of_parameters() const - { -#warning need to fix this - return 0; - //return _parameter_list_t::size::value; - } + static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run insert directly with parameters, use prepare instead"); + return db.insert(*this); + } - void _check_consistency() const - { - // FIXME: Read up on what is allowed/prohibited in INSERT - } + /* + template + auto _prepare(Db& db) const + -> prepared_insert_t + { + _statement_t::_check_consistency(); - template - auto _run(Db& db) const -> decltype(db.insert(_get_statement())) - { - _check_consistency(); - - static_assert(_get_static_no_of_parameters() == 0, "cannot run insert directly with parameters, use prepare instead"); - return db.insert(*this); - } - - /* - template - auto _prepare(Db& db) const - -> prepared_insert_t - { - _check_consistency(); - - return {{}, db.prepare_insert(*this)}; - } - */ + return {{}, db.prepare_insert(*this)}; + } + */ }; }; diff --git a/include/sqlpp11/vendor/select_column_list.h b/include/sqlpp11/vendor/select_column_list.h index 46fed623..56b512b5 100644 --- a/include/sqlpp11/vendor/select_column_list.h +++ b/include/sqlpp11/vendor/select_column_list.h @@ -281,18 +281,6 @@ namespace sqlpp return _get_statement().selected_columns._data._dynamic_columns._dynamic_expression_names; } - static constexpr size_t _get_static_no_of_parameters() - { -#warning need to fix this - return 0; - } - - size_t _get_no_of_parameters() const - { -#warning need to fix this - return 0; - } - size_t get_no_of_result_columns() const { return sizeof...(Columns) + get_dynamic_names().size(); @@ -303,8 +291,8 @@ namespace sqlpp auto _run(Db& db) const -> result_t> { - Policies::_check_consistency(); - static_assert(_get_static_no_of_parameters() == 0, "cannot run select directly with parameters, use prepare instead"); + _statement_t::_check_consistency(); + static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run select directly with parameters, use prepare instead"); return {db.select(_get_statement()), get_dynamic_names()}; } @@ -315,7 +303,7 @@ namespace sqlpp auto _prepare(Db& db) const -> prepared_select_t { - Policies::_check_consistency(); + _statement_t::_check_consistency(); return {{}, get_dynamic_names(), db.prepare_select(*this)}; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9ea24a1f..9de5e4e2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,9 +8,9 @@ endmacro () #build_and_run(InterpretTest) build_and_run(InsertTest) -build_and_run(RemoveTest) -build_and_run(UpdateTest) -build_and_run(SelectTest) +#build_and_run(RemoveTest) +#build_and_run(UpdateTest) +#build_and_run(SelectTest) #build_and_run(SelectTypeTest) #build_and_run(FunctionTest) #build_and_run(PreparedTest) From 060d59125cb50a2b9f0b711a4a465a035143a6f4 Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 13 Jun 2014 18:51:51 +0200 Subject: [PATCH 32/65] Moved files from sqlpp11/vendor to sqlpp11 --- include/sqlpp11/alias.h | 2 +- include/sqlpp11/{vendor => }/assignment.h | 4 +-- include/sqlpp11/basic_expression_operators.h | 8 +++--- .../sqlpp11/{vendor => }/char_result_row.h | 0 include/sqlpp11/column.h | 8 +++--- include/sqlpp11/{vendor => }/concat.h | 2 +- include/sqlpp11/detail/type_set.h | 2 +- include/sqlpp11/{vendor => }/expression.h | 8 +++--- include/sqlpp11/{vendor => }/expression_fwd.h | 0 include/sqlpp11/{vendor => }/extra_tables.h | 2 +- include/sqlpp11/{vendor => }/field.h | 0 include/sqlpp11/{vendor => }/from.h | 6 ++--- include/sqlpp11/functions.h | 6 ++--- include/sqlpp11/{vendor => }/group_by.h | 8 +++--- include/sqlpp11/{vendor => }/having.h | 8 +++--- include/sqlpp11/{vendor => }/in.h | 2 +- include/sqlpp11/{vendor => }/in_fwd.h | 0 include/sqlpp11/insert.h | 6 ++--- include/sqlpp11/{vendor => }/insert_value.h | 2 +- .../sqlpp11/{vendor => }/insert_value_list.h | 10 +++---- include/sqlpp11/integral.h | 2 +- include/sqlpp11/interpret.h | 2 +- .../sqlpp11/{vendor => }/interpret_tuple.h | 0 include/sqlpp11/{vendor => }/interpretable.h | 0 .../sqlpp11/{vendor => }/interpretable_list.h | 2 +- include/sqlpp11/{vendor => }/interpreter.h | 6 ++--- include/sqlpp11/{vendor => }/into.h | 6 ++--- include/sqlpp11/{vendor => }/is_null.h | 0 include/sqlpp11/{vendor => }/is_null_fwd.h | 0 include/sqlpp11/join.h | 2 +- include/sqlpp11/{vendor => }/like.h | 0 include/sqlpp11/{vendor => }/limit.h | 2 +- .../{vendor => }/named_interpretable.h | 0 include/sqlpp11/{vendor => }/noop.h | 2 +- include/sqlpp11/{vendor => }/noop_fwd.h | 0 include/sqlpp11/{vendor => }/offset.h | 2 +- include/sqlpp11/on.h | 4 +-- include/sqlpp11/{vendor => }/order_by.h | 6 ++--- include/sqlpp11/parameter_list.h | 2 +- include/sqlpp11/{vendor => }/policy_update.h | 6 ++--- include/sqlpp11/remove.h | 10 +++---- include/sqlpp11/result_row.h | 4 +-- include/sqlpp11/select.h | 26 +++++++++---------- .../sqlpp11/{vendor => }/select_column_list.h | 12 ++++----- .../sqlpp11/{vendor => }/select_flag_list.h | 8 +++--- include/sqlpp11/select_flags.h | 2 +- .../{vendor => }/select_pseudo_table.h | 0 include/sqlpp11/serialize.h | 2 +- include/sqlpp11/{vendor => }/serializer.h | 6 ++--- include/sqlpp11/{vendor => }/simple_column.h | 2 +- include/sqlpp11/{vendor => }/single_table.h | 6 ++--- include/sqlpp11/statement.h | 6 ++--- include/sqlpp11/text.h | 4 +-- include/sqlpp11/tvin.h | 4 +-- include/sqlpp11/update.h | 8 +++--- include/sqlpp11/{vendor => }/update_list.h | 4 +-- include/sqlpp11/{vendor => }/using.h | 6 ++--- include/sqlpp11/{vendor => }/value_type.h | 2 +- include/sqlpp11/{vendor => }/where.h | 6 ++--- include/sqlpp11/{vendor => }/wrap_operand.h | 2 +- include/sqlpp11/{vendor => }/wrong.h | 4 +-- 61 files changed, 126 insertions(+), 126 deletions(-) rename include/sqlpp11/{vendor => }/assignment.h (98%) rename include/sqlpp11/{vendor => }/char_result_row.h (100%) rename include/sqlpp11/{vendor => }/concat.h (98%) rename include/sqlpp11/{vendor => }/expression.h (97%) rename include/sqlpp11/{vendor => }/expression_fwd.h (100%) rename include/sqlpp11/{vendor => }/extra_tables.h (99%) rename include/sqlpp11/{vendor => }/field.h (100%) rename include/sqlpp11/{vendor => }/from.h (98%) rename include/sqlpp11/{vendor => }/group_by.h (97%) rename include/sqlpp11/{vendor => }/having.h (97%) rename include/sqlpp11/{vendor => }/in.h (98%) rename include/sqlpp11/{vendor => }/in_fwd.h (100%) rename include/sqlpp11/{vendor => }/insert_value.h (99%) rename include/sqlpp11/{vendor => }/insert_value_list.h (98%) rename include/sqlpp11/{vendor => }/interpret_tuple.h (100%) rename include/sqlpp11/{vendor => }/interpretable.h (100%) rename include/sqlpp11/{vendor => }/interpretable_list.h (98%) rename include/sqlpp11/{vendor => }/interpreter.h (94%) rename include/sqlpp11/{vendor => }/into.h (98%) rename include/sqlpp11/{vendor => }/is_null.h (100%) rename include/sqlpp11/{vendor => }/is_null_fwd.h (100%) rename include/sqlpp11/{vendor => }/like.h (100%) rename include/sqlpp11/{vendor => }/limit.h (99%) rename include/sqlpp11/{vendor => }/named_interpretable.h (100%) rename include/sqlpp11/{vendor => }/noop.h (98%) rename include/sqlpp11/{vendor => }/noop_fwd.h (100%) rename include/sqlpp11/{vendor => }/offset.h (99%) rename include/sqlpp11/{vendor => }/order_by.h (98%) rename include/sqlpp11/{vendor => }/policy_update.h (95%) rename include/sqlpp11/{vendor => }/select_column_list.h (98%) rename include/sqlpp11/{vendor => }/select_flag_list.h (97%) rename include/sqlpp11/{vendor => }/select_pseudo_table.h (100%) rename include/sqlpp11/{vendor => }/serializer.h (94%) rename include/sqlpp11/{vendor => }/simple_column.h (98%) rename include/sqlpp11/{vendor => }/single_table.h (98%) rename include/sqlpp11/{vendor => }/update_list.h (98%) rename include/sqlpp11/{vendor => }/using.h (98%) rename include/sqlpp11/{vendor => }/value_type.h (97%) rename include/sqlpp11/{vendor => }/where.h (98%) rename include/sqlpp11/{vendor => }/wrap_operand.h (99%) rename include/sqlpp11/{vendor => }/wrong.h (96%) diff --git a/include/sqlpp11/alias.h b/include/sqlpp11/alias.h index c280c893..9f9df56e 100644 --- a/include/sqlpp11/alias.h +++ b/include/sqlpp11/alias.h @@ -28,7 +28,7 @@ #define SQLPP_ALIAS_H #include -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/vendor/assignment.h b/include/sqlpp11/assignment.h similarity index 98% rename from include/sqlpp11/vendor/assignment.h rename to include/sqlpp11/assignment.h index e74a6da5..3689d5f1 100644 --- a/include/sqlpp11/vendor/assignment.h +++ b/include/sqlpp11/assignment.h @@ -31,8 +31,8 @@ #include #include #include -#include -#include +#include +#include namespace sqlpp { diff --git a/include/sqlpp11/basic_expression_operators.h b/include/sqlpp11/basic_expression_operators.h index d1f06749..6140d9f3 100644 --- a/include/sqlpp11/basic_expression_operators.h +++ b/include/sqlpp11/basic_expression_operators.h @@ -29,10 +29,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include namespace sqlpp diff --git a/include/sqlpp11/vendor/char_result_row.h b/include/sqlpp11/char_result_row.h similarity index 100% rename from include/sqlpp11/vendor/char_result_row.h rename to include/sqlpp11/char_result_row.h diff --git a/include/sqlpp11/column.h b/include/sqlpp11/column.h index 47f764f1..37f051d2 100644 --- a/include/sqlpp11/column.h +++ b/include/sqlpp11/column.h @@ -33,10 +33,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include namespace sqlpp diff --git a/include/sqlpp11/vendor/concat.h b/include/sqlpp11/concat.h similarity index 98% rename from include/sqlpp11/vendor/concat.h rename to include/sqlpp11/concat.h index 7a93c6ad..c902d490 100644 --- a/include/sqlpp11/vendor/concat.h +++ b/include/sqlpp11/concat.h @@ -28,7 +28,7 @@ #define SQLPP_CONCAT_H #include -#include +#include #include namespace sqlpp diff --git a/include/sqlpp11/detail/type_set.h b/include/sqlpp11/detail/type_set.h index ecc51a23..3aa7eade 100644 --- a/include/sqlpp11/detail/type_set.h +++ b/include/sqlpp11/detail/type_set.h @@ -29,7 +29,7 @@ #include #include -#include +#include #include namespace sqlpp diff --git a/include/sqlpp11/vendor/expression.h b/include/sqlpp11/expression.h similarity index 97% rename from include/sqlpp11/vendor/expression.h rename to include/sqlpp11/expression.h index e91b2d68..c831d157 100644 --- a/include/sqlpp11/vendor/expression.h +++ b/include/sqlpp11/expression.h @@ -30,10 +30,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include namespace sqlpp { diff --git a/include/sqlpp11/vendor/expression_fwd.h b/include/sqlpp11/expression_fwd.h similarity index 100% rename from include/sqlpp11/vendor/expression_fwd.h rename to include/sqlpp11/expression_fwd.h diff --git a/include/sqlpp11/vendor/extra_tables.h b/include/sqlpp11/extra_tables.h similarity index 99% rename from include/sqlpp11/vendor/extra_tables.h rename to include/sqlpp11/extra_tables.h index 3feaac4c..df7f6d8a 100644 --- a/include/sqlpp11/vendor/extra_tables.h +++ b/include/sqlpp11/extra_tables.h @@ -29,7 +29,7 @@ #include #include -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/vendor/field.h b/include/sqlpp11/field.h similarity index 100% rename from include/sqlpp11/vendor/field.h rename to include/sqlpp11/field.h diff --git a/include/sqlpp11/vendor/from.h b/include/sqlpp11/from.h similarity index 98% rename from include/sqlpp11/vendor/from.h rename to include/sqlpp11/from.h index 308dfed3..6cfaaef5 100644 --- a/include/sqlpp11/vendor/from.h +++ b/include/sqlpp11/from.h @@ -28,10 +28,10 @@ #define SQLPP_FROM_H #include -#include -#include +#include +#include #include -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/functions.h b/include/sqlpp11/functions.h index 2d8ce0f6..516ad247 100644 --- a/include/sqlpp11/functions.h +++ b/include/sqlpp11/functions.h @@ -30,9 +30,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include #include diff --git a/include/sqlpp11/vendor/group_by.h b/include/sqlpp11/group_by.h similarity index 97% rename from include/sqlpp11/vendor/group_by.h rename to include/sqlpp11/group_by.h index a3732a5b..0638b46f 100644 --- a/include/sqlpp11/vendor/group_by.h +++ b/include/sqlpp11/group_by.h @@ -29,10 +29,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include namespace sqlpp diff --git a/include/sqlpp11/vendor/having.h b/include/sqlpp11/having.h similarity index 97% rename from include/sqlpp11/vendor/having.h rename to include/sqlpp11/having.h index 0abdcb72..eb847d4d 100644 --- a/include/sqlpp11/vendor/having.h +++ b/include/sqlpp11/having.h @@ -28,10 +28,10 @@ #define SQLPP_HAVING_H #include -#include -#include -#include -#include +#include +#include +#include +#include #include namespace sqlpp diff --git a/include/sqlpp11/vendor/in.h b/include/sqlpp11/in.h similarity index 98% rename from include/sqlpp11/vendor/in.h rename to include/sqlpp11/in.h index ea4b9470..a3f7b7b3 100644 --- a/include/sqlpp11/vendor/in.h +++ b/include/sqlpp11/in.h @@ -29,7 +29,7 @@ #include #include -#include +#include #include namespace sqlpp diff --git a/include/sqlpp11/vendor/in_fwd.h b/include/sqlpp11/in_fwd.h similarity index 100% rename from include/sqlpp11/vendor/in_fwd.h rename to include/sqlpp11/in_fwd.h diff --git a/include/sqlpp11/insert.h b/include/sqlpp11/insert.h index fa9320fb..771da981 100644 --- a/include/sqlpp11/insert.h +++ b/include/sqlpp11/insert.h @@ -32,9 +32,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include namespace sqlpp { diff --git a/include/sqlpp11/vendor/insert_value.h b/include/sqlpp11/insert_value.h similarity index 99% rename from include/sqlpp11/vendor/insert_value.h rename to include/sqlpp11/insert_value.h index b0f4dfea..f9a21c74 100644 --- a/include/sqlpp11/vendor/insert_value.h +++ b/include/sqlpp11/insert_value.h @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include namespace sqlpp diff --git a/include/sqlpp11/vendor/insert_value_list.h b/include/sqlpp11/insert_value_list.h similarity index 98% rename from include/sqlpp11/vendor/insert_value_list.h rename to include/sqlpp11/insert_value_list.h index f4cb6794..8eb898c5 100644 --- a/include/sqlpp11/vendor/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -29,11 +29,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include namespace sqlpp { diff --git a/include/sqlpp11/integral.h b/include/sqlpp11/integral.h index b5e2ad85..923a79bf 100644 --- a/include/sqlpp11/integral.h +++ b/include/sqlpp11/integral.h @@ -32,7 +32,7 @@ #include #include #include -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/interpret.h b/include/sqlpp11/interpret.h index 42cc1524..06c0b17b 100644 --- a/include/sqlpp11/interpret.h +++ b/include/sqlpp11/interpret.h @@ -27,7 +27,7 @@ #ifndef SQLPP_INTERPRET_H #define SQLPP_INTERPRET_H -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/vendor/interpret_tuple.h b/include/sqlpp11/interpret_tuple.h similarity index 100% rename from include/sqlpp11/vendor/interpret_tuple.h rename to include/sqlpp11/interpret_tuple.h diff --git a/include/sqlpp11/vendor/interpretable.h b/include/sqlpp11/interpretable.h similarity index 100% rename from include/sqlpp11/vendor/interpretable.h rename to include/sqlpp11/interpretable.h diff --git a/include/sqlpp11/vendor/interpretable_list.h b/include/sqlpp11/interpretable_list.h similarity index 98% rename from include/sqlpp11/vendor/interpretable_list.h rename to include/sqlpp11/interpretable_list.h index a6b2d27e..5af36314 100644 --- a/include/sqlpp11/vendor/interpretable_list.h +++ b/include/sqlpp11/interpretable_list.h @@ -28,7 +28,7 @@ #define SQLPP_INTERPRETABLE_LIST_H #include -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/vendor/interpreter.h b/include/sqlpp11/interpreter.h similarity index 94% rename from include/sqlpp11/vendor/interpreter.h rename to include/sqlpp11/interpreter.h index 17dd6075..e191be59 100644 --- a/include/sqlpp11/vendor/interpreter.h +++ b/include/sqlpp11/interpreter.h @@ -24,10 +24,10 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SQLPP_VENDOR_INTERPRETER_H -#define SQLPP_VENDOR_INTERPRETER_H +#ifndef SQLPP_INTERPRETER_H +#define SQLPP_INTERPRETER_H -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/vendor/into.h b/include/sqlpp11/into.h similarity index 98% rename from include/sqlpp11/vendor/into.h rename to include/sqlpp11/into.h index 74551017..16edbbf9 100644 --- a/include/sqlpp11/vendor/into.h +++ b/include/sqlpp11/into.h @@ -24,12 +24,12 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SQLPP_VENDOR_INTO_H -#define SQLPP_VENDOR_INTO_H +#ifndef SQLPP_INTO_H +#define SQLPP_INTO_H #include #include -#include +#include #include namespace sqlpp diff --git a/include/sqlpp11/vendor/is_null.h b/include/sqlpp11/is_null.h similarity index 100% rename from include/sqlpp11/vendor/is_null.h rename to include/sqlpp11/is_null.h diff --git a/include/sqlpp11/vendor/is_null_fwd.h b/include/sqlpp11/is_null_fwd.h similarity index 100% rename from include/sqlpp11/vendor/is_null_fwd.h rename to include/sqlpp11/is_null_fwd.h diff --git a/include/sqlpp11/join.h b/include/sqlpp11/join.h index 926de5c2..51c005c2 100644 --- a/include/sqlpp11/join.h +++ b/include/sqlpp11/join.h @@ -29,7 +29,7 @@ #include #include -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/vendor/like.h b/include/sqlpp11/like.h similarity index 100% rename from include/sqlpp11/vendor/like.h rename to include/sqlpp11/like.h diff --git a/include/sqlpp11/vendor/limit.h b/include/sqlpp11/limit.h similarity index 99% rename from include/sqlpp11/vendor/limit.h rename to include/sqlpp11/limit.h index 588b31ee..0548d9ff 100644 --- a/include/sqlpp11/vendor/limit.h +++ b/include/sqlpp11/limit.h @@ -28,7 +28,7 @@ #define SQLPP_LIMIT_H #include -#include +#include #include namespace sqlpp diff --git a/include/sqlpp11/vendor/named_interpretable.h b/include/sqlpp11/named_interpretable.h similarity index 100% rename from include/sqlpp11/vendor/named_interpretable.h rename to include/sqlpp11/named_interpretable.h diff --git a/include/sqlpp11/vendor/noop.h b/include/sqlpp11/noop.h similarity index 98% rename from include/sqlpp11/vendor/noop.h rename to include/sqlpp11/noop.h index 8ed22a75..25e799d8 100644 --- a/include/sqlpp11/vendor/noop.h +++ b/include/sqlpp11/noop.h @@ -29,7 +29,7 @@ #include #include -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/vendor/noop_fwd.h b/include/sqlpp11/noop_fwd.h similarity index 100% rename from include/sqlpp11/vendor/noop_fwd.h rename to include/sqlpp11/noop_fwd.h diff --git a/include/sqlpp11/vendor/offset.h b/include/sqlpp11/offset.h similarity index 99% rename from include/sqlpp11/vendor/offset.h rename to include/sqlpp11/offset.h index 65113beb..3fc71329 100644 --- a/include/sqlpp11/vendor/offset.h +++ b/include/sqlpp11/offset.h @@ -28,7 +28,7 @@ #define SQLPP_OFFSET_H #include -#include +#include #include namespace sqlpp diff --git a/include/sqlpp11/on.h b/include/sqlpp11/on.h index caa23bc6..0f15b530 100644 --- a/include/sqlpp11/on.h +++ b/include/sqlpp11/on.h @@ -28,8 +28,8 @@ #define SQLPP_ON_H #include -#include -#include +#include +#include #include namespace sqlpp diff --git a/include/sqlpp11/vendor/order_by.h b/include/sqlpp11/order_by.h similarity index 98% rename from include/sqlpp11/vendor/order_by.h rename to include/sqlpp11/order_by.h index 37e84724..b1f41e11 100644 --- a/include/sqlpp11/vendor/order_by.h +++ b/include/sqlpp11/order_by.h @@ -29,9 +29,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include diff --git a/include/sqlpp11/parameter_list.h b/include/sqlpp11/parameter_list.h index 46e27c0c..47ca39b0 100644 --- a/include/sqlpp11/parameter_list.h +++ b/include/sqlpp11/parameter_list.h @@ -29,7 +29,7 @@ #include #include -#include +#include #include namespace sqlpp diff --git a/include/sqlpp11/vendor/policy_update.h b/include/sqlpp11/policy_update.h similarity index 95% rename from include/sqlpp11/vendor/policy_update.h rename to include/sqlpp11/policy_update.h index a65c332b..df1ed8cb 100644 --- a/include/sqlpp11/vendor/policy_update.h +++ b/include/sqlpp11/policy_update.h @@ -24,10 +24,10 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SQLPP_VENDOR_POLICY_UPDATE_H -#define SQLPP_VENDOR_POLICY_UPDATE_H +#ifndef SQLPP_POLICY_UPDATE_H +#define SQLPP_POLICY_UPDATE_H -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/remove.h b/include/sqlpp11/remove.h index 671a310f..07d5923d 100644 --- a/include/sqlpp11/remove.h +++ b/include/sqlpp11/remove.h @@ -31,12 +31,12 @@ #include #include #include -#include +#include #warning: need to use another table provider, since delete can be used with several tables -#include -#include -#include -#include +#include +#include +#include +#include namespace sqlpp { diff --git a/include/sqlpp11/result_row.h b/include/sqlpp11/result_row.h index d09bf79a..9415c2a9 100644 --- a/include/sqlpp11/result_row.h +++ b/include/sqlpp11/result_row.h @@ -28,8 +28,8 @@ #define SQLPP_RESULT_ROW_H #include -#include -#include +#include +#include #include #include diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index bda042f9..850a5b11 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -29,19 +29,19 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace sqlpp diff --git a/include/sqlpp11/vendor/select_column_list.h b/include/sqlpp11/select_column_list.h similarity index 98% rename from include/sqlpp11/vendor/select_column_list.h rename to include/sqlpp11/select_column_list.h index 56b512b5..44ef1325 100644 --- a/include/sqlpp11/vendor/select_column_list.h +++ b/include/sqlpp11/select_column_list.h @@ -31,12 +31,12 @@ #include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include diff --git a/include/sqlpp11/vendor/select_flag_list.h b/include/sqlpp11/select_flag_list.h similarity index 97% rename from include/sqlpp11/vendor/select_flag_list.h rename to include/sqlpp11/select_flag_list.h index c458ad6e..c2430420 100644 --- a/include/sqlpp11/vendor/select_flag_list.h +++ b/include/sqlpp11/select_flag_list.h @@ -24,15 +24,15 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SQLPP_VENDOR_SELECT_FLAG_LIST_H -#define SQLPP_VENDOR_SELECT_FLAG_LIST_H +#ifndef SQLPP_SELECT_FLAG_LIST_H +#define SQLPP_SELECT_FLAG_LIST_H #include #include #include #include -#include -#include +#include +#include namespace sqlpp { diff --git a/include/sqlpp11/select_flags.h b/include/sqlpp11/select_flags.h index 3462f224..278e65ec 100644 --- a/include/sqlpp11/select_flags.h +++ b/include/sqlpp11/select_flags.h @@ -29,7 +29,7 @@ #include #include -#include +#include #include namespace sqlpp diff --git a/include/sqlpp11/vendor/select_pseudo_table.h b/include/sqlpp11/select_pseudo_table.h similarity index 100% rename from include/sqlpp11/vendor/select_pseudo_table.h rename to include/sqlpp11/select_pseudo_table.h diff --git a/include/sqlpp11/serialize.h b/include/sqlpp11/serialize.h index 296ae043..5dce87d2 100644 --- a/include/sqlpp11/serialize.h +++ b/include/sqlpp11/serialize.h @@ -27,7 +27,7 @@ #ifndef SQLPP_SERIALIZE_H #define SQLPP_SERIALIZE_H -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/vendor/serializer.h b/include/sqlpp11/serializer.h similarity index 94% rename from include/sqlpp11/vendor/serializer.h rename to include/sqlpp11/serializer.h index 1a5031f9..bda5ff8e 100644 --- a/include/sqlpp11/vendor/serializer.h +++ b/include/sqlpp11/serializer.h @@ -24,10 +24,10 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SQLPP_VENDOR_SERIALIZER_H -#define SQLPP_VENDOR_SERIALIZER_H +#ifndef SQLPP_SERIALIZER_H +#define SQLPP_SERIALIZER_H -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/vendor/simple_column.h b/include/sqlpp11/simple_column.h similarity index 98% rename from include/sqlpp11/vendor/simple_column.h rename to include/sqlpp11/simple_column.h index 56d664bc..ea22d66b 100644 --- a/include/sqlpp11/vendor/simple_column.h +++ b/include/sqlpp11/simple_column.h @@ -27,7 +27,7 @@ #ifndef SQLPP_SIMPLE_COLUMN_H #define SQLPP_SIMPLE_COLUMN_H -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/vendor/single_table.h b/include/sqlpp11/single_table.h similarity index 98% rename from include/sqlpp11/vendor/single_table.h rename to include/sqlpp11/single_table.h index 9826b35f..58745839 100644 --- a/include/sqlpp11/vendor/single_table.h +++ b/include/sqlpp11/single_table.h @@ -24,12 +24,12 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SQLPP_VENDOR_SINGLE_TABLE_H -#define SQLPP_VENDOR_SINGLE_TABLE_H +#ifndef SQLPP_SINGLE_TABLE_H +#define SQLPP_SINGLE_TABLE_H #include #include -#include +#include #include namespace sqlpp diff --git a/include/sqlpp11/statement.h b/include/sqlpp11/statement.h index 2e7f4026..895babdc 100644 --- a/include/sqlpp11/statement.h +++ b/include/sqlpp11/statement.h @@ -31,9 +31,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include diff --git a/include/sqlpp11/text.h b/include/sqlpp11/text.h index dbb32118..c3a52913 100644 --- a/include/sqlpp11/text.h +++ b/include/sqlpp11/text.h @@ -31,8 +31,8 @@ #include #include #include -#include -#include +#include +#include namespace sqlpp { diff --git a/include/sqlpp11/tvin.h b/include/sqlpp11/tvin.h index 255f9d3e..83a4f360 100644 --- a/include/sqlpp11/tvin.h +++ b/include/sqlpp11/tvin.h @@ -31,8 +31,8 @@ #include #include -#include -#include +#include +#include namespace sqlpp { diff --git a/include/sqlpp11/update.h b/include/sqlpp11/update.h index 9fd1414d..be992719 100644 --- a/include/sqlpp11/update.h +++ b/include/sqlpp11/update.h @@ -32,10 +32,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include namespace sqlpp { diff --git a/include/sqlpp11/vendor/update_list.h b/include/sqlpp11/update_list.h similarity index 98% rename from include/sqlpp11/vendor/update_list.h rename to include/sqlpp11/update_list.h index 8cd99bea..11c916fd 100644 --- a/include/sqlpp11/vendor/update_list.h +++ b/include/sqlpp11/update_list.h @@ -29,8 +29,8 @@ #include #include -#include -#include +#include +#include namespace sqlpp { diff --git a/include/sqlpp11/vendor/using.h b/include/sqlpp11/using.h similarity index 98% rename from include/sqlpp11/vendor/using.h rename to include/sqlpp11/using.h index 3731c3c0..0841b8b0 100644 --- a/include/sqlpp11/vendor/using.h +++ b/include/sqlpp11/using.h @@ -28,10 +28,10 @@ #define SQLPP_USING_H #include -#include -#include +#include +#include #include -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/vendor/value_type.h b/include/sqlpp11/value_type.h similarity index 97% rename from include/sqlpp11/vendor/value_type.h rename to include/sqlpp11/value_type.h index 2f9b5188..a4bca0e3 100644 --- a/include/sqlpp11/vendor/value_type.h +++ b/include/sqlpp11/value_type.h @@ -28,7 +28,7 @@ #define SQLPP_VALUE_TYPE_H #include -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/vendor/where.h b/include/sqlpp11/where.h similarity index 98% rename from include/sqlpp11/vendor/where.h rename to include/sqlpp11/where.h index 0dcbd9c2..4652cdee 100644 --- a/include/sqlpp11/vendor/where.h +++ b/include/sqlpp11/where.h @@ -29,9 +29,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include namespace sqlpp diff --git a/include/sqlpp11/vendor/wrap_operand.h b/include/sqlpp11/wrap_operand.h similarity index 99% rename from include/sqlpp11/vendor/wrap_operand.h rename to include/sqlpp11/wrap_operand.h index 2a832e07..380c91e5 100644 --- a/include/sqlpp11/vendor/wrap_operand.h +++ b/include/sqlpp11/wrap_operand.h @@ -28,7 +28,7 @@ #define SQLPP_DETAIL_WRAP_OPERAND_H #include -#include +#include #include namespace sqlpp diff --git a/include/sqlpp11/vendor/wrong.h b/include/sqlpp11/wrong.h similarity index 96% rename from include/sqlpp11/vendor/wrong.h rename to include/sqlpp11/wrong.h index 65a4d181..7cc59ac4 100644 --- a/include/sqlpp11/vendor/wrong.h +++ b/include/sqlpp11/wrong.h @@ -24,8 +24,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SQLPP_VENDOR_WRONG_H -#define SQLPP_VENDOR_WRONG_H +#ifndef SQLPP_WRONG_H +#define SQLPP_WRONG_H #include From 09d220541ebd10452aeb88c07f5047d8ae142181 Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 14 Jun 2014 07:43:27 +0200 Subject: [PATCH 33/65] removed namespace vendor --- include/sqlpp11/alias.h | 3 -- include/sqlpp11/all_of.h | 3 -- include/sqlpp11/any.h | 16 +++----- include/sqlpp11/assignment.h | 3 -- include/sqlpp11/avg.h | 18 +++------ include/sqlpp11/basic_expression_operators.h | 40 +++++++++---------- include/sqlpp11/boolean.h | 10 ++--- include/sqlpp11/column.h | 11 ++--- include/sqlpp11/concat.h | 3 -- include/sqlpp11/count.h | 18 +++------ include/sqlpp11/default_value.h | 3 -- .../sqlpp11/detail/column_index_sequence.h | 2 +- include/sqlpp11/detail/copy_tuple_args.h | 2 +- include/sqlpp11/detail/type_set.h | 12 +++--- include/sqlpp11/exists.h | 14 ++----- include/sqlpp11/expression.h | 3 -- include/sqlpp11/expression_fwd.h | 3 -- include/sqlpp11/extra_tables.h | 3 -- include/sqlpp11/field.h | 3 -- include/sqlpp11/floating_point.h | 36 ++++++++--------- include/sqlpp11/from.h | 5 +-- include/sqlpp11/functions.h | 14 ++----- include/sqlpp11/group_by.h | 5 +-- include/sqlpp11/having.h | 5 +-- include/sqlpp11/in.h | 7 +--- include/sqlpp11/in_fwd.h | 3 -- include/sqlpp11/insert.h | 9 ++--- include/sqlpp11/insert_value.h | 3 -- include/sqlpp11/insert_value_list.h | 17 ++++---- include/sqlpp11/integral.h | 40 +++++++++---------- include/sqlpp11/interpret.h | 4 +- include/sqlpp11/interpretable.h | 3 -- include/sqlpp11/interpretable_list.h | 3 -- include/sqlpp11/interpreter.h | 3 -- include/sqlpp11/into.h | 3 -- include/sqlpp11/is_null.h | 7 +--- include/sqlpp11/is_null_fwd.h | 3 -- include/sqlpp11/join.h | 21 +++++----- include/sqlpp11/like.h | 3 -- include/sqlpp11/limit.h | 3 -- include/sqlpp11/max.h | 14 ++----- include/sqlpp11/min.h | 14 ++----- include/sqlpp11/multi_column.h | 3 -- include/sqlpp11/named_interpretable.h | 3 -- include/sqlpp11/noop.h | 3 -- include/sqlpp11/noop_fwd.h | 3 -- include/sqlpp11/null.h | 3 -- include/sqlpp11/offset.h | 3 -- include/sqlpp11/on.h | 5 +-- include/sqlpp11/order_by.h | 5 +-- include/sqlpp11/parameter.h | 5 +-- include/sqlpp11/parameter_list.h | 2 +- include/sqlpp11/policy_update.h | 3 -- include/sqlpp11/remove.h | 13 +++--- include/sqlpp11/result_row.h | 2 +- include/sqlpp11/select.h | 25 +++++------- include/sqlpp11/select_column_list.h | 10 +---- include/sqlpp11/select_flag_list.h | 5 +-- include/sqlpp11/select_flags.h | 9 ----- include/sqlpp11/select_pseudo_table.h | 3 -- include/sqlpp11/serialize.h | 11 ++--- include/sqlpp11/serializer.h | 3 -- include/sqlpp11/simple_column.h | 3 -- include/sqlpp11/single_table.h | 3 -- include/sqlpp11/some.h | 16 +++----- include/sqlpp11/sort_order.h | 3 -- include/sqlpp11/statement.h | 7 +--- include/sqlpp11/sum.h | 18 +++------ include/sqlpp11/table.h | 3 -- include/sqlpp11/table_alias.h | 3 -- include/sqlpp11/text.h | 12 +++--- include/sqlpp11/tvin.h | 14 ++----- include/sqlpp11/update.h | 11 ++--- include/sqlpp11/update_list.h | 7 +--- include/sqlpp11/using.h | 5 +-- include/sqlpp11/value_type.h | 3 -- include/sqlpp11/verbatim_table.h | 3 -- include/sqlpp11/where.h | 5 +-- include/sqlpp11/wrap_operand.h | 3 -- include/sqlpp11/wrong.h | 3 -- 80 files changed, 195 insertions(+), 441 deletions(-) diff --git a/include/sqlpp11/alias.h b/include/sqlpp11/alias.h index 9f9df56e..2cd0da5d 100644 --- a/include/sqlpp11/alias.h +++ b/include/sqlpp11/alias.h @@ -46,8 +46,6 @@ namespace sqlpp Expression _expression; }; - namespace vendor - { template struct serializer_t> { @@ -63,7 +61,6 @@ namespace sqlpp } }; - } } #endif diff --git a/include/sqlpp11/all_of.h b/include/sqlpp11/all_of.h index 270dea20..fb3c6a14 100644 --- a/include/sqlpp11/all_of.h +++ b/include/sqlpp11/all_of.h @@ -51,8 +51,6 @@ namespace sqlpp return {}; } - namespace vendor - { template struct serializer_t> { @@ -63,7 +61,6 @@ namespace sqlpp static_assert(wrong_t::value, "all_of(table) does not seem to be used in select"); } }; - } } diff --git a/include/sqlpp11/any.h b/include/sqlpp11/any.h index b4897b6a..a8ffed96 100644 --- a/include/sqlpp11/any.h +++ b/include/sqlpp11/any.h @@ -32,8 +32,6 @@ namespace sqlpp { - namespace vendor - { template struct any_t { @@ -64,14 +62,11 @@ namespace sqlpp Select _select; }; - } - namespace vendor - { template - struct serializer_t> + struct serializer_t> { - using T = vendor::any_t; static Context& _(const T& t, Context& context) { @@ -83,15 +78,14 @@ namespace sqlpp }; template - auto any(T t) -> typename vendor::any_t> + auto any(T t) -> typename any_t> { - static_assert(is_select_t>::value, "any() requires a select expression as argument"); - static_assert(is_expression_t>::value, "any() requires a single column select expression as argument"); + static_assert(is_select_t>::value, "any() requires a select expression as argument"); + static_assert(is_expression_t>::value, "any() requires a single column select expression as argument"); // FIXME: can we accept non-values like NULL here? return { t }; } - } } #endif diff --git a/include/sqlpp11/assignment.h b/include/sqlpp11/assignment.h index 3689d5f1..15ed6dcb 100644 --- a/include/sqlpp11/assignment.h +++ b/include/sqlpp11/assignment.h @@ -36,8 +36,6 @@ namespace sqlpp { - namespace vendor - { template struct is_trivial_t { @@ -158,7 +156,6 @@ namespace sqlpp return context; } }; - } } #endif diff --git a/include/sqlpp11/avg.h b/include/sqlpp11/avg.h index 50ca491c..0e2cb3df 100644 --- a/include/sqlpp11/avg.h +++ b/include/sqlpp11/avg.h @@ -31,8 +31,6 @@ namespace sqlpp { - namespace vendor - { template struct avg_t: public floating_point::template expression_operators>, public alias_operators> @@ -67,14 +65,11 @@ namespace sqlpp Expr _expr; }; - } - namespace vendor - { template - struct serializer_t> + struct serializer_t> { - using T = vendor::avg_t; + using T = avg_t; static Context& _(const T& t, Context& context) { @@ -89,19 +84,18 @@ namespace sqlpp return context; } }; - } template - auto avg(T t) -> typename vendor::avg_t> + auto avg(T t) -> typename avg_t> { - static_assert(is_numeric_t>::value, "avg() requires a value expression as argument"); + static_assert(is_numeric_t>::value, "avg() requires a value expression as argument"); return { t }; } template - auto avg(const sqlpp::distinct_t&, T t) -> typename vendor::avg_t> + auto avg(const sqlpp::distinct_t&, T t) -> typename avg_t> { - static_assert(is_numeric_t>::value, "avg() requires a value expression as argument"); + static_assert(is_numeric_t>::value, "avg() requires a value expression as argument"); return { t }; } diff --git a/include/sqlpp11/basic_expression_operators.h b/include/sqlpp11/basic_expression_operators.h index 6140d9f3..87b06e5a 100644 --- a/include/sqlpp11/basic_expression_operators.h +++ b/include/sqlpp11/basic_expression_operators.h @@ -52,65 +52,65 @@ namespace sqlpp }; template - vendor::equal_to_t> operator==(T t) const + equal_to_t> operator==(T t) const { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_comparison_operand::value, "invalid rhs operand in comparison"); return { *static_cast(this), rhs{t} }; } template - vendor::not_equal_to_t> operator!=(T t) const + not_equal_to_t> operator!=(T t) const { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_comparison_operand::value, "invalid rhs operand in comparison"); return { *static_cast(this), rhs{t} }; } template - vendor::less_than_t> operator<(T t) const + less_than_t> operator<(T t) const { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_comparison_operand::value, "invalid rhs operand in comparison"); return { *static_cast(this), rhs{t} }; } template - vendor::less_equal_t> operator<=(T t) const + less_equal_t> operator<=(T t) const { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_comparison_operand::value, "invalid rhs operand in comparison"); return { *static_cast(this), rhs{t} }; } template - vendor::greater_than_t> operator>(T t) const + greater_than_t> operator>(T t) const { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_comparison_operand::value, "invalid rhs operand in comparison"); return { *static_cast(this), rhs{t} }; } template - vendor::greater_equal_t> operator>=(T t) const + greater_equal_t> operator>=(T t) const { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_comparison_operand::value, "invalid rhs operand in comparison"); return { *static_cast(this), rhs{t} }; } - vendor::is_null_t is_null() const + is_null_t is_null() const { return { *static_cast(this) }; } - vendor::is_null_t is_not_null() const + is_null_t is_not_null() const { return { *static_cast(this) }; } @@ -127,17 +127,17 @@ namespace sqlpp // Hint: use value_list wrapper for containers... template - vendor::in_t...> in(T... t) const + in_t...> in(T... t) const { - static_assert(detail::all_t<_is_valid_comparison_operand>::value...>::value, "at least one operand of in() is not valid"); - return { *static_cast(this), vendor::wrap_operand_t{t}... }; + static_assert(detail::all_t<_is_valid_comparison_operand>::value...>::value, "at least one operand of in() is not valid"); + return { *static_cast(this), wrap_operand_t{t}... }; } template - vendor::in_t...> not_in(T... t) const + in_t...> not_in(T... t) const { - static_assert(detail::all_t<_is_valid_comparison_operand>::value...>::value, "at least one operand of in() is not valid"); - return { *static_cast(this), vendor::wrap_operand_t{t}... }; + static_assert(detail::all_t<_is_valid_comparison_operand>::value...>::value, "at least one operand of in() is not valid"); + return { *static_cast(this), wrap_operand_t{t}... }; } }; diff --git a/include/sqlpp11/boolean.h b/include/sqlpp11/boolean.h index d5935484..b01d49bb 100644 --- a/include/sqlpp11/boolean.h +++ b/include/sqlpp11/boolean.h @@ -184,24 +184,24 @@ namespace sqlpp struct expression_operators: public basic_expression_operators { template - vendor::logical_and_t> operator and(T t) const + logical_and_t> operator and(T t) const { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs operand"); return { *static_cast(this), rhs{t} }; } template - vendor::logical_or_t> operator or(T t) const + logical_or_t> operator or(T t) const { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs operand"); return { *static_cast(this), rhs{t} }; } - vendor::logical_not_t operator not() const + logical_not_t operator not() const { return { *static_cast(this) }; } diff --git a/include/sqlpp11/column.h b/include/sqlpp11/column.h index 37f051d2..c69af308 100644 --- a/include/sqlpp11/column.h +++ b/include/sqlpp11/column.h @@ -81,30 +81,28 @@ namespace sqlpp } template - auto operator =(T t) const -> vendor::assignment_t> + auto operator =(T t) const -> assignment_t> { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs operand assignment operand"); return { *this, rhs{t} }; } auto operator =(sqlpp::null_t) const - ->vendor::assignment_t + ->assignment_t { static_assert(can_be_null_t::value, "column cannot be null"); return { *this, {} }; } auto operator =(sqlpp::default_value_t) const - ->vendor::assignment_t + ->assignment_t { return { *this, {} }; } }; - namespace vendor - { template struct serializer_t> { @@ -117,7 +115,6 @@ namespace sqlpp } }; - } } #endif diff --git a/include/sqlpp11/concat.h b/include/sqlpp11/concat.h index c902d490..766b4f0a 100644 --- a/include/sqlpp11/concat.h +++ b/include/sqlpp11/concat.h @@ -33,8 +33,6 @@ namespace sqlpp { - namespace vendor - { // FIXME: Remove First, inherit from text_t template struct concat_t: public value_type_of::template expression_operators>, @@ -81,7 +79,6 @@ namespace sqlpp return context; } }; - } } #endif diff --git a/include/sqlpp11/count.h b/include/sqlpp11/count.h index 838189a6..a29e1414 100644 --- a/include/sqlpp11/count.h +++ b/include/sqlpp11/count.h @@ -32,8 +32,6 @@ namespace sqlpp { - namespace vendor - { template struct count_t: public sqlpp::detail::integral::template expression_operators>, public alias_operators> @@ -68,14 +66,11 @@ namespace sqlpp Expr _expr; }; - } - namespace vendor - { template - struct serializer_t> + struct serializer_t> { - using T = vendor::count_t; + using T = count_t; static Context& _(const T& t, Context& context) { @@ -90,19 +85,18 @@ namespace sqlpp return context; } }; - } template - auto count(T t) -> typename vendor::count_t> + auto count(T t) -> typename count_t> { - static_assert(is_expression_t>::value, "count() requires an expression as argument"); + static_assert(is_expression_t>::value, "count() requires an expression as argument"); return { t }; } template - auto count(const sqlpp::distinct_t&, T t) -> typename vendor::count_t> + auto count(const sqlpp::distinct_t&, T t) -> typename count_t> { - static_assert(is_expression_t>::value, "count() requires an expression as argument"); + static_assert(is_expression_t>::value, "count() requires an expression as argument"); return { t }; } diff --git a/include/sqlpp11/default_value.h b/include/sqlpp11/default_value.h index 87c4b523..d31aef95 100644 --- a/include/sqlpp11/default_value.h +++ b/include/sqlpp11/default_value.h @@ -39,8 +39,6 @@ namespace sqlpp static constexpr bool _is_trivial() { return false; } }; - namespace vendor - { template struct serializer_t { @@ -52,7 +50,6 @@ namespace sqlpp return context; } }; - } constexpr default_value_t default_value = {}; diff --git a/include/sqlpp11/detail/column_index_sequence.h b/include/sqlpp11/detail/column_index_sequence.h index 277e85e2..be5a2c49 100644 --- a/include/sqlpp11/detail/column_index_sequence.h +++ b/include/sqlpp11/detail/column_index_sequence.h @@ -49,7 +49,7 @@ namespace sqlpp }; template - struct make_column_index_sequence_impl, vendor::multi_field_t, Rest...> + struct make_column_index_sequence_impl, multi_field_t, Rest...> { using type = typename make_column_index_sequence_impl, Rest...>::type; }; diff --git a/include/sqlpp11/detail/copy_tuple_args.h b/include/sqlpp11/detail/copy_tuple_args.h index 0891e6ac..3496a2be 100644 --- a/include/sqlpp11/detail/copy_tuple_args.h +++ b/include/sqlpp11/detail/copy_tuple_args.h @@ -57,7 +57,7 @@ namespace sqlpp template class Target, typename First, typename T> struct copy_tuple_args_impl { - static_assert(vendor::wrong_t::value, "copy_tuple_args must be called with a tuple"); + static_assert(wrong_t::value, "copy_tuple_args must be called with a tuple"); }; template class Target, typename First, typename... Args> diff --git a/include/sqlpp11/detail/type_set.h b/include/sqlpp11/detail/type_set.h index 3aa7eade..9f5f855f 100644 --- a/include/sqlpp11/detail/type_set.h +++ b/include/sqlpp11/detail/type_set.h @@ -73,7 +73,7 @@ namespace sqlpp template struct is_element_of { - static_assert(::sqlpp::vendor::wrong_t::value, "SET has to be a type set"); + static_assert(::sqlpp::wrong_t::value, "SET has to be a type set"); }; template @@ -85,7 +85,7 @@ namespace sqlpp template struct joined_set { - static_assert(::sqlpp::vendor::wrong_t::value, "L and R have to be type sets"); + static_assert(::sqlpp::wrong_t::value, "L and R have to be type sets"); }; template @@ -100,7 +100,7 @@ namespace sqlpp template struct is_superset_of { - static_assert(::sqlpp::vendor::wrong_t::value, "L and R have to be type sets"); + static_assert(::sqlpp::wrong_t::value, "L and R have to be type sets"); }; template @@ -118,7 +118,7 @@ namespace sqlpp template struct is_disjunct_from { - static_assert(::sqlpp::vendor::wrong_t::value, "invalid argument for is_disjunct_from"); + static_assert(::sqlpp::wrong_t::value, "invalid argument for is_disjunct_from"); }; template @@ -174,7 +174,7 @@ namespace sqlpp template struct make_joined_set { - static_assert(::sqlpp::vendor::wrong_t::value, "invalid argument for joined set"); + static_assert(::sqlpp::wrong_t::value, "invalid argument for joined set"); }; template<> @@ -197,7 +197,7 @@ namespace sqlpp template struct make_difference_set { - static_assert(::sqlpp::vendor::wrong_t::value, "invalid argument for difference set"); + static_assert(::sqlpp::wrong_t::value, "invalid argument for difference set"); }; template diff --git a/include/sqlpp11/exists.h b/include/sqlpp11/exists.h index 8d767754..811c502d 100644 --- a/include/sqlpp11/exists.h +++ b/include/sqlpp11/exists.h @@ -31,8 +31,6 @@ namespace sqlpp { - namespace vendor - { template struct exists_t: public boolean::template expression_operators>, public alias_operators> @@ -66,14 +64,11 @@ namespace sqlpp Select _select; }; - } - namespace vendor - { template - struct serializer_t> + struct serializer_t> { - using T = vendor::exists_t; static Context& _(const T& t, Context& context) { @@ -83,13 +78,12 @@ namespace sqlpp return context; } }; - } template - auto exists(T t) -> typename vendor::exists_t> + auto exists(T t) -> typename exists_t> { - static_assert(is_select_t>::value, "exists() requires a select expression as argument"); + static_assert(is_select_t>::value, "exists() requires a select expression as argument"); return { t }; } diff --git a/include/sqlpp11/expression.h b/include/sqlpp11/expression.h index c831d157..ba192890 100644 --- a/include/sqlpp11/expression.h +++ b/include/sqlpp11/expression.h @@ -37,8 +37,6 @@ namespace sqlpp { - namespace vendor - { template struct binary_expression_t: public ::sqlpp::detail::boolean::template expression_operators>, public alias_operators> @@ -236,7 +234,6 @@ namespace sqlpp return context; } }; - } } #endif diff --git a/include/sqlpp11/expression_fwd.h b/include/sqlpp11/expression_fwd.h index 796596e5..ed542c7d 100644 --- a/include/sqlpp11/expression_fwd.h +++ b/include/sqlpp11/expression_fwd.h @@ -36,8 +36,6 @@ namespace sqlpp struct floating_point; } - namespace vendor - { namespace op { struct less @@ -193,7 +191,6 @@ namespace sqlpp template using unary_minus_t = unary_expression_t, Rhs>; - } } #endif diff --git a/include/sqlpp11/extra_tables.h b/include/sqlpp11/extra_tables.h index df7f6d8a..f660e92a 100644 --- a/include/sqlpp11/extra_tables.h +++ b/include/sqlpp11/extra_tables.h @@ -33,8 +33,6 @@ namespace sqlpp { - namespace vendor - { template struct extra_tables_data_t { @@ -164,7 +162,6 @@ namespace sqlpp } }; - } } #endif diff --git a/include/sqlpp11/field.h b/include/sqlpp11/field.h index b843dc8d..49a6abe6 100644 --- a/include/sqlpp11/field.h +++ b/include/sqlpp11/field.h @@ -31,8 +31,6 @@ namespace sqlpp { - namespace vendor - { template struct field_t { @@ -67,7 +65,6 @@ namespace sqlpp template using make_field_t = typename detail::make_field_t_impl::type; - } } diff --git a/include/sqlpp11/floating_point.h b/include/sqlpp11/floating_point.h index 48bd70b9..bbed7aac 100644 --- a/include/sqlpp11/floating_point.h +++ b/include/sqlpp11/floating_point.h @@ -185,45 +185,45 @@ namespace sqlpp struct expression_operators: public basic_expression_operators { template - vendor::plus_t> operator +(T t) const + plus_t> operator +(T t) const { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs operand"); return { *static_cast(this), rhs{t} }; } template - vendor::minus_t> operator -(T t) const + minus_t> operator -(T t) const { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs operand"); return { *static_cast(this), rhs{t} }; } template - vendor::multiplies_t> operator *(T t) const + multiplies_t> operator *(T t) const { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; return { *static_cast(this), rhs{t} }; } template - vendor::divides_t> operator /(T t) const + divides_t> operator /(T t) const { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; return { *static_cast(this), rhs{t} }; } - vendor::unary_plus_t operator +() const + unary_plus_t operator +() const { return { *static_cast(this) }; } - vendor::unary_minus_t operator -() const + unary_minus_t operator -() const { return { *static_cast(this) }; } @@ -233,36 +233,36 @@ namespace sqlpp struct column_operators { template - auto operator +=(T t) const -> vendor::assignment_t>> + auto operator +=(T t) const -> assignment_t>> { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); return { *static_cast(this), { *static_cast(this), rhs{t} } }; } template - auto operator -=(T t) const -> vendor::assignment_t>> + auto operator -=(T t) const -> assignment_t>> { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); return { *static_cast(this), { *static_cast(this), rhs{t} } }; } template - auto operator /=(T t) const -> vendor::assignment_t>> + auto operator /=(T t) const -> assignment_t>> { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); return { *static_cast(this), { *static_cast(this), rhs{t} } }; } template - auto operator *=(T t) const -> vendor::assignment_t>> + auto operator *=(T t) const -> assignment_t>> { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); return { *static_cast(this), { *static_cast(this), rhs{t} } }; diff --git a/include/sqlpp11/from.h b/include/sqlpp11/from.h index 6cfaaef5..efb8cedf 100644 --- a/include/sqlpp11/from.h +++ b/include/sqlpp11/from.h @@ -35,8 +35,6 @@ namespace sqlpp { - namespace vendor - { // FROM DATA template struct from_data_t @@ -52,7 +50,7 @@ namespace sqlpp ~from_data_t() = default; std::tuple _tables; - vendor::interpretable_list_t _dynamic_tables; + interpretable_list_t _dynamic_tables; }; // FROM @@ -206,7 +204,6 @@ namespace sqlpp } }; - } } #endif diff --git a/include/sqlpp11/functions.h b/include/sqlpp11/functions.h index 516ad247..3896c23e 100644 --- a/include/sqlpp11/functions.h +++ b/include/sqlpp11/functions.h @@ -46,11 +46,11 @@ namespace sqlpp { template - auto value(T t) -> vendor::wrap_operand_t + auto value(T t) -> wrap_operand_t { using _provided_tables = detail::type_set<>; using _required_tables = ::sqlpp::detail::type_set<>; - static_assert(is_wrapped_value_t>::value, "value() is to be called with non-sql-type like int, or string"); + static_assert(is_wrapped_value_t>::value, "value() is to be called with non-sql-type like int, or string"); return { t }; } @@ -71,8 +71,6 @@ namespace sqlpp std::string _verbatim; }; - namespace vendor - { template struct serializer_t> { @@ -84,7 +82,6 @@ namespace sqlpp return context; } }; - } template auto verbatim(StringType s) -> verbatim_t @@ -104,7 +101,7 @@ namespace sqlpp template struct value_list_t // to be used in .in() method { - using _traits = make_traits>; + using _traits = make_traits>; using _recursive_traits = make_recursive_traits<>; using _container_t = Container; @@ -122,8 +119,6 @@ namespace sqlpp _container_t _container; }; - namespace vendor - { template struct serializer_t> { @@ -144,12 +139,11 @@ namespace sqlpp return context; } }; - } template auto value_list(Container c) -> value_list_t { - static_assert(is_wrapped_value_t>::value, "value_list() is to be called with a container of non-sql-type like std::vector, or std::list(string)"); + static_assert(is_wrapped_value_t>::value, "value_list() is to be called with a container of non-sql-type like std::vector, or std::list(string)"); return { c }; } diff --git a/include/sqlpp11/group_by.h b/include/sqlpp11/group_by.h index 0638b46f..0b059201 100644 --- a/include/sqlpp11/group_by.h +++ b/include/sqlpp11/group_by.h @@ -37,8 +37,6 @@ namespace sqlpp { - namespace vendor - { // GROUP BY DATA template struct group_by_data_t @@ -54,7 +52,7 @@ namespace sqlpp ~group_by_data_t() = default; std::tuple _expressions; - vendor::interpretable_list_t _dynamic_expressions; + interpretable_list_t _dynamic_expressions; }; // GROUP BY @@ -208,7 +206,6 @@ namespace sqlpp return context; } }; - } } #endif diff --git a/include/sqlpp11/having.h b/include/sqlpp11/having.h index eb847d4d..483b45ae 100644 --- a/include/sqlpp11/having.h +++ b/include/sqlpp11/having.h @@ -36,8 +36,6 @@ namespace sqlpp { - namespace vendor - { // HAVING DATA template struct having_data_t @@ -53,7 +51,7 @@ namespace sqlpp ~having_data_t() = default; std::tuple _expressions; - vendor::interpretable_list_t _dynamic_expressions; + interpretable_list_t _dynamic_expressions; }; // HAVING @@ -206,7 +204,6 @@ namespace sqlpp return context; } }; - } } #endif diff --git a/include/sqlpp11/in.h b/include/sqlpp11/in.h index a3f7b7b3..76b9ed77 100644 --- a/include/sqlpp11/in.h +++ b/include/sqlpp11/in.h @@ -34,8 +34,6 @@ namespace sqlpp { - namespace vendor - { template struct in_t: public boolean::template expression_operators>, public alias_operators> @@ -72,9 +70,9 @@ namespace sqlpp }; template - struct serializer_t> + struct serializer_t> { - using T = vendor::in_t; + using T = in_t; static Context& _(const T& t, Context& context) { @@ -85,7 +83,6 @@ namespace sqlpp return context; } }; - } } diff --git a/include/sqlpp11/in_fwd.h b/include/sqlpp11/in_fwd.h index 809c4cc2..9b2e06a4 100644 --- a/include/sqlpp11/in_fwd.h +++ b/include/sqlpp11/in_fwd.h @@ -29,11 +29,8 @@ namespace sqlpp { - namespace vendor - { template struct in_t; - } } diff --git a/include/sqlpp11/insert.h b/include/sqlpp11/insert.h index 771da981..eeb08f4b 100644 --- a/include/sqlpp11/insert.h +++ b/include/sqlpp11/insert.h @@ -40,11 +40,9 @@ namespace sqlpp { struct insert_name_t {}; - struct insert_t: public vendor::statement_name_t + struct insert_t: public statement_name_t {}; - namespace vendor - { template struct serializer_t { @@ -57,13 +55,12 @@ namespace sqlpp return context; } }; - } template using blank_insert_t = statement_t; + no_into_t, + no_insert_value_list_t>; auto insert() -> blank_insert_t diff --git a/include/sqlpp11/insert_value.h b/include/sqlpp11/insert_value.h index f9a21c74..d9c0f4e1 100644 --- a/include/sqlpp11/insert_value.h +++ b/include/sqlpp11/insert_value.h @@ -36,8 +36,6 @@ namespace sqlpp { - namespace vendor - { namespace detail { template @@ -118,7 +116,6 @@ namespace sqlpp } }; - } } #endif diff --git a/include/sqlpp11/insert_value_list.h b/include/sqlpp11/insert_value_list.h index 8eb898c5..ea3676f3 100644 --- a/include/sqlpp11/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -37,8 +37,6 @@ namespace sqlpp { - namespace vendor - { struct insert_default_values_data_t {}; @@ -98,8 +96,8 @@ namespace sqlpp std::tuple...> _columns; std::tuple _values; std::tuple _assignments; // FIXME: Need to replace _columns and _values by _assignments (connector-container requires assignments) - typename vendor::interpretable_list_t _dynamic_columns; - typename vendor::interpretable_list_t _dynamic_values; + interpretable_list_t _dynamic_columns; + interpretable_list_t _dynamic_values; }; template @@ -218,7 +216,7 @@ namespace sqlpp ~column_list_data_t() = default; #warning need to define just one version of value_tuple_t - using _value_tuple_t = std::tuple...>; + using _value_tuple_t = std::tuple...>; std::tuple...> _columns; std::vector<_value_tuple_t> _insert_values; }; @@ -237,7 +235,7 @@ namespace sqlpp static_assert(::sqlpp::detail::none_t::value...>::value, "at least one column argument has a must_not_insert flag in its definition"); - using _value_tuple_t = std::tuple...>; + using _value_tuple_t = std::tuple...>; static_assert(required_tables_of::size::value == 1, "columns from multiple tables in columns()"); @@ -252,7 +250,7 @@ namespace sqlpp void add(Assignments... assignments) { static_assert(::sqlpp::detail::all_t::value...>::value, "add_values() arguments have to be assignments"); - using _arg_value_tuple = std::tuple...>; + using _arg_value_tuple = std::tuple...>; using _args_correct = std::is_same<_arg_value_tuple, _value_tuple_t>; static_assert(_args_correct::value, "add_values() arguments do not match columns() arguments"); @@ -267,7 +265,7 @@ namespace sqlpp template void _add_impl(const std::true_type&, Assignments... assignments) { - return _data._insert_values.emplace_back(vendor::insert_value_t{assignments}...); + return _data._insert_values.emplace_back(insert_value_t{assignments}...); } template @@ -373,7 +371,7 @@ namespace sqlpp -> _new_statement_t> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_set must not be called in a static statement"); - return { *static_cast(this), vendor::insert_list_data_t<_database_t, Args...>{args...} }; + return { *static_cast(this), insert_list_data_t<_database_t, Args...>{args...} }; } }; }; @@ -447,7 +445,6 @@ namespace sqlpp } }; - } } #endif diff --git a/include/sqlpp11/integral.h b/include/sqlpp11/integral.h index 923a79bf..47fc007c 100644 --- a/include/sqlpp11/integral.h +++ b/include/sqlpp11/integral.h @@ -186,56 +186,56 @@ namespace sqlpp struct expression_operators: public basic_expression_operators { template - vendor::plus_t, vendor::wrap_operand_t> operator +(T t) const + plus_t, wrap_operand_t> operator +(T t) const { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs operand"); return { *static_cast(this), {t} }; } template - vendor::minus_t, vendor::wrap_operand_t> operator -(T t) const + minus_t, wrap_operand_t> operator -(T t) const { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs operand"); return { *static_cast(this), {t} }; } template - vendor::multiplies_t, vendor::wrap_operand_t> operator *(T t) const + multiplies_t, wrap_operand_t> operator *(T t) const { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs operand"); return { *static_cast(this), {t} }; } template - vendor::divides_t> operator /(T t) const + divides_t> operator /(T t) const { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs operand"); return { *static_cast(this), {t} }; } template - vendor::modulus_t> operator %(T t) const + modulus_t> operator %(T t) const { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs operand"); return { *static_cast(this), {t} }; } - vendor::unary_plus_t operator +() const + unary_plus_t operator +() const { return { *static_cast(this) }; } - vendor::unary_minus_t operator -() const + unary_minus_t operator -() const { return { *static_cast(this) }; } @@ -245,36 +245,36 @@ namespace sqlpp struct column_operators { template - auto operator +=(T t) const -> vendor::assignment_t, vendor::wrap_operand_t>> + auto operator +=(T t) const -> assignment_t, wrap_operand_t>> { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); return { *static_cast(this), { *static_cast(this), rhs{t} } }; } template - auto operator -=(T t) const -> vendor::assignment_t, vendor::wrap_operand_t>> + auto operator -=(T t) const -> assignment_t, wrap_operand_t>> { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); return { *static_cast(this), { *static_cast(this), rhs{t} } }; } template - auto operator /=(T t) const -> vendor::assignment_t>> + auto operator /=(T t) const -> assignment_t>> { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); return { *static_cast(this), { *static_cast(this), rhs{t} } }; } template - auto operator *=(T t) const -> vendor::assignment_t, vendor::wrap_operand_t>> + auto operator *=(T t) const -> assignment_t, wrap_operand_t>> { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); return { *static_cast(this), { *static_cast(this), rhs{t} } }; diff --git a/include/sqlpp11/interpret.h b/include/sqlpp11/interpret.h index 06c0b17b..4d1b2c20 100644 --- a/include/sqlpp11/interpret.h +++ b/include/sqlpp11/interpret.h @@ -33,9 +33,9 @@ namespace sqlpp { template auto interpret(const T& t, Context& context) - -> decltype(vendor::interpreter_t::_(t, context)) + -> decltype(interpreter_t::_(t, context)) { - return vendor::interpreter_t::_(t, context); + return interpreter_t::_(t, context); } } diff --git a/include/sqlpp11/interpretable.h b/include/sqlpp11/interpretable.h index a190f04e..faa6a133 100644 --- a/include/sqlpp11/interpretable.h +++ b/include/sqlpp11/interpretable.h @@ -35,8 +35,6 @@ namespace sqlpp { - namespace vendor - { template struct interpretable_t { @@ -125,7 +123,6 @@ namespace sqlpp } }; - } } #endif diff --git a/include/sqlpp11/interpretable_list.h b/include/sqlpp11/interpretable_list.h index 5af36314..8c9367d0 100644 --- a/include/sqlpp11/interpretable_list.h +++ b/include/sqlpp11/interpretable_list.h @@ -32,8 +32,6 @@ namespace sqlpp { - namespace vendor - { template struct interpretable_list_t { @@ -113,7 +111,6 @@ namespace sqlpp return serializable_list_interpreter_t::_(t, separator, context); } - } } #endif diff --git a/include/sqlpp11/interpreter.h b/include/sqlpp11/interpreter.h index e191be59..f58f0940 100644 --- a/include/sqlpp11/interpreter.h +++ b/include/sqlpp11/interpreter.h @@ -31,8 +31,6 @@ namespace sqlpp { - namespace vendor - { template struct interpreter_t { @@ -41,7 +39,6 @@ namespace sqlpp static_assert(wrong_t::value, "missing interpreter specialization"); } }; - } } diff --git a/include/sqlpp11/into.h b/include/sqlpp11/into.h index 16edbbf9..f65857cd 100644 --- a/include/sqlpp11/into.h +++ b/include/sqlpp11/into.h @@ -34,8 +34,6 @@ namespace sqlpp { - namespace vendor - { // A SINGLE TABLE DATA template struct into_data_t @@ -192,7 +190,6 @@ namespace sqlpp } }; - } } #endif diff --git a/include/sqlpp11/is_null.h b/include/sqlpp11/is_null.h index ad212cca..5dc584dd 100644 --- a/include/sqlpp11/is_null.h +++ b/include/sqlpp11/is_null.h @@ -33,8 +33,6 @@ namespace sqlpp { - namespace vendor - { template struct is_null_t: public boolean::template expression_operators>, public alias_operators> @@ -73,9 +71,9 @@ namespace sqlpp }; template - struct serializer_t> + struct serializer_t> { - using T = ::sqlpp::vendor::is_null_t; + using T = ::sqlpp::is_null_t; static Context& _(const T& t, Context& context) { @@ -84,7 +82,6 @@ namespace sqlpp return context; } }; - } } diff --git a/include/sqlpp11/is_null_fwd.h b/include/sqlpp11/is_null_fwd.h index 0c8e62f0..0a866b3d 100644 --- a/include/sqlpp11/is_null_fwd.h +++ b/include/sqlpp11/is_null_fwd.h @@ -29,11 +29,8 @@ namespace sqlpp { - namespace vendor - { template struct is_null_t; - } } #endif diff --git a/include/sqlpp11/join.h b/include/sqlpp11/join.h index 51c005c2..811fb0c5 100644 --- a/include/sqlpp11/join.h +++ b/include/sqlpp11/join.h @@ -74,7 +74,7 @@ namespace sqlpp static constexpr const char* _name = " RIGHT OUTER "; }; - template + template struct join_t { using _traits = make_traits; @@ -83,7 +83,7 @@ namespace sqlpp static_assert(is_table_t::value, "lhs argument for join() has to be a table or join"); static_assert(is_table_t::value, "rhs argument for join() has to be a table"); static_assert(not is_join_t::value, "rhs argument for join must not be a join"); - static_assert(vendor::is_noop::value or is_on_t::value, "invalid on expression in join().on()"); + static_assert(is_noop::value or is_on_t::value, "invalid on expression in join().on()"); static_assert(::sqlpp::detail::is_disjunct_from, provided_tables_of>::value, "joined tables must not be identical"); @@ -96,7 +96,7 @@ namespace sqlpp auto on(Expr... expr) -> set_on_t> { - static_assert(vendor::is_noop::value, "cannot call on() twice for a single join()"); + static_assert(is_noop::value, "cannot call on() twice for a single join()"); return { _lhs, _rhs, {std::tuple{expr...}} @@ -106,35 +106,35 @@ namespace sqlpp template join_t join(T t) { - static_assert(not vendor::is_noop::value, "join type requires on()"); + static_assert(not is_noop::value, "join type requires on()"); return { *this, t }; } template join_t inner_join(T t) { - static_assert(not vendor::is_noop::value, "join type requires on()"); + static_assert(not is_noop::value, "join type requires on()"); return { *this, t }; } template join_t outer_join(T t) { - static_assert(not vendor::is_noop::value, "join type requires on()"); + static_assert(not is_noop::value, "join type requires on()"); return { *this, t }; } template join_t left_outer_join(T t) { - static_assert(not vendor::is_noop::value, "join type requires on()"); + static_assert(not is_noop::value, "join type requires on()"); return { *this, t }; } template join_t right_outer_join(T t) { - static_assert(not vendor::is_noop::value, "join type requires on()"); + static_assert(not is_noop::value, "join type requires on()"); return { *this, t }; } @@ -143,8 +143,6 @@ namespace sqlpp On _on; }; - namespace vendor - { template struct serializer_t> { @@ -152,7 +150,7 @@ namespace sqlpp static Context& _(const T& t, Context& context) { - static_assert(not vendor::is_noop::value, "joined tables require on()"); + static_assert(not is_noop::value, "joined tables require on()"); serialize(t._lhs, context); context << JoinType::_name; context << " JOIN "; @@ -162,7 +160,6 @@ namespace sqlpp } }; - } } #endif diff --git a/include/sqlpp11/like.h b/include/sqlpp11/like.h index bb58030d..10b987ed 100644 --- a/include/sqlpp11/like.h +++ b/include/sqlpp11/like.h @@ -33,8 +33,6 @@ namespace sqlpp { - namespace vendor - { template struct like_t: public boolean::template expression_operators>, public alias_operators> @@ -84,7 +82,6 @@ namespace sqlpp return context; } }; - } } #endif diff --git a/include/sqlpp11/limit.h b/include/sqlpp11/limit.h index 0548d9ff..61e94d06 100644 --- a/include/sqlpp11/limit.h +++ b/include/sqlpp11/limit.h @@ -33,8 +33,6 @@ namespace sqlpp { - namespace vendor - { // LIMIT DATA template struct limit_data_t @@ -254,7 +252,6 @@ namespace sqlpp return context; } }; - } } #endif diff --git a/include/sqlpp11/max.h b/include/sqlpp11/max.h index 582d6a9f..78cb12f9 100644 --- a/include/sqlpp11/max.h +++ b/include/sqlpp11/max.h @@ -31,8 +31,6 @@ namespace sqlpp { - namespace vendor - { template struct max_t: public value_type_of::template expression_operators>, public alias_operators> @@ -66,14 +64,11 @@ namespace sqlpp Expr _expr; }; - } - namespace vendor - { template - struct serializer_t> + struct serializer_t> { - using T = vendor::max_t; + using T = max_t; static Context& _(const T& t, Context& context) { @@ -83,12 +78,11 @@ namespace sqlpp return context; } }; - } template - auto max(T t) -> typename vendor::max_t> + auto max(T t) -> typename max_t> { - static_assert(is_expression_t>::value, "max() requires a value expression as argument"); + static_assert(is_expression_t>::value, "max() requires a value expression as argument"); return { t }; } diff --git a/include/sqlpp11/min.h b/include/sqlpp11/min.h index 5930a48c..28e72f21 100644 --- a/include/sqlpp11/min.h +++ b/include/sqlpp11/min.h @@ -31,8 +31,6 @@ namespace sqlpp { - namespace vendor - { template struct min_t: public value_type_of::template expression_operators>, public alias_operators> @@ -66,14 +64,11 @@ namespace sqlpp Expr _expr; }; - } - namespace vendor - { template - struct serializer_t> + struct serializer_t> { - using T = vendor::min_t; + using T = min_t; static Context& _(const T& t, Context& context) { @@ -83,12 +78,11 @@ namespace sqlpp return context; } }; - } template - auto min(T t) -> typename vendor::min_t> + auto min(T t) -> typename min_t> { - static_assert(is_expression_t>::value, "min() requires a value expression as argument"); + static_assert(is_expression_t>::value, "min() requires a value expression as argument"); return { t }; } diff --git a/include/sqlpp11/multi_column.h b/include/sqlpp11/multi_column.h index 650e1bc7..6484ba96 100644 --- a/include/sqlpp11/multi_column.h +++ b/include/sqlpp11/multi_column.h @@ -110,8 +110,6 @@ namespace sqlpp std::tuple _columns; }; - namespace vendor - { template struct serializer_t> { @@ -134,7 +132,6 @@ namespace sqlpp return context; } }; - } namespace detail { diff --git a/include/sqlpp11/named_interpretable.h b/include/sqlpp11/named_interpretable.h index 08e4ed68..8e91d06c 100644 --- a/include/sqlpp11/named_interpretable.h +++ b/include/sqlpp11/named_interpretable.h @@ -33,8 +33,6 @@ namespace sqlpp { - namespace vendor - { template struct named_interpretable_t { @@ -133,7 +131,6 @@ namespace sqlpp return context; } }; - } } diff --git a/include/sqlpp11/noop.h b/include/sqlpp11/noop.h index 25e799d8..57ca5e14 100644 --- a/include/sqlpp11/noop.h +++ b/include/sqlpp11/noop.h @@ -33,8 +33,6 @@ namespace sqlpp { - namespace vendor - { #warning: Need extra include file for no_data struct no_data_t {}; @@ -74,7 +72,6 @@ namespace sqlpp template struct is_noop: std::is_same {}; - } } #endif diff --git a/include/sqlpp11/noop_fwd.h b/include/sqlpp11/noop_fwd.h index 243f77a2..4936e858 100644 --- a/include/sqlpp11/noop_fwd.h +++ b/include/sqlpp11/noop_fwd.h @@ -29,12 +29,9 @@ namespace sqlpp { - namespace vendor - { struct noop; template struct is_noop; - } } #endif diff --git a/include/sqlpp11/null.h b/include/sqlpp11/null.h index 7119998d..f78ce12d 100644 --- a/include/sqlpp11/null.h +++ b/include/sqlpp11/null.h @@ -37,8 +37,6 @@ namespace sqlpp using _recursive_traits = make_recursive_traits<>; }; - namespace vendor - { template struct serializer_t { @@ -50,7 +48,6 @@ namespace sqlpp return context; } }; - } constexpr null_t null = {}; diff --git a/include/sqlpp11/offset.h b/include/sqlpp11/offset.h index 3fc71329..1a9eb8e2 100644 --- a/include/sqlpp11/offset.h +++ b/include/sqlpp11/offset.h @@ -33,8 +33,6 @@ namespace sqlpp { - namespace vendor - { // OFFSET DATA template struct offset_data_t @@ -264,7 +262,6 @@ namespace sqlpp return context; } }; - } } #endif diff --git a/include/sqlpp11/on.h b/include/sqlpp11/on.h index 0f15b530..224cc652 100644 --- a/include/sqlpp11/on.h +++ b/include/sqlpp11/on.h @@ -53,11 +53,9 @@ namespace sqlpp } std::tuple _expressions; - vendor::interpretable_list_t _dynamic_expressions; + interpretable_list_t _dynamic_expressions; }; - namespace vendor - { template struct serializer_t> { @@ -76,7 +74,6 @@ namespace sqlpp } }; - } } #endif diff --git a/include/sqlpp11/order_by.h b/include/sqlpp11/order_by.h index b1f41e11..f431224f 100644 --- a/include/sqlpp11/order_by.h +++ b/include/sqlpp11/order_by.h @@ -37,8 +37,6 @@ namespace sqlpp { - namespace vendor - { // ORDER BY DATA template struct order_by_data_t @@ -54,7 +52,7 @@ namespace sqlpp ~order_by_data_t() = default; std::tuple _expressions; - vendor::interpretable_list_t _dynamic_expressions; + interpretable_list_t _dynamic_expressions; }; // ORDER BY @@ -208,7 +206,6 @@ namespace sqlpp return context; } }; - } } #endif diff --git a/include/sqlpp11/parameter.h b/include/sqlpp11/parameter.h index 565f236a..b582b805 100644 --- a/include/sqlpp11/parameter.h +++ b/include/sqlpp11/parameter.h @@ -57,8 +57,6 @@ namespace sqlpp ~parameter_t() = default; }; - namespace vendor - { template struct serializer_t> { @@ -70,7 +68,6 @@ namespace sqlpp return context; } }; - } template auto parameter(const NamedExpr&) @@ -82,7 +79,7 @@ namespace sqlpp template auto parameter(const ValueType&, const AliasProvider&) - -> parameter_t, AliasProvider> + -> parameter_t, AliasProvider> { static_assert(is_expression_t::value, "first argument is not a value type"); static_assert(is_alias_provider_t::value, "second argument is not an alias provider"); diff --git a/include/sqlpp11/parameter_list.h b/include/sqlpp11/parameter_list.h index 47ca39b0..e7386d2a 100644 --- a/include/sqlpp11/parameter_list.h +++ b/include/sqlpp11/parameter_list.h @@ -37,7 +37,7 @@ namespace sqlpp template struct parameter_list_t { - static_assert(vendor::wrong_t::value, "Template parameter for parameter_list_t has to be a tuple"); + static_assert(wrong_t::value, "Template parameter for parameter_list_t has to be a tuple"); }; template diff --git a/include/sqlpp11/policy_update.h b/include/sqlpp11/policy_update.h index df1ed8cb..5183767b 100644 --- a/include/sqlpp11/policy_update.h +++ b/include/sqlpp11/policy_update.h @@ -31,8 +31,6 @@ namespace sqlpp { - namespace vendor - { template struct policy_update_impl { @@ -52,7 +50,6 @@ namespace sqlpp template using update_policies_t = typename update_policies_impl::type; - } } diff --git a/include/sqlpp11/remove.h b/include/sqlpp11/remove.h index 07d5923d..54ffcbc1 100644 --- a/include/sqlpp11/remove.h +++ b/include/sqlpp11/remove.h @@ -41,7 +41,7 @@ namespace sqlpp { struct remove_name_t {}; - struct remove_t: public vendor::statement_name_t + struct remove_t: public statement_name_t { using _traits = make_traits; struct _name_t {}; @@ -79,8 +79,6 @@ namespace sqlpp }; - namespace vendor - { template struct serializer_t { @@ -93,15 +91,14 @@ namespace sqlpp return context; } }; - } template using blank_remove_t = statement_t; + no_from_t, + no_using_t, + no_extra_tables_t, + no_where_t>; auto remove() -> blank_remove_t diff --git a/include/sqlpp11/result_row.h b/include/sqlpp11/result_row.h index 9415c2a9..2f31c117 100644 --- a/include/sqlpp11/result_row.h +++ b/include/sqlpp11/result_row.h @@ -76,7 +76,7 @@ namespace sqlpp }; template - struct result_field>>: + struct result_field>>: public AliasProvider::_name_t::template _member_t, NamedExprs...>> { using _multi_field = typename AliasProvider::_name_t::template _member_t, NamedExprs...>>; diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 850a5b11..c014abe4 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -48,11 +48,9 @@ namespace sqlpp { struct select_name_t {}; - struct select_t: public vendor::statement_name_t + struct select_t: public statement_name_t {}; - namespace vendor - { template struct serializer_t { @@ -65,21 +63,20 @@ namespace sqlpp return context; } }; - } template using blank_select_t = statement_t; + no_select_flag_list_t, + no_select_column_list_t, + no_from_t, + no_extra_tables_t, + no_where_t, + no_group_by_t, + no_having_t, + no_order_by_t, + no_limit_t, + no_offset_t>; blank_select_t select() // FIXME: These should be constexpr diff --git a/include/sqlpp11/select_column_list.h b/include/sqlpp11/select_column_list.h index 44ef1325..efdaf8ed 100644 --- a/include/sqlpp11/select_column_list.h +++ b/include/sqlpp11/select_column_list.h @@ -59,13 +59,11 @@ namespace sqlpp }; } - namespace vendor - { template struct dynamic_select_column_list { using _names_t = std::vector; - std::vector> _dynamic_columns; + std::vector> _dynamic_columns; _names_t _dynamic_expression_names; template @@ -311,18 +309,15 @@ namespace sqlpp }; }; - } namespace detail { template using make_select_column_list_t = - copy_tuple_args_t::_(std::declval())...))>; } - namespace vendor - { struct no_select_column_list_t { using _traits = make_traits; @@ -401,7 +396,6 @@ namespace sqlpp } }; - } } #endif diff --git a/include/sqlpp11/select_flag_list.h b/include/sqlpp11/select_flag_list.h index c2430420..9b0414e3 100644 --- a/include/sqlpp11/select_flag_list.h +++ b/include/sqlpp11/select_flag_list.h @@ -36,8 +36,6 @@ namespace sqlpp { - namespace vendor - { // SELECTED FLAGS DATA template struct select_flag_list_data_t @@ -53,7 +51,7 @@ namespace sqlpp ~select_flag_list_data_t() = default; std::tuple _flags; - vendor::interpretable_list_t _dynamic_flags; + interpretable_list_t _dynamic_flags; }; // SELECT FLAGS @@ -207,7 +205,6 @@ namespace sqlpp } }; - } } diff --git a/include/sqlpp11/select_flags.h b/include/sqlpp11/select_flags.h index 278e65ec..e082680f 100644 --- a/include/sqlpp11/select_flags.h +++ b/include/sqlpp11/select_flags.h @@ -42,8 +42,6 @@ namespace sqlpp }; static constexpr all_t all = {}; - namespace vendor - { template struct serializer_t { @@ -53,7 +51,6 @@ namespace sqlpp return context; } }; - } struct distinct_t { @@ -62,8 +59,6 @@ namespace sqlpp }; static constexpr distinct_t distinct = {}; - namespace vendor - { template struct serializer_t { @@ -73,7 +68,6 @@ namespace sqlpp return context; } }; - } struct straight_join_t { @@ -82,8 +76,6 @@ namespace sqlpp }; static constexpr straight_join_t straight_join = {}; - namespace vendor - { template struct serializer_t { @@ -93,7 +85,6 @@ namespace sqlpp return context; } }; - } } diff --git a/include/sqlpp11/select_pseudo_table.h b/include/sqlpp11/select_pseudo_table.h index 86e9e4b9..efd9d4d3 100644 --- a/include/sqlpp11/select_pseudo_table.h +++ b/include/sqlpp11/select_pseudo_table.h @@ -72,8 +72,6 @@ namespace sqlpp Select _select; }; - namespace vendor - { template struct serializer_t> { @@ -86,7 +84,6 @@ namespace sqlpp } }; - } } #endif diff --git a/include/sqlpp11/serialize.h b/include/sqlpp11/serialize.h index 5dce87d2..c8641ae7 100644 --- a/include/sqlpp11/serialize.h +++ b/include/sqlpp11/serialize.h @@ -33,21 +33,18 @@ namespace sqlpp { template auto serialize(const T& t, Context& context) - -> decltype(vendor::serializer_t::_(t, context)) + -> decltype(serializer_t::_(t, context)) { - return vendor::serializer_t::_(t, context); + return serializer_t::_(t, context); } /* - namespace vendor // Required if you want to call serialize(sqlpp::value(7), printer), for instance - { template auto serialize(const T& t, Context& context) - -> decltype(vendor::serializer_t::_(t, context)) + -> decltype(serializer_t::_(t, context)) { - return vendor::serializer_t::_(t, context); + return serializer_t::_(t, context); } - } */ } diff --git a/include/sqlpp11/serializer.h b/include/sqlpp11/serializer.h index bda5ff8e..c263b393 100644 --- a/include/sqlpp11/serializer.h +++ b/include/sqlpp11/serializer.h @@ -31,8 +31,6 @@ namespace sqlpp { - namespace vendor - { template struct serializer_t { @@ -41,7 +39,6 @@ namespace sqlpp static_assert(wrong_t::value, "missing serializer specialization"); } }; - } } diff --git a/include/sqlpp11/simple_column.h b/include/sqlpp11/simple_column.h index ea22d66b..bdf74345 100644 --- a/include/sqlpp11/simple_column.h +++ b/include/sqlpp11/simple_column.h @@ -31,8 +31,6 @@ namespace sqlpp { - namespace vendor - { template struct simple_column_t { @@ -56,7 +54,6 @@ namespace sqlpp { return {c}; } - } } #endif diff --git a/include/sqlpp11/single_table.h b/include/sqlpp11/single_table.h index 58745839..23544dba 100644 --- a/include/sqlpp11/single_table.h +++ b/include/sqlpp11/single_table.h @@ -34,8 +34,6 @@ namespace sqlpp { - namespace vendor - { // A SINGLE TABLE DATA template struct single_table_data_t @@ -211,7 +209,6 @@ namespace sqlpp } }; - } } #endif diff --git a/include/sqlpp11/some.h b/include/sqlpp11/some.h index 5fe64cac..2b1fb002 100644 --- a/include/sqlpp11/some.h +++ b/include/sqlpp11/some.h @@ -32,8 +32,6 @@ namespace sqlpp { - namespace vendor - { template struct some_t { @@ -64,14 +62,11 @@ namespace sqlpp Select _select; }; - } - namespace vendor - { template - struct serializer_t> + struct serializer_t> { - using T = vendor::some_t; static Context& _(const T& t, Context& context) { @@ -81,13 +76,12 @@ namespace sqlpp return context; } }; - } template - auto some(T t) -> typename vendor::some_t> + auto some(T t) -> typename some_t> { - static_assert(is_select_t>::value, "some() requires a single column select expression as argument"); - static_assert(is_expression_t>::value, "some() requires a single column select expression as argument"); + static_assert(is_select_t>::value, "some() requires a single column select expression as argument"); + static_assert(is_expression_t>::value, "some() requires a single column select expression as argument"); return { t }; } diff --git a/include/sqlpp11/sort_order.h b/include/sqlpp11/sort_order.h index 7ef6c238..a7e8bdea 100644 --- a/include/sqlpp11/sort_order.h +++ b/include/sqlpp11/sort_order.h @@ -46,8 +46,6 @@ namespace sqlpp Expression _expression; }; - namespace vendor - { template struct serializer_t> { @@ -69,7 +67,6 @@ namespace sqlpp } }; - } } #endif diff --git a/include/sqlpp11/statement.h b/include/sqlpp11/statement.h index 895babdc..e875ac20 100644 --- a/include/sqlpp11/statement.h +++ b/include/sqlpp11/statement.h @@ -61,7 +61,7 @@ namespace sqlpp struct _policies_update_t { static_assert(detail::is_element_of>::value, "policies update for non-policy class detected"); - using type = statement_t...>; + using type = statement_t...>; }; template @@ -82,7 +82,7 @@ namespace sqlpp _all_provided_tables // Hint: extra_tables are not used here because they are just a helper for dynamic .add_*() >; - using _result_type_provider = detail::get_last_if; + using _result_type_provider = detail::get_last_if; struct _result_methods_t: public _result_type_provider::template _result_methods_t {}; @@ -181,8 +181,6 @@ namespace sqlpp }; - namespace vendor - { template struct serializer_t> { @@ -238,7 +236,6 @@ namespace sqlpp }; }; - } } #endif diff --git a/include/sqlpp11/sum.h b/include/sqlpp11/sum.h index 7487a5b9..9bfca5d9 100644 --- a/include/sqlpp11/sum.h +++ b/include/sqlpp11/sum.h @@ -31,8 +31,6 @@ namespace sqlpp { - namespace vendor - { template struct sum_t: public value_type_of::template expression_operators>, public alias_operators> @@ -67,14 +65,11 @@ namespace sqlpp Expr _expr; }; - } - namespace vendor - { template - struct serializer_t> + struct serializer_t> { - using T = vendor::sum_t; + using T = sum_t; static Context& _(const T& t, Context& context) { @@ -89,19 +84,18 @@ namespace sqlpp return context; } }; - } template - auto sum(T t) -> typename vendor::sum_t> + auto sum(T t) -> typename sum_t> { - static_assert(is_numeric_t>::value, "sum() requires a numeric expression as argument"); + static_assert(is_numeric_t>::value, "sum() requires a numeric expression as argument"); return { t }; } template - auto sum(const sqlpp::distinct_t&, T t) -> typename vendor::sum_t> + auto sum(const sqlpp::distinct_t&, T t) -> typename sum_t> { - static_assert(is_numeric_t>::value, "sum() requires a numeric expression as argument"); + static_assert(is_numeric_t>::value, "sum() requires a numeric expression as argument"); return { t }; } diff --git a/include/sqlpp11/table.h b/include/sqlpp11/table.h index 5f74da41..fa2e1043 100644 --- a/include/sqlpp11/table.h +++ b/include/sqlpp11/table.h @@ -101,8 +101,6 @@ namespace sqlpp } }; - namespace vendor - { template struct serializer_t::value and not is_pseudo_table_t::value, void>::type> { @@ -116,7 +114,6 @@ namespace sqlpp }; - } } #endif diff --git a/include/sqlpp11/table_alias.h b/include/sqlpp11/table_alias.h index e357973c..d8bc5ba5 100644 --- a/include/sqlpp11/table_alias.h +++ b/include/sqlpp11/table_alias.h @@ -61,8 +61,6 @@ namespace sqlpp Table _table; }; - namespace vendor - { template struct serializer_t> { @@ -77,7 +75,6 @@ namespace sqlpp } }; - } } #endif diff --git a/include/sqlpp11/text.h b/include/sqlpp11/text.h index c3a52913..1d533dcb 100644 --- a/include/sqlpp11/text.h +++ b/include/sqlpp11/text.h @@ -189,18 +189,18 @@ namespace sqlpp struct expression_operators: public basic_expression_operators { template - vendor::concat_t> operator+(T t) const + concat_t> operator+(T t) const { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs operand"); return { *static_cast(this), {t} }; } template - vendor::like_t> like(T t) const + like_t> like(T t) const { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid argument for like()"); return { *static_cast(this), {t} }; @@ -211,9 +211,9 @@ namespace sqlpp struct column_operators { template - auto operator +=(T t) const -> vendor::assignment_t>> + auto operator +=(T t) const -> assignment_t>> { - using rhs = vendor::wrap_operand_t; + using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); return { *static_cast(this), { *static_cast(this), rhs{t} } }; diff --git a/include/sqlpp11/tvin.h b/include/sqlpp11/tvin.h index 83a4f360..823706c1 100644 --- a/include/sqlpp11/tvin.h +++ b/include/sqlpp11/tvin.h @@ -61,8 +61,6 @@ namespace sqlpp Operand _value; }; - namespace vendor - { template struct serializer_t> { @@ -70,10 +68,9 @@ namespace sqlpp static void _(const T& t, Context& context) { - static_assert(vendor::wrong_t::value, "tvin() must not be used with anything but =, ==, != and !"); + static_assert(wrong_t::value, "tvin() must not be used with anything but =, ==, != and !"); } }; - } template struct maybe_tvin_t @@ -121,8 +118,6 @@ namespace sqlpp typename tvin_t::_operand_t _value; }; - namespace vendor - { template struct serializer_t> { @@ -141,13 +136,12 @@ namespace sqlpp return context; } }; - } template - auto tvin(Operand operand) -> tvin_t::type> + auto tvin(Operand operand) -> tvin_t::type> { - using _operand_t = typename vendor::wrap_operand::type; - static_assert(std::is_same<_operand_t, vendor::text_operand>::value + using _operand_t = typename wrap_operand::type; + static_assert(std::is_same<_operand_t, text_operand>::value or not std::is_same<_operand_t, Operand>::value, "tvin() used with invalid type (only string and primitive types allowed)"); return {{operand}}; } diff --git a/include/sqlpp11/update.h b/include/sqlpp11/update.h index be992719..e598d69b 100644 --- a/include/sqlpp11/update.h +++ b/include/sqlpp11/update.h @@ -41,7 +41,7 @@ namespace sqlpp { struct update_name_t {}; - struct update_t: public vendor::statement_name_t + struct update_t: public statement_name_t { using _traits = make_traits; struct _name_t {}; @@ -79,8 +79,6 @@ namespace sqlpp }; - namespace vendor - { template struct serializer_t { @@ -93,14 +91,13 @@ namespace sqlpp return context; } }; - } template using blank_update_t = statement_t; + no_single_table_t, + no_update_list_t, + no_where_t>; template constexpr auto update(Table table) diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index 11c916fd..a311bef0 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -34,8 +34,6 @@ namespace sqlpp { - namespace vendor - { // UPDATE ASSIGNMENTS DATA template struct update_list_data_t @@ -51,7 +49,7 @@ namespace sqlpp ~update_list_data_t() = default; std::tuple _assignments; - typename vendor::interpretable_list_t _dynamic_assignments; + typename interpretable_list_t _dynamic_assignments; }; // UPDATE ASSIGNMENTS @@ -196,7 +194,7 @@ namespace sqlpp -> _new_statement_t> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_set must not be called in a static statement"); - return { *static_cast(this), vendor::update_list_data_t<_database_t, Args...>{args...} }; + return { *static_cast(this), update_list_data_t<_database_t, Args...>{args...} }; } }; }; @@ -217,7 +215,6 @@ namespace sqlpp return context; } }; - } } #endif diff --git a/include/sqlpp11/using.h b/include/sqlpp11/using.h index 0841b8b0..6aabd249 100644 --- a/include/sqlpp11/using.h +++ b/include/sqlpp11/using.h @@ -35,8 +35,6 @@ namespace sqlpp { - namespace vendor - { // USING DATA template struct using_data_t @@ -52,7 +50,7 @@ namespace sqlpp ~using_data_t() = default; std::tuple _tables; - vendor::interpretable_list_t _dynamic_tables; + interpretable_list_t _dynamic_tables; }; // USING @@ -201,7 +199,6 @@ namespace sqlpp return context; } }; - } } #endif diff --git a/include/sqlpp11/value_type.h b/include/sqlpp11/value_type.h index a4bca0e3..e7f38198 100644 --- a/include/sqlpp11/value_type.h +++ b/include/sqlpp11/value_type.h @@ -32,10 +32,7 @@ namespace sqlpp { - namespace vendor - { template using value_type_t = value_type_of>; - } } #endif diff --git a/include/sqlpp11/verbatim_table.h b/include/sqlpp11/verbatim_table.h index d4715bf2..39799bfe 100644 --- a/include/sqlpp11/verbatim_table.h +++ b/include/sqlpp11/verbatim_table.h @@ -63,8 +63,6 @@ namespace sqlpp std::string _name; }; - namespace vendor - { template struct serializer_t { @@ -76,7 +74,6 @@ namespace sqlpp return context; } }; - } verbatim_table_t verbatim_table(std::string name) diff --git a/include/sqlpp11/where.h b/include/sqlpp11/where.h index 4652cdee..93331606 100644 --- a/include/sqlpp11/where.h +++ b/include/sqlpp11/where.h @@ -36,8 +36,6 @@ namespace sqlpp { - namespace vendor - { // WHERE DATA template struct where_data_t @@ -53,7 +51,7 @@ namespace sqlpp ~where_data_t() = default; std::tuple _expressions; - vendor::interpretable_list_t _dynamic_expressions; + interpretable_list_t _dynamic_expressions; }; // WHERE(EXPR) @@ -271,7 +269,6 @@ namespace sqlpp } }; - } } #endif diff --git a/include/sqlpp11/wrap_operand.h b/include/sqlpp11/wrap_operand.h index 380c91e5..e5be8c06 100644 --- a/include/sqlpp11/wrap_operand.h +++ b/include/sqlpp11/wrap_operand.h @@ -41,8 +41,6 @@ namespace sqlpp struct text; } - namespace vendor - { struct boolean_operand { using _traits = make_traits<::sqlpp::detail::boolean, ::sqlpp::tag::expression, ::sqlpp::tag::wrapped_value>; @@ -231,7 +229,6 @@ namespace sqlpp template using wrap_operand_t = typename wrap_operand::type; - } } #endif diff --git a/include/sqlpp11/wrong.h b/include/sqlpp11/wrong.h index 7cc59ac4..af7ce7f4 100644 --- a/include/sqlpp11/wrong.h +++ b/include/sqlpp11/wrong.h @@ -31,8 +31,6 @@ namespace sqlpp { - namespace vendor - { namespace detail { // A template that always returns false @@ -46,6 +44,5 @@ namespace sqlpp } template using wrong_t = typename detail::wrong::type; - } } #endif From 269f2e7e17accac4350b0115b3711be21c5ad62d Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 14 Jun 2014 07:45:10 +0200 Subject: [PATCH 34/65] Fixed indentations --- include/sqlpp11/alias.h | 26 +- include/sqlpp11/alias_provider.h | 20 +- include/sqlpp11/all_of.h | 44 +- include/sqlpp11/any.h | 40 +- include/sqlpp11/assignment.h | 190 ++--- include/sqlpp11/avg.h | 92 +-- include/sqlpp11/basic_expression_operators.h | 14 +- include/sqlpp11/boolean.h | 164 ++--- include/sqlpp11/column.h | 24 +- include/sqlpp11/concat.h | 84 +-- include/sqlpp11/count.h | 92 +-- include/sqlpp11/default_value.h | 20 +- include/sqlpp11/exists.h | 84 +-- include/sqlpp11/expression.h | 246 +++---- include/sqlpp11/expression_fwd.h | 190 ++--- include/sqlpp11/extra_tables.h | 198 ++--- include/sqlpp11/field.h | 58 +- include/sqlpp11/floating_point.h | 224 +++--- include/sqlpp11/from.h | 242 +++---- include/sqlpp11/functions.h | 56 +- include/sqlpp11/group_by.h | 278 +++---- include/sqlpp11/having.h | 278 +++---- include/sqlpp11/in.h | 90 +-- include/sqlpp11/in_fwd.h | 2 +- include/sqlpp11/insert.h | 26 +- include/sqlpp11/insert_value.h | 150 ++-- include/sqlpp11/insert_value_list.h | 726 +++++++++---------- include/sqlpp11/integral.h | 224 +++--- include/sqlpp11/interpret_tuple.h | 2 +- include/sqlpp11/interpretable.h | 140 ++-- include/sqlpp11/interpretable_list.h | 134 ++-- include/sqlpp11/interpreter.h | 14 +- include/sqlpp11/into.h | 248 +++---- include/sqlpp11/is_null.h | 88 +-- include/sqlpp11/is_null_fwd.h | 2 +- include/sqlpp11/join.h | 30 +- include/sqlpp11/like.h | 90 +-- include/sqlpp11/limit.h | 362 ++++----- include/sqlpp11/max.h | 84 +-- include/sqlpp11/min.h | 84 +-- include/sqlpp11/multi_column.h | 36 +- include/sqlpp11/named_interpretable.h | 158 ++-- include/sqlpp11/noop.h | 62 +- include/sqlpp11/noop_fwd.h | 6 +- include/sqlpp11/null.h | 20 +- include/sqlpp11/offset.h | 392 +++++----- include/sqlpp11/on.h | 30 +- include/sqlpp11/order_by.h | 278 +++---- include/sqlpp11/parameter.h | 22 +- include/sqlpp11/policy_update.h | 30 +- include/sqlpp11/prepared_insert.h | 6 +- include/sqlpp11/prepared_remove.h | 6 +- include/sqlpp11/prepared_select.h | 6 +- include/sqlpp11/prepared_update.h | 6 +- include/sqlpp11/remove.h | 30 +- include/sqlpp11/result.h | 12 +- include/sqlpp11/result_row.h | 80 +- include/sqlpp11/select.h | 42 +- include/sqlpp11/select_column_list.h | 588 +++++++-------- include/sqlpp11/select_flag_list.h | 274 +++---- include/sqlpp11/select_flags.h | 48 +- include/sqlpp11/select_pseudo_table.h | 26 +- include/sqlpp11/serialize.h | 14 +- include/sqlpp11/serializer.h | 14 +- include/sqlpp11/simple_column.h | 38 +- include/sqlpp11/single_table.h | 286 ++++---- include/sqlpp11/some.h | 26 +- include/sqlpp11/sort_order.h | 34 +- include/sqlpp11/statement.h | 124 ++-- include/sqlpp11/sum.h | 92 +-- include/sqlpp11/table.h | 22 +- include/sqlpp11/table_alias.h | 24 +- include/sqlpp11/text.h | 190 ++--- include/sqlpp11/transaction.h | 84 +-- include/sqlpp11/tvin.h | 50 +- include/sqlpp11/type_traits.h | 28 +- include/sqlpp11/update.h | 32 +- include/sqlpp11/update_list.h | 288 ++++---- include/sqlpp11/using.h | 270 +++---- include/sqlpp11/value_type.h | 4 +- include/sqlpp11/verbatim_table.h | 20 +- include/sqlpp11/where.h | 350 ++++----- include/sqlpp11/wrap_operand.h | 316 ++++---- include/sqlpp11/wrong.h | 24 +- 84 files changed, 4824 insertions(+), 4824 deletions(-) diff --git a/include/sqlpp11/alias.h b/include/sqlpp11/alias.h index 2cd0da5d..eeb9e2b6 100644 --- a/include/sqlpp11/alias.h +++ b/include/sqlpp11/alias.h @@ -46,20 +46,20 @@ namespace sqlpp Expression _expression; }; - template - struct serializer_t> - { - using T = expression_alias_t; + template + struct serializer_t> + { + using T = expression_alias_t; - static Context& _(const T& t, Context& context) - { - context << '('; - serialize(t._expression, context); - context << ") AS "; - context << T::_name_t::_get_name(); - return context; - } - }; + static Context& _(const T& t, Context& context) + { + context << '('; + serialize(t._expression, context); + context << ") AS "; + context << T::_name_t::_get_name(); + return context; + } + }; } diff --git a/include/sqlpp11/alias_provider.h b/include/sqlpp11/alias_provider.h index 6949933b..78dcf1e3 100644 --- a/include/sqlpp11/alias_provider.h +++ b/include/sqlpp11/alias_provider.h @@ -31,20 +31,20 @@ #define SQLPP_ALIAS_PROVIDER(name) \ struct name##_t\ +{\ + struct _name_t\ {\ - struct _name_t\ + static constexpr const char* _get_name() { return #name; }\ + template\ + struct _member_t\ {\ - static constexpr const char* _get_name() { return #name; }\ - template\ - struct _member_t\ - {\ - T name;\ - T& operator()() { return name; }\ - const T& operator()() const { return name; }\ - };\ + T name;\ + T& operator()() { return name; }\ + const T& operator()() const { return name; }\ };\ };\ - constexpr name##_t name = {}; +};\ +constexpr name##_t name = {}; namespace sqlpp { diff --git a/include/sqlpp11/all_of.h b/include/sqlpp11/all_of.h index fb3c6a14..b4d90fae 100644 --- a/include/sqlpp11/all_of.h +++ b/include/sqlpp11/all_of.h @@ -34,33 +34,33 @@ namespace sqlpp { template - struct all_of_t - { - using _column_tuple_t = typename Table::_column_tuple_t; + struct all_of_t + { + using _column_tuple_t = typename Table::_column_tuple_t; - template - detail::copy_tuple_args_t as(const AliasProvider& alias) - { - return ::sqlpp::multi_column(_column_tuple_t{}).as(alias); - } - }; + template + detail::copy_tuple_args_t as(const AliasProvider& alias) + { + return ::sqlpp::multi_column(_column_tuple_t{}).as(alias); + } + }; template - auto all_of(Table t) -> all_of_t
- { - return {}; - } + auto all_of(Table t) -> all_of_t
+ { + return {}; + } - template - struct serializer_t> + template + struct serializer_t> + { + using T = all_of_t
; + + static Context& _(const T& t, const Context&) { - using T = all_of_t
; - - static Context& _(const T& t, const Context&) - { - static_assert(wrong_t::value, "all_of(table) does not seem to be used in select"); - } - }; + static_assert(wrong_t::value, "all_of(table) does not seem to be used in select"); + } + }; } diff --git a/include/sqlpp11/any.h b/include/sqlpp11/any.h index a8ffed96..c2f6258f 100644 --- a/include/sqlpp11/any.h +++ b/include/sqlpp11/any.h @@ -32,7 +32,7 @@ namespace sqlpp { - template + template struct any_t { using _traits = make_traits, ::sqlpp::tag::multi_expression>; @@ -63,28 +63,28 @@ namespace sqlpp Select _select; }; - template - struct serializer_t> - { - using T = any_t; - static Context& _(const T& t, Context& context) - { - context << "ANY("; - serialize(t._select, context); - context << ")"; - return context; - } - }; - - template - auto any(T t) -> typename any_t> + static Context& _(const T& t, Context& context) { - static_assert(is_select_t>::value, "any() requires a select expression as argument"); - static_assert(is_expression_t>::value, "any() requires a single column select expression as argument"); - // FIXME: can we accept non-values like NULL here? - return { t }; + context << "ANY("; + serialize(t._select, context); + context << ")"; + return context; } + }; + + template + auto any(T t) -> typename any_t> + { + static_assert(is_select_t>::value, "any() requires a select expression as argument"); + static_assert(is_expression_t>::value, "any() requires a single column select expression as argument"); + // FIXME: can we accept non-values like NULL here? + return { t }; + } } diff --git a/include/sqlpp11/assignment.h b/include/sqlpp11/assignment.h index 15ed6dcb..8161db1b 100644 --- a/include/sqlpp11/assignment.h +++ b/include/sqlpp11/assignment.h @@ -36,7 +36,7 @@ namespace sqlpp { - template + template struct is_trivial_t { static constexpr bool _(const T&) @@ -45,7 +45,7 @@ namespace sqlpp } }; - template + template struct is_trivial_t::value, void>::type> { static bool _(const T& t) @@ -54,108 +54,108 @@ namespace sqlpp } }; - template + template bool is_trivial(const T& t) { return is_trivial_t::_(t); } - template - struct assignment_t + template + struct assignment_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + + using _column_t = Lhs; + using _value_t = Rhs; + + static_assert(can_be_null_t<_column_t>::value ? true : not std::is_same<_value_t, null_t>::value, "column must not be null"); + + assignment_t(_column_t lhs, _value_t rhs): + _lhs(lhs), + _rhs(rhs) + {} + + assignment_t(const assignment_t&) = default; + assignment_t(assignment_t&&) = default; + assignment_t& operator=(const assignment_t&) = default; + assignment_t& operator=(assignment_t&&) = default; + ~assignment_t() = default; + + _column_t _lhs; + _value_t _rhs; + }; + + template + struct serializer_t> + { + using T = assignment_t; + + static Context& _(const T& t, Context& context) { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits; - - using _column_t = Lhs; - using _value_t = Rhs; - - static_assert(can_be_null_t<_column_t>::value ? true : not std::is_same<_value_t, null_t>::value, "column must not be null"); - - assignment_t(_column_t lhs, _value_t rhs): - _lhs(lhs), - _rhs(rhs) - {} - - assignment_t(const assignment_t&) = default; - assignment_t(assignment_t&&) = default; - assignment_t& operator=(const assignment_t&) = default; - assignment_t& operator=(assignment_t&&) = default; - ~assignment_t() = default; - - _column_t _lhs; - _value_t _rhs; - }; - - template - struct serializer_t> - { - using T = assignment_t; - - static Context& _(const T& t, Context& context) - { - if ((trivial_value_is_null_t::value - and is_trivial(t._rhs)) - or (std::is_same::value)) - { - serialize(simple_column(t._lhs), context); - context << "=NULL"; - } - else - { - serialize(simple_column(t._lhs), context); - context << "="; - serialize(t._rhs, context); - } - return context; - } - }; - - template - struct assignment_t> - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits; - - using _column_t = Lhs; - using _value_t = tvin_t; - - static_assert(can_be_null_t<_column_t>::value, "column cannot be null"); - - assignment_t(_column_t lhs, _value_t rhs): - _lhs(lhs), - _rhs(rhs) - {} - - assignment_t(const assignment_t&) = default; - assignment_t(assignment_t&&) = default; - assignment_t& operator=(const assignment_t&) = default; - assignment_t& operator=(assignment_t&&) = default; - ~assignment_t() = default; - - _column_t _lhs; - _value_t _rhs; - }; - - template - struct serializer_t>> - { - using T = assignment_t>; - - static Context& _(const T& t, Context& context) + if ((trivial_value_is_null_t::value + and is_trivial(t._rhs)) + or (std::is_same::value)) { serialize(simple_column(t._lhs), context); - if (t._rhs._value._is_trivial()) - { - context << "=NULL"; - } - else - { - context << "="; - serialize(t._rhs._value, context); - } - return context; + context << "=NULL"; } - }; + else + { + serialize(simple_column(t._lhs), context); + context << "="; + serialize(t._rhs, context); + } + return context; + } + }; + + template + struct assignment_t> + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + + using _column_t = Lhs; + using _value_t = tvin_t; + + static_assert(can_be_null_t<_column_t>::value, "column cannot be null"); + + assignment_t(_column_t lhs, _value_t rhs): + _lhs(lhs), + _rhs(rhs) + {} + + assignment_t(const assignment_t&) = default; + assignment_t(assignment_t&&) = default; + assignment_t& operator=(const assignment_t&) = default; + assignment_t& operator=(assignment_t&&) = default; + ~assignment_t() = default; + + _column_t _lhs; + _value_t _rhs; + }; + + template + struct serializer_t>> + { + using T = assignment_t>; + + static Context& _(const T& t, Context& context) + { + serialize(simple_column(t._lhs), context); + if (t._rhs._value._is_trivial()) + { + context << "=NULL"; + } + else + { + context << "="; + serialize(t._rhs._value, context); + } + return context; + } + }; } #endif diff --git a/include/sqlpp11/avg.h b/include/sqlpp11/avg.h index 0e2cb3df..46bba2b3 100644 --- a/include/sqlpp11/avg.h +++ b/include/sqlpp11/avg.h @@ -31,59 +31,59 @@ namespace sqlpp { - template + template struct avg_t: public floating_point::template expression_operators>, - public alias_operators> + public alias_operators> + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + + static_assert(is_noop::value or std::is_same::value, "avg() used with flag other than 'distinct'"); + static_assert(is_numeric_t::value, "avg() requires a value expression as argument"); + + struct _name_t { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits; - - static_assert(is_noop::value or std::is_same::value, "avg() used with flag other than 'distinct'"); - static_assert(is_numeric_t::value, "avg() requires a value expression as argument"); - - struct _name_t - { - static constexpr const char* _get_name() { return "AVG"; } - template - struct _member_t - { - T avg; - T& operator()() { return avg; } - const T& operator()() const { return avg; } - }; - }; - - avg_t(Expr expr): - _expr(expr) - {} - - avg_t(const avg_t&) = default; - avg_t(avg_t&&) = default; - avg_t& operator=(const avg_t&) = default; - avg_t& operator=(avg_t&&) = default; - ~avg_t() = default; - - Expr _expr; + static constexpr const char* _get_name() { return "AVG"; } + template + struct _member_t + { + T avg; + T& operator()() { return avg; } + const T& operator()() const { return avg; } + }; }; - template - struct serializer_t> - { - using T = avg_t; + avg_t(Expr expr): + _expr(expr) + {} - static Context& _(const T& t, Context& context) + avg_t(const avg_t&) = default; + avg_t(avg_t&&) = default; + avg_t& operator=(const avg_t&) = default; + avg_t& operator=(avg_t&&) = default; + ~avg_t() = default; + + Expr _expr; + }; + + template + struct serializer_t> + { + using T = avg_t; + + static Context& _(const T& t, Context& context) + { + context << "AVG("; + if (std::is_same::value) { - context << "AVG("; - if (std::is_same::value) - { - serialize(Flag(), context); - context << ' '; - } - serialize(t._expr, context); - context << ")"; - return context; + serialize(Flag(), context); + context << ' '; } - }; + serialize(t._expr, context); + context << ")"; + return context; + } + }; template auto avg(T t) -> typename avg_t> diff --git a/include/sqlpp11/basic_expression_operators.h b/include/sqlpp11/basic_expression_operators.h index 87b06e5a..deeb5342 100644 --- a/include/sqlpp11/basic_expression_operators.h +++ b/include/sqlpp11/basic_expression_operators.h @@ -43,13 +43,13 @@ namespace sqlpp { template struct _is_valid_comparison_operand - { - static constexpr bool value = - (is_expression_t::value // expressions are OK - or is_multi_expression_t::value) // multi-expressions like ANY are OK for comparisons, too - and IsCorrectValueType::value // the correct value type is required, of course - ; - }; + { + static constexpr bool value = + (is_expression_t::value // expressions are OK + or is_multi_expression_t::value) // multi-expressions like ANY are OK for comparisons, too + and IsCorrectValueType::value // the correct value type is required, of course + ; + }; template equal_to_t> operator==(T t) const diff --git a/include/sqlpp11/boolean.h b/include/sqlpp11/boolean.h index b01d49bb..ed8fe94c 100644 --- a/include/sqlpp11/boolean.h +++ b/include/sqlpp11/boolean.h @@ -52,12 +52,12 @@ namespace sqlpp _parameter_t(): _value(false), _is_null(true) - {} + {} _parameter_t(const _cpp_value_type& value): _value(value), _is_null(false) - {} + {} _parameter_t& operator=(const _cpp_value_type& value) { @@ -74,7 +74,7 @@ namespace sqlpp } bool is_null() const - { + { return _is_null; } @@ -97,88 +97,88 @@ namespace sqlpp }; template - struct _result_entry_t - { - _result_entry_t(): - _is_valid(false), - _is_null(true), - _value(false) + struct _result_entry_t + { + _result_entry_t(): + _is_valid(false), + _is_null(true), + _value(false) {} - _result_entry_t(const char* data, size_t): - _is_valid(true), - _is_null(data == nullptr), - _value(_is_null ? false : (data[0] == 't' or data[0] == '1')) - {} + _result_entry_t(const char* data, size_t): + _is_valid(true), + _is_null(data == nullptr), + _value(_is_null ? false : (data[0] == 't' or data[0] == '1')) + {} - void assign(const char* data, size_t) - { - _is_valid = true; - _is_null = data == nullptr; - _value = _is_null ? false : (data[0] == 't' or data[0] == '1'); - } - - void validate() - { - _is_valid = true; - } - - void invalidate() - { - _is_valid = false; - _is_null = true; - _value = 0; - } - - bool is_null() const - { - if (connector_assert_result_validity_t::value) - assert(_is_valid); - else if (not _is_valid) - throw exception("accessing is_null in non-existing row"); - return _is_null; - } - - _cpp_value_type value() const - { - const bool null_value = _is_null and not NullIsTrivial and not connector_null_result_is_trivial_value_t::value; - if (connector_assert_result_validity_t::value) + void assign(const char* data, size_t) { - assert(_is_valid); - assert(not null_value); - } - else - { - if (not _is_valid) - throw exception("accessing value in non-existing row"); - if (null_value) - throw exception("accessing value of NULL field"); - } - return _value; - } - - operator _cpp_value_type() const { return value(); } - - template - void _bind(Target& target, size_t i) - { - target._bind_boolean_result(i, &_value, &_is_null); + _is_valid = true; + _is_null = data == nullptr; + _value = _is_null ? false : (data[0] == 't' or data[0] == '1'); } - private: - bool _is_valid; - bool _is_null; - signed char _value; - }; + void validate() + { + _is_valid = true; + } + + void invalidate() + { + _is_valid = false; + _is_null = true; + _value = 0; + } + + bool is_null() const + { + if (connector_assert_result_validity_t::value) + assert(_is_valid); + else if (not _is_valid) + throw exception("accessing is_null in non-existing row"); + return _is_null; + } + + _cpp_value_type value() const + { + const bool null_value = _is_null and not NullIsTrivial and not connector_null_result_is_trivial_value_t::value; + if (connector_assert_result_validity_t::value) + { + assert(_is_valid); + assert(not null_value); + } + else + { + if (not _is_valid) + throw exception("accessing value in non-existing row"); + if (null_value) + throw exception("accessing value of NULL field"); + } + return _value; + } + + operator _cpp_value_type() const { return value(); } + + template + void _bind(Target& target, size_t i) + { + target._bind_boolean_result(i, &_value, &_is_null); + } + + private: + bool _is_valid; + bool _is_null; + signed char _value; + }; template struct _is_valid_operand - { - static constexpr bool value = - is_expression_t::value // expressions are OK - and is_boolean_t::value // the correct value type is required, of course - ; - }; + { + static constexpr bool value = + is_expression_t::value // expressions are OK + and is_boolean_t::value // the correct value type is required, of course + ; + }; template struct expression_operators: public basic_expression_operators @@ -209,15 +209,15 @@ namespace sqlpp template struct column_operators - { - }; + { + }; }; template - inline std::ostream& operator<<(std::ostream& os, const boolean::_result_entry_t& e) - { - return os << e.value(); - } + inline std::ostream& operator<<(std::ostream& os, const boolean::_result_entry_t& e) + { + return os << e.value(); + } } using boolean = detail::boolean; diff --git a/include/sqlpp11/column.h b/include/sqlpp11/column.h index c69af308..31da39a2 100644 --- a/include/sqlpp11/column.h +++ b/include/sqlpp11/column.h @@ -42,8 +42,8 @@ namespace sqlpp { template - struct column_t: public ColumnSpec::_value_type::template expression_operators>, - public ColumnSpec::_value_type::template column_operators> + struct column_t: public ColumnSpec::_value_type::template expression_operators>, + public ColumnSpec::_value_type::template column_operators> { using _traits = make_traits; struct _recursive_traits @@ -103,17 +103,17 @@ namespace sqlpp } }; - template - struct serializer_t> - { - using T = column_t; + template + struct serializer_t> + { + using T = column_t; - static Context& _(const T& t, Context& context) - { - context << T::_table::_name_t::_get_name() << '.' << T::_name_t::_get_name(); - return context; - } - }; + static Context& _(const T& t, Context& context) + { + context << T::_table::_name_t::_get_name() << '.' << T::_name_t::_get_name(); + return context; + } + }; } diff --git a/include/sqlpp11/concat.h b/include/sqlpp11/concat.h index 766b4f0a..ecae74ce 100644 --- a/include/sqlpp11/concat.h +++ b/include/sqlpp11/concat.h @@ -33,52 +33,52 @@ namespace sqlpp { - // FIXME: Remove First, inherit from text_t - template - struct concat_t: public value_type_of::template expression_operators>, - public alias_operators> + // FIXME: Remove First, inherit from text_t + template + struct concat_t: public value_type_of::template expression_operators>, + public alias_operators> + { + using _traits = make_traits, ::sqlpp::tag::expression, ::sqlpp::tag::named_expression>; + using _recursive_traits = make_recursive_traits; + + static_assert(sizeof...(Args) > 0, "concat requires two arguments at least"); + static_assert(sqlpp::detail::all_t::value, is_text_t::value...>::value, "at least one non-text argument detected in concat()"); + struct _name_t { - using _traits = make_traits, ::sqlpp::tag::expression, ::sqlpp::tag::named_expression>; - using _recursive_traits = make_recursive_traits; - - static_assert(sizeof...(Args) > 0, "concat requires two arguments at least"); - static_assert(sqlpp::detail::all_t::value, is_text_t::value...>::value, "at least one non-text argument detected in concat()"); - struct _name_t - { - static constexpr const char* _get_name() { return "CONCAT"; } - template - struct _member_t - { - T concat; - }; - }; - - concat_t(First first, Args... args): - _args(first, args...) - {} - - concat_t(const concat_t&) = default; - concat_t(concat_t&&) = default; - concat_t& operator=(const concat_t&) = default; - concat_t& operator=(concat_t&&) = default; - ~concat_t() = default; - - std::tuple _args; + static constexpr const char* _get_name() { return "CONCAT"; } + template + struct _member_t + { + T concat; + }; }; - template - struct serializer_t> - { - using T = concat_t; + concat_t(First first, Args... args): + _args(first, args...) + {} - static Context& _(const T& t, Context& context) - { - context << "("; - interpret_tuple(t._args, "||", context); - context << ")"; - return context; - } - }; + concat_t(const concat_t&) = default; + concat_t(concat_t&&) = default; + concat_t& operator=(const concat_t&) = default; + concat_t& operator=(concat_t&&) = default; + ~concat_t() = default; + + std::tuple _args; + }; + + template + struct serializer_t> + { + using T = concat_t; + + static Context& _(const T& t, Context& context) + { + context << "("; + interpret_tuple(t._args, "||", context); + context << ")"; + return context; + } + }; } #endif diff --git a/include/sqlpp11/count.h b/include/sqlpp11/count.h index a29e1414..3e61bb53 100644 --- a/include/sqlpp11/count.h +++ b/include/sqlpp11/count.h @@ -32,59 +32,59 @@ namespace sqlpp { - template + template struct count_t: public sqlpp::detail::integral::template expression_operators>, - public alias_operators> + public alias_operators> + { + using _traits = make_traits<::sqlpp::detail::integral, ::sqlpp::tag::expression, ::sqlpp::tag::named_expression>; + using _recursive_traits = make_recursive_traits; + + static_assert(is_noop::value or std::is_same::value, "count() used with flag other than 'distinct'"); + static_assert(is_expression_t::value, "count() requires a sql expression as argument"); + + struct _name_t { - using _traits = make_traits<::sqlpp::detail::integral, ::sqlpp::tag::expression, ::sqlpp::tag::named_expression>; - using _recursive_traits = make_recursive_traits; - - static_assert(is_noop::value or std::is_same::value, "count() used with flag other than 'distinct'"); - static_assert(is_expression_t::value, "count() requires a sql expression as argument"); - - struct _name_t - { - static constexpr const char* _get_name() { return "COUNT"; } - template - struct _member_t - { - T count; - T& operator()() { return count; } - const T& operator()() const { return count; } - }; - }; - - count_t(const Expr expr): - _expr(expr) - {} - - count_t(const count_t&) = default; - count_t(count_t&&) = default; - count_t& operator=(const count_t&) = default; - count_t& operator=(count_t&&) = default; - ~count_t() = default; - - Expr _expr; + static constexpr const char* _get_name() { return "COUNT"; } + template + struct _member_t + { + T count; + T& operator()() { return count; } + const T& operator()() const { return count; } + }; }; - template - struct serializer_t> - { - using T = count_t; + count_t(const Expr expr): + _expr(expr) + {} - static Context& _(const T& t, Context& context) + count_t(const count_t&) = default; + count_t(count_t&&) = default; + count_t& operator=(const count_t&) = default; + count_t& operator=(count_t&&) = default; + ~count_t() = default; + + Expr _expr; + }; + + template + struct serializer_t> + { + using T = count_t; + + static Context& _(const T& t, Context& context) + { + context << "COUNT("; + if (std::is_same::value) { - context << "COUNT("; - if (std::is_same::value) - { - serialize(Flag(), context); - context << ' '; - } - serialize(t._expr, context); - context << ")"; - return context; + serialize(Flag(), context); + context << ' '; } - }; + serialize(t._expr, context); + context << ")"; + return context; + } + }; template auto count(T t) -> typename count_t> diff --git a/include/sqlpp11/default_value.h b/include/sqlpp11/default_value.h index d31aef95..bb8fce6d 100644 --- a/include/sqlpp11/default_value.h +++ b/include/sqlpp11/default_value.h @@ -39,17 +39,17 @@ namespace sqlpp static constexpr bool _is_trivial() { return false; } }; - template - struct serializer_t - { - using Operand = default_value_t; + template + struct serializer_t + { + using Operand = default_value_t; - static Context& _(const Operand& t, Context& context) - { - context << "DEFAULT"; - return context; - } - }; + static Context& _(const Operand& t, Context& context) + { + context << "DEFAULT"; + return context; + } + }; constexpr default_value_t default_value = {}; diff --git a/include/sqlpp11/exists.h b/include/sqlpp11/exists.h index 811c502d..ca993727 100644 --- a/include/sqlpp11/exists.h +++ b/include/sqlpp11/exists.h @@ -31,53 +31,53 @@ namespace sqlpp { - template + template struct exists_t: public boolean::template expression_operators>, - public alias_operators> + public alias_operators> + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits::value, "exists() requires a select expression as argument"); + + struct _name_t { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits::value, "exists() requires a select expression as argument"); - - struct _name_t - { - static constexpr const char* _get_name() { return "EXISTS"; } - template - struct _member_t - { - T exists; - T& operator()() { return exists; } - const T& operator()() const { return exists; } - }; - }; - - exists_t(Select select): - _select(select) - {} - - exists_t(const exists_t&) = default; - exists_t(exists_t&&) = default; - exists_t& operator=(const exists_t&) = default; - exists_t& operator=(exists_t&&) = default; - ~exists_t() = default; - - Select _select; + static constexpr const char* _get_name() { return "EXISTS"; } + template + struct _member_t + { + T exists; + T& operator()() { return exists; } + const T& operator()() const { return exists; } + }; }; - template - struct serializer_t> - { - using T = exists_t; + + static Context& _(const T& t, Context& context) + { + context << "EXISTS("; + serialize(t._select, context); + context << ")"; + return context; + } + }; template diff --git a/include/sqlpp11/expression.h b/include/sqlpp11/expression.h index ba192890..28a72bb3 100644 --- a/include/sqlpp11/expression.h +++ b/include/sqlpp11/expression.h @@ -37,9 +37,9 @@ namespace sqlpp { - template - struct binary_expression_t: public ::sqlpp::detail::boolean::template expression_operators>, - public alias_operators> + template + struct binary_expression_t: public ::sqlpp::detail::boolean::template expression_operators>, + public alias_operators> { using _traits = make_traits; using _recursive_traits = make_recursive_traits; @@ -59,32 +59,32 @@ namespace sqlpp maybe_tvin_t _rhs; }; - template - struct serializer_t> + template + struct serializer_t> + { + using T = equal_to_t; + + static Context& _(const T& t, Context& context) { - using T = equal_to_t; - - static Context& _(const T& t, Context& context) + context << "("; + serialize(t._lhs, context); + if (t._rhs._is_trivial()) { - context << "("; - serialize(t._lhs, context); - if (t._rhs._is_trivial()) - { - context << " IS NULL"; - } - else - { - context << "="; - serialize(t._rhs, context); - } - context << ")"; - return context; + context << " IS NULL"; } - }; + else + { + context << "="; + serialize(t._rhs, context); + } + context << ")"; + return context; + } + }; - template - struct binary_expression_t: public ::sqlpp::detail::boolean::template expression_operators>, - public alias_operators> + template + struct binary_expression_t: public ::sqlpp::detail::boolean::template expression_operators>, + public alias_operators> { using _traits = make_traits; using _recursive_traits = make_recursive_traits; @@ -104,32 +104,32 @@ namespace sqlpp maybe_tvin_t _rhs; }; - template - struct serializer_t> + template + struct serializer_t> + { + using T = not_equal_to_t; + + static Context& _(const T& t, Context& context) { - using T = not_equal_to_t; - - static Context& _(const T& t, Context& context) + context << "("; + serialize(t._lhs, context); + if (t._rhs._is_trivial()) { - context << "("; - serialize(t._lhs, context); - if (t._rhs._is_trivial()) - { - context << " IS NOT NULL"; - } - else - { - context << "!="; - serialize(t._rhs, context); - } - context << ")"; - return context; + context << " IS NOT NULL"; } - }; + else + { + context << "!="; + serialize(t._rhs, context); + } + context << ")"; + return context; + } + }; - template - struct unary_expression_t: public ::sqlpp::detail::boolean::template expression_operators>, - public alias_operators> + template + struct unary_expression_t: public ::sqlpp::detail::boolean::template expression_operators>, + public alias_operators> { using _traits = make_traits; using _recursive_traits = make_recursive_traits; @@ -147,93 +147,93 @@ namespace sqlpp Rhs _rhs; }; - template - struct serializer_t> - { - using T = logical_not_t; - - static Context& _(const T& t, Context& context) - { - context << "("; - context << "NOT "; - serialize(t._lhs, context); - context << ")"; - return context; - } - }; - - template - struct binary_expression_t: public value_type_of::template expression_operators>, - public alias_operators> + template + struct serializer_t> { - using _traits = make_traits, sqlpp::tag::expression>; - using _recursive_traits = make_recursive_traits; + using T = logical_not_t; - binary_expression_t(Lhs lhs, Rhs rhs): - _lhs(lhs), - _rhs(rhs) - {} - - binary_expression_t(const binary_expression_t&) = default; - binary_expression_t(binary_expression_t&&) = default; - binary_expression_t& operator=(const binary_expression_t&) = default; - binary_expression_t& operator=(binary_expression_t&&) = default; - ~binary_expression_t() = default; - - Lhs _lhs; - Rhs _rhs; + static Context& _(const T& t, Context& context) + { + context << "("; + context << "NOT "; + serialize(t._lhs, context); + context << ")"; + return context; + } }; - template - struct serializer_t> - { - using T = binary_expression_t; + template + struct binary_expression_t: public value_type_of::template expression_operators>, + public alias_operators> + { + using _traits = make_traits, sqlpp::tag::expression>; + using _recursive_traits = make_recursive_traits; - static Context& _(const T& t, Context& context) - { - context << "("; - serialize(t._lhs, context); - context << O::_name; - serialize(t._rhs, context); - context << ")"; - return context; - } - }; + binary_expression_t(Lhs lhs, Rhs rhs): + _lhs(lhs), + _rhs(rhs) + {} - template - struct unary_expression_t: public value_type_of::template expression_operators>, - public alias_operators> + binary_expression_t(const binary_expression_t&) = default; + binary_expression_t(binary_expression_t&&) = default; + binary_expression_t& operator=(const binary_expression_t&) = default; + binary_expression_t& operator=(binary_expression_t&&) = default; + ~binary_expression_t() = default; + + Lhs _lhs; + Rhs _rhs; + }; + + template + struct serializer_t> { - using _traits = make_traits, sqlpp::tag::expression>; - using _recursive_traits = make_recursive_traits; + using T = binary_expression_t; - unary_expression_t(Rhs rhs): - _rhs(rhs) - {} - - unary_expression_t(const unary_expression_t&) = default; - unary_expression_t(unary_expression_t&&) = default; - unary_expression_t& operator=(const unary_expression_t&) = default; - unary_expression_t& operator=(unary_expression_t&&) = default; - ~unary_expression_t() = default; - - Rhs _rhs; + static Context& _(const T& t, Context& context) + { + context << "("; + serialize(t._lhs, context); + context << O::_name; + serialize(t._rhs, context); + context << ")"; + return context; + } }; - template - struct serializer_t> - { - using T = unary_expression_t; + template + struct unary_expression_t: public value_type_of::template expression_operators>, + public alias_operators> + { + using _traits = make_traits, sqlpp::tag::expression>; + using _recursive_traits = make_recursive_traits; - static Context& _(const T& t, Context& context) - { - context << "("; - context << O::_name; - serialize(t._rhs, context); - context << ")"; - return context; - } - }; + unary_expression_t(Rhs rhs): + _rhs(rhs) + {} + + unary_expression_t(const unary_expression_t&) = default; + unary_expression_t(unary_expression_t&&) = default; + unary_expression_t& operator=(const unary_expression_t&) = default; + unary_expression_t& operator=(unary_expression_t&&) = default; + ~unary_expression_t() = default; + + Rhs _rhs; + }; + + template + struct serializer_t> + { + using T = unary_expression_t; + + static Context& _(const T& t, Context& context) + { + context << "("; + context << O::_name; + serialize(t._rhs, context); + context << ")"; + return context; + } + }; } #endif diff --git a/include/sqlpp11/expression_fwd.h b/include/sqlpp11/expression_fwd.h index ed542c7d..2a389e5b 100644 --- a/include/sqlpp11/expression_fwd.h +++ b/include/sqlpp11/expression_fwd.h @@ -36,160 +36,160 @@ namespace sqlpp struct floating_point; } - namespace op + namespace op + { + struct less { - struct less - { - using _traits = make_traits<::sqlpp::detail::boolean>; - static constexpr const char* _name = "<"; - }; + using _traits = make_traits<::sqlpp::detail::boolean>; + static constexpr const char* _name = "<"; + }; - struct less_equal - { - using _traits = make_traits<::sqlpp::detail::boolean>; - static constexpr const char* _name = "<="; - }; + struct less_equal + { + using _traits = make_traits<::sqlpp::detail::boolean>; + static constexpr const char* _name = "<="; + }; - struct equal_to - { - using _traits = make_traits<::sqlpp::detail::boolean>; - }; + struct equal_to + { + using _traits = make_traits<::sqlpp::detail::boolean>; + }; - struct not_equal_to - { - using _traits = make_traits<::sqlpp::detail::boolean>; - }; + struct not_equal_to + { + using _traits = make_traits<::sqlpp::detail::boolean>; + }; - struct greater_equal - { - using _traits = make_traits<::sqlpp::detail::boolean>; - static constexpr const char* _name = ">="; - }; + struct greater_equal + { + using _traits = make_traits<::sqlpp::detail::boolean>; + static constexpr const char* _name = ">="; + }; - struct greater - { - using _traits = make_traits<::sqlpp::detail::boolean>; - static constexpr const char* _name = ">"; - }; + struct greater + { + using _traits = make_traits<::sqlpp::detail::boolean>; + static constexpr const char* _name = ">"; + }; - struct logical_or - { - using _traits = make_traits<::sqlpp::detail::boolean>; - static constexpr const char* _name = " OR "; - }; + struct logical_or + { + using _traits = make_traits<::sqlpp::detail::boolean>; + static constexpr const char* _name = " OR "; + }; - struct logical_and - { - using _traits = make_traits<::sqlpp::detail::boolean>; - static constexpr const char* _name = " AND "; - }; + struct logical_and + { + using _traits = make_traits<::sqlpp::detail::boolean>; + static constexpr const char* _name = " AND "; + }; - struct logical_not - { - using _traits = make_traits<::sqlpp::detail::boolean>; - }; + struct logical_not + { + using _traits = make_traits<::sqlpp::detail::boolean>; + }; - template + template struct plus { using _traits = make_traits; static constexpr const char* _name = "+"; }; - template + template struct minus { using _traits = make_traits; static constexpr const char* _name = "-"; }; - template + template struct multiplies { using _traits = make_traits; static constexpr const char* _name = "*"; }; - struct divides - { - using _traits = make_traits<::sqlpp::detail::floating_point>; - static constexpr const char* _name = "/"; - }; + struct divides + { + using _traits = make_traits<::sqlpp::detail::floating_point>; + static constexpr const char* _name = "/"; + }; - struct modulus - { - using _traits = make_traits<::sqlpp::detail::integral>; - static constexpr const char* _name = "%"; - }; + struct modulus + { + using _traits = make_traits<::sqlpp::detail::integral>; + static constexpr const char* _name = "%"; + }; - template + template struct unary_minus { using _traits = make_traits; static constexpr const char* _name = "-"; }; - template + template struct unary_plus { using _traits = make_traits; static constexpr const char* _name = "+"; }; - } + } - template - struct binary_expression_t; + template + struct binary_expression_t; - template - struct unary_expression_t; + template + struct unary_expression_t; - template - using less_than_t = binary_expression_t; + template + using less_than_t = binary_expression_t; - template - using less_equal_t = binary_expression_t; + template + using less_equal_t = binary_expression_t; - template - using equal_to_t = binary_expression_t; + template + using equal_to_t = binary_expression_t; - template - using not_equal_to_t = binary_expression_t; + template + using not_equal_to_t = binary_expression_t; - template - using greater_than_t = binary_expression_t; + template + using greater_than_t = binary_expression_t; - template - using greater_equal_t = binary_expression_t; + template + using greater_equal_t = binary_expression_t; - template - using logical_and_t = binary_expression_t; + template + using logical_and_t = binary_expression_t; - template - using logical_or_t = binary_expression_t; + template + using logical_or_t = binary_expression_t; - template - using plus_t = binary_expression_t, Rhs>; + template + using plus_t = binary_expression_t, Rhs>; - template - using minus_t = binary_expression_t, Rhs>; + template + using minus_t = binary_expression_t, Rhs>; - template - using multiplies_t = binary_expression_t, Rhs>; + template + using multiplies_t = binary_expression_t, Rhs>; - template - using divides_t = binary_expression_t; + template + using divides_t = binary_expression_t; - template - using modulus_t = binary_expression_t; + template + using modulus_t = binary_expression_t; - template - using logical_not_t = unary_expression_t; + template + using logical_not_t = unary_expression_t; - template - using unary_plus_t = unary_expression_t, Rhs>; + template + using unary_plus_t = unary_expression_t, Rhs>; - template - using unary_minus_t = unary_expression_t, Rhs>; + template + using unary_minus_t = unary_expression_t, Rhs>; } diff --git a/include/sqlpp11/extra_tables.h b/include/sqlpp11/extra_tables.h index f660e92a..4b25a04f 100644 --- a/include/sqlpp11/extra_tables.h +++ b/include/sqlpp11/extra_tables.h @@ -33,86 +33,46 @@ namespace sqlpp { - template - struct extra_tables_data_t - { - extra_tables_data_t() - {} - - extra_tables_data_t(const extra_tables_data_t&) = default; - extra_tables_data_t(extra_tables_data_t&&) = default; - extra_tables_data_t& operator=(const extra_tables_data_t&) = default; - extra_tables_data_t& operator=(extra_tables_data_t&&) = default; - ~extra_tables_data_t() = default; - - }; - - // EXTRA_TABLES - template - struct extra_tables_t - { - using _traits = make_traits; - struct _recursive_traits - { - using _parameters = std::tuple<>; - using _required_tables = ::sqlpp::detail::type_set<>; - using _provided_tables = ::sqlpp::detail::type_set<>; - using _extra_tables = ::sqlpp::detail::type_set; - }; - - using _recursive_traits = make_recursive_traits; - - // FIXME: extra_tables must not require tables! - - static_assert(sizeof...(Tables), "at least one table or join argument required in extra_tables()"); - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in extra_tables()"); - static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a table or join in extra_tables()"); - - // Data - using _data_t = extra_tables_data_t; - - // Member implementation with data and methods - template - struct _impl_t - { - _data_t _data; - }; - - // Member template for adding the named member to a statement - template - struct _member_t - { - using _data_t = extra_tables_data_t; - - _impl_t extra_tables; - _impl_t& operator()() { return extra_tables; } - const _impl_t& operator()() const { return extra_tables; } - - template - static auto _get_member(T t) -> decltype(t.extra_tables) - { - return t.extra_tables; - } - }; - - // Additional methods for the statement - template - struct _methods_t - { - }; - }; - - // NO EXTRA TABLES YET - struct no_extra_tables_t + template + struct extra_tables_data_t { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; + extra_tables_data_t() + {} + + extra_tables_data_t(const extra_tables_data_t&) = default; + extra_tables_data_t(extra_tables_data_t&&) = default; + extra_tables_data_t& operator=(const extra_tables_data_t&) = default; + extra_tables_data_t& operator=(extra_tables_data_t&&) = default; + ~extra_tables_data_t() = default; + + }; + + // EXTRA_TABLES + template + struct extra_tables_t + { + using _traits = make_traits; + struct _recursive_traits + { + using _parameters = std::tuple<>; + using _required_tables = ::sqlpp::detail::type_set<>; + using _provided_tables = ::sqlpp::detail::type_set<>; + using _extra_tables = ::sqlpp::detail::type_set; + }; + + using _recursive_traits = make_recursive_traits; + + // FIXME: extra_tables must not require tables! + + static_assert(sizeof...(Tables), "at least one table or join argument required in extra_tables()"); + static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in extra_tables()"); + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a table or join in extra_tables()"); // Data - using _data_t = no_data_t; + using _data_t = extra_tables_data_t; // Member implementation with data and methods - template + template struct _impl_t { _data_t _data; @@ -122,46 +82,86 @@ namespace sqlpp template struct _member_t { - using _data_t = no_data_t; + using _data_t = extra_tables_data_t; - _impl_t no_extra_tables; - _impl_t& operator()() { return no_extra_tables; } - const _impl_t& operator()() const { return no_extra_tables; } + _impl_t extra_tables; + _impl_t& operator()() { return extra_tables; } + const _impl_t& operator()() const { return extra_tables; } template - static auto _get_member(T t) -> decltype(t.no_extra_tables) + static auto _get_member(T t) -> decltype(t.extra_tables) { - return t.no_extra_tables; + return t.extra_tables; } }; + // Additional methods for the statement template struct _methods_t { - template - using _new_statement_t = typename Policies::template _new_statement_t; - - template - auto extra_tables(Args...) - -> _new_statement_t> - { - return { *static_cast(this), extra_tables_data_t{} }; - } }; }; - // Interpreters - template - struct serializer_t> - { - using T = extra_tables_data_t; + // NO EXTRA TABLES YET + struct no_extra_tables_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; - static Context& _(const T& t, Context& context) - { - return context; - } + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; }; + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; + + _impl_t no_extra_tables; + _impl_t& operator()() { return no_extra_tables; } + const _impl_t& operator()() const { return no_extra_tables; } + + template + static auto _get_member(T t) -> decltype(t.no_extra_tables) + { + return t.no_extra_tables; + } + }; + + template + struct _methods_t + { + template + using _new_statement_t = typename Policies::template _new_statement_t; + + template + auto extra_tables(Args...) + -> _new_statement_t> + { + return { *static_cast(this), extra_tables_data_t{} }; + } + }; + }; + + // Interpreters + template + struct serializer_t> + { + using T = extra_tables_data_t; + + static Context& _(const T& t, Context& context) + { + return context; + } + }; + } #endif diff --git a/include/sqlpp11/field.h b/include/sqlpp11/field.h index 49a6abe6..1a5db815 100644 --- a/include/sqlpp11/field.h +++ b/include/sqlpp11/field.h @@ -31,40 +31,40 @@ namespace sqlpp { - template - struct field_t - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; + template + struct field_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; - using _name_t = NameType; - static constexpr bool _trivial_value_is_null = TrivialValueIsNull; - }; + using _name_t = NameType; + static constexpr bool _trivial_value_is_null = TrivialValueIsNull; + }; - template - struct multi_field_t - { - }; - - namespace detail + template + struct multi_field_t { - template - struct make_field_t_impl - { - using type = field_t, - trivial_value_is_null_t::value>; - }; - - template - struct make_field_t_impl> - { - using type = multi_field_t::type...>>; - }; - } + }; + namespace detail + { template - using make_field_t = typename detail::make_field_t_impl::type; + struct make_field_t_impl + { + using type = field_t, + trivial_value_is_null_t::value>; + }; + + template + struct make_field_t_impl> + { + using type = multi_field_t::type...>>; + }; + } + + template + using make_field_t = typename detail::make_field_t_impl::type; } diff --git a/include/sqlpp11/floating_point.h b/include/sqlpp11/floating_point.h index bbed7aac..0b9b57b6 100644 --- a/include/sqlpp11/floating_point.h +++ b/include/sqlpp11/floating_point.h @@ -43,7 +43,7 @@ namespace sqlpp { using _tag = ::sqlpp::tag::floating_point; using _cpp_value_type = double; - + struct _parameter_t { using _value_type = floating_point; @@ -51,12 +51,12 @@ namespace sqlpp _parameter_t(): _value(0), _is_null(true) - {} + {} _parameter_t(const _cpp_value_type& value): _value(value), _is_null(false) - {} + {} _parameter_t& operator=(const _cpp_value_type& value) { @@ -73,7 +73,7 @@ namespace sqlpp } bool is_null() const - { + { return _is_null; } @@ -96,90 +96,90 @@ namespace sqlpp }; template - struct _result_entry_t - { - using _value_type = integral; + struct _result_entry_t + { + using _value_type = integral; - _result_entry_t(): - _is_valid(false), - _is_null(true), - _value(0) + _result_entry_t(): + _is_valid(false), + _is_null(true), + _value(0) {} - _result_entry_t(const char* data, size_t): - _is_valid(true), - _is_null(data == nullptr), - _value(_is_null ? 0 : std::strtoll(data, nullptr, 10)) - {} + _result_entry_t(const char* data, size_t): + _is_valid(true), + _is_null(data == nullptr), + _value(_is_null ? 0 : std::strtoll(data, nullptr, 10)) + {} - void assign(const char* data, size_t) - { - _is_valid = true; - _is_null = data == nullptr; - _value = _is_null ? 0 : std::strtoll(data, nullptr, 10); - } - - void validate() - { - _is_valid = true; - } - - void invalidate() - { - _is_valid = false; - _is_null = true; - _value = 0; - } - - bool is_null() const - { - if (connector_assert_result_validity_t::value) - assert(_is_valid); - else if (not _is_valid) - throw exception("accessing is_null in non-existing row"); - return _is_null; - } - - _cpp_value_type value() const - { - const bool null_value = _is_null and not NullIsTrivial and not connector_null_result_is_trivial_value_t::value; - if (connector_assert_result_validity_t::value) + void assign(const char* data, size_t) { - assert(_is_valid); - assert(not null_value); - } - else - { - if (not _is_valid) - throw exception("accessing value in non-existing row"); - if (null_value) - throw exception("accessing value of NULL field"); - } - return _value; - } - - operator _cpp_value_type() const { return value(); } - - template - void _bind(Target& target, size_t i) - { - target._bind_floating_point_result(i, &_value, &_is_null); + _is_valid = true; + _is_null = data == nullptr; + _value = _is_null ? 0 : std::strtoll(data, nullptr, 10); } - private: - bool _is_valid; - bool _is_null; - _cpp_value_type _value; - }; + void validate() + { + _is_valid = true; + } + + void invalidate() + { + _is_valid = false; + _is_null = true; + _value = 0; + } + + bool is_null() const + { + if (connector_assert_result_validity_t::value) + assert(_is_valid); + else if (not _is_valid) + throw exception("accessing is_null in non-existing row"); + return _is_null; + } + + _cpp_value_type value() const + { + const bool null_value = _is_null and not NullIsTrivial and not connector_null_result_is_trivial_value_t::value; + if (connector_assert_result_validity_t::value) + { + assert(_is_valid); + assert(not null_value); + } + else + { + if (not _is_valid) + throw exception("accessing value in non-existing row"); + if (null_value) + throw exception("accessing value of NULL field"); + } + return _value; + } + + operator _cpp_value_type() const { return value(); } + + template + void _bind(Target& target, size_t i) + { + target._bind_floating_point_result(i, &_value, &_is_null); + } + + private: + bool _is_valid; + bool _is_null; + _cpp_value_type _value; + }; template struct _is_valid_operand - { - static constexpr bool value = - is_expression_t::value // expressions are OK - and is_numeric_t::value // the correct value type is required, of course - ; - }; + { + static constexpr bool value = + is_expression_t::value // expressions are OK + and is_numeric_t::value // the correct value type is required, of course + ; + }; template struct expression_operators: public basic_expression_operators @@ -231,50 +231,50 @@ namespace sqlpp template struct column_operators - { - template - auto operator +=(T t) const -> assignment_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + { + template + auto operator +=(T t) const -> assignment_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - return { *static_cast(this), { *static_cast(this), rhs{t} } }; - } + return { *static_cast(this), { *static_cast(this), rhs{t} } }; + } - template - auto operator -=(T t) const -> assignment_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + template + auto operator -=(T t) const -> assignment_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - return { *static_cast(this), { *static_cast(this), rhs{t} } }; - } + return { *static_cast(this), { *static_cast(this), rhs{t} } }; + } - template - auto operator /=(T t) const -> assignment_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + template + auto operator /=(T t) const -> assignment_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - return { *static_cast(this), { *static_cast(this), rhs{t} } }; - } + return { *static_cast(this), { *static_cast(this), rhs{t} } }; + } - template - auto operator *=(T t) const -> assignment_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + template + auto operator *=(T t) const -> assignment_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - return { *static_cast(this), { *static_cast(this), rhs{t} } }; - } - }; + return { *static_cast(this), { *static_cast(this), rhs{t} } }; + } + }; }; template - inline std::ostream& operator<<(std::ostream& os, const floating_point::_result_entry_t& e) - { - return os << e.value(); - } + inline std::ostream& operator<<(std::ostream& os, const floating_point::_result_entry_t& e) + { + return os << e.value(); + } } using floating_point = detail::floating_point; diff --git a/include/sqlpp11/from.h b/include/sqlpp11/from.h index efb8cedf..74babb1e 100644 --- a/include/sqlpp11/from.h +++ b/include/sqlpp11/from.h @@ -35,8 +35,8 @@ namespace sqlpp { - // FROM DATA - template + // FROM DATA + template struct from_data_t { from_data_t(Tables... tables): @@ -53,93 +53,54 @@ namespace sqlpp interpretable_list_t _dynamic_tables; }; - // FROM - template - struct from_t - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits; - - using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - - static_assert(_is_dynamic::value or sizeof...(Tables), "at least one table or join argument required in from()"); - - // FIXME: Joins contain two tables. This is not being dealt with at the moment when looking at duplicates, for instance - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in from()"); - - static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a table or join in from()"); - - static_assert(required_tables_of::size::value == 0, "at least one table depends on another table"); - - // Data - using _data_t = from_data_t; - - // Member implementation with data and methods - template - struct _impl_t - { - template - void add(Table table) - { - static_assert(_is_dynamic::value, "from::add() must not be called for static from()"); - static_assert(is_table_t
::value, "invalid table argument in from::add()"); -#warning need to check if table is already known - - using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_table_t
::value>; - - _add_impl(table, ok()); // dispatch to prevent compile messages after the static_assert - } - - private: - template - void _add_impl(Table table, const std::true_type&) - { - return _data._dynamic_tables.emplace_back(table); - } - - template - void _add_impl(Table table, const std::false_type&); - - public: - _data_t _data; - }; - - // Member template for adding the named member to a statement - template - struct _member_t - { - using _data_t = from_data_t; - - _impl_t from; - _impl_t& operator()() { return from; } - const _impl_t& operator()() const { return from; } - - template - static auto _get_member(T t) -> decltype(t.from) - { - return t.from; - } - }; - - // Additional methods for the statement - template - struct _methods_t - { - }; - }; - - struct no_from_t + // FROM + template + struct from_t { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + + using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; + + static_assert(_is_dynamic::value or sizeof...(Tables), "at least one table or join argument required in from()"); + + // FIXME: Joins contain two tables. This is not being dealt with at the moment when looking at duplicates, for instance + static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in from()"); + + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a table or join in from()"); + + static_assert(required_tables_of::size::value == 0, "at least one table depends on another table"); // Data - using _data_t = no_data_t; + using _data_t = from_data_t; // Member implementation with data and methods template struct _impl_t { + template + void add(Table table) + { + static_assert(_is_dynamic::value, "from::add() must not be called for static from()"); + static_assert(is_table_t
::value, "invalid table argument in from::add()"); +#warning need to check if table is already known + + using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_table_t
::value>; + + _add_impl(table, ok()); // dispatch to prevent compile messages after the static_assert + } + + private: + template + void _add_impl(Table table, const std::true_type&) + { + return _data._dynamic_tables.emplace_back(table); + } + + template + void _add_impl(Table table, const std::false_type&); + + public: _data_t _data; }; @@ -147,16 +108,16 @@ namespace sqlpp template struct _member_t { - using _data_t = no_data_t; + using _data_t = from_data_t; - _impl_t no_from; - _impl_t& operator()() { return no_from; } - const _impl_t& operator()() const { return no_from; } + _impl_t from; + _impl_t& operator()() { return from; } + const _impl_t& operator()() const { return from; } template - static auto _get_member(T t) -> decltype(t.no_from) + static auto _get_member(T t) -> decltype(t.from) { - return t.no_from; + return t.from; } }; @@ -164,46 +125,85 @@ namespace sqlpp template struct _methods_t { - using _database_t = typename Policies::_database_t; - template - using _new_statement_t = typename Policies::template _new_statement_t; - - template - auto from(Args... args) - -> _new_statement_t> - { - return { *static_cast(this), from_data_t{args...} }; - } - - template - auto dynamic_from(Args... args) - -> _new_statement_t> - { - static_assert(not std::is_same<_database_t, void>::value, "dynamic_from must not be called in a static statement"); - return { *static_cast(this), from_data_t<_database_t, Args...>{args...} }; - } }; }; - // Interpreters - template - struct serializer_t> - { - using T = from_data_t; + struct no_from_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; - static Context& _(const T& t, Context& context) - { - if (sizeof...(Tables) == 0 and t._dynamic_tables.empty()) - return context; - context << " FROM "; - interpret_tuple(t._tables, ',', context); - if (sizeof...(Tables) and not t._dynamic_tables.empty()) - context << ','; - interpret_list(t._dynamic_tables, ',', context); - return context; - } + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; }; + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; + + _impl_t no_from; + _impl_t& operator()() { return no_from; } + const _impl_t& operator()() const { return no_from; } + + template + static auto _get_member(T t) -> decltype(t.no_from) + { + return t.no_from; + } + }; + + // Additional methods for the statement + template + struct _methods_t + { + using _database_t = typename Policies::_database_t; + template + using _new_statement_t = typename Policies::template _new_statement_t; + + template + auto from(Args... args) + -> _new_statement_t> + { + return { *static_cast(this), from_data_t{args...} }; + } + + template + auto dynamic_from(Args... args) + -> _new_statement_t> + { + static_assert(not std::is_same<_database_t, void>::value, "dynamic_from must not be called in a static statement"); + return { *static_cast(this), from_data_t<_database_t, Args...>{args...} }; + } + }; + }; + + // Interpreters + template + struct serializer_t> + { + using T = from_data_t; + + static Context& _(const T& t, Context& context) + { + if (sizeof...(Tables) == 0 and t._dynamic_tables.empty()) + return context; + context << " FROM "; + interpret_tuple(t._tables, ',', context); + if (sizeof...(Tables) and not t._dynamic_tables.empty()) + context << ','; + interpret_list(t._dynamic_tables, ',', context); + return context; + } + }; + } #endif diff --git a/include/sqlpp11/functions.h b/include/sqlpp11/functions.h index 3896c23e..a01aa323 100644 --- a/include/sqlpp11/functions.h +++ b/include/sqlpp11/functions.h @@ -55,8 +55,8 @@ namespace sqlpp } template // Csaba Csoma suggests: unsafe_sql instead of verbatim - struct verbatim_t: public ValueType::template expression_operators>, - public alias_operators> + struct verbatim_t: public ValueType::template expression_operators>, + public alias_operators> { using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; @@ -71,17 +71,17 @@ namespace sqlpp std::string _verbatim; }; - template - struct serializer_t> - { - using T = verbatim_t; + template + struct serializer_t> + { + using T = verbatim_t; - static Context& _(const T& t, Context& context) - { - context << t._verbatim; - return context; - } - }; + static Context& _(const T& t, Context& context) + { + context << t._verbatim; + return context; + } + }; template auto verbatim(StringType s) -> verbatim_t @@ -119,26 +119,26 @@ namespace sqlpp _container_t _container; }; - template - struct serializer_t> + template + struct serializer_t> + { + using T = value_list_t; + + static Context& _(const T& t, Context& context) { - using T = value_list_t; - - static Context& _(const T& t, Context& context) + bool first = true; + for (const auto& entry: t._container) { - bool first = true; - for (const auto& entry: t._container) - { - if (first) - first = false; - else - context << ','; + if (first) + first = false; + else + context << ','; - serialize(value(entry), context); - } - return context; + serialize(value(entry), context); } - }; + return context; + } + }; template auto value_list(Container c) -> value_list_t diff --git a/include/sqlpp11/group_by.h b/include/sqlpp11/group_by.h index 0b059201..8e369b0c 100644 --- a/include/sqlpp11/group_by.h +++ b/include/sqlpp11/group_by.h @@ -37,113 +37,74 @@ namespace sqlpp { - // GROUP BY DATA - template - struct group_by_data_t - { - group_by_data_t(Expressions... expressions): - _expressions(expressions...) - {} - - group_by_data_t(const group_by_data_t&) = default; - group_by_data_t(group_by_data_t&&) = default; - group_by_data_t& operator=(const group_by_data_t&) = default; - group_by_data_t& operator=(group_by_data_t&&) = default; - ~group_by_data_t() = default; - - std::tuple _expressions; - interpretable_list_t _dynamic_expressions; - }; - - // GROUP BY - template - struct group_by_t - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits; - - using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - - static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression (e.g. a column) required in group_by()"); - - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in group_by()"); - - static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an expression in group_by()"); - - // Data - using _data_t = group_by_data_t; - - // Member implementation with data and methods - template - struct _impl_t - { - template - void add_ntc(Expression expression) - { - add(expression); - } - - template - void add(Expression expression) - { - static_assert(_is_dynamic::value, "add() must not be called for static group_by"); - static_assert(is_expression_t::value, "invalid expression argument in group_by::add()"); - static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in group_by::add()"); - - using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; - - _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert - } - - private: - template - void _add_impl(Expression expression, const std::true_type&) - { - return _data._dynamic_expressions.emplace_back(expression); - } - - template - void _add_impl(Expression expression, const std::false_type&); - public: - _data_t _data; - }; - - // Member template for adding the named member to a statement - template - struct _member_t - { - using _data_t = group_by_data_t; - - _impl_t group_by; - _impl_t& operator()() { return group_by; } - const _impl_t& operator()() const { return group_by; } - - template - static auto _get_member(T t) -> decltype(t.group_by) - { - return t.group_by; - } - }; - - template - struct _methods_t - { - }; - }; - - // NO GROUP BY YET - struct no_group_by_t + // GROUP BY DATA + template + struct group_by_data_t { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; + group_by_data_t(Expressions... expressions): + _expressions(expressions...) + {} + + group_by_data_t(const group_by_data_t&) = default; + group_by_data_t(group_by_data_t&&) = default; + group_by_data_t& operator=(const group_by_data_t&) = default; + group_by_data_t& operator=(group_by_data_t&&) = default; + ~group_by_data_t() = default; + + std::tuple _expressions; + interpretable_list_t _dynamic_expressions; + }; + + // GROUP BY + template + struct group_by_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + + using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; + + static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression (e.g. a column) required in group_by()"); + + static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in group_by()"); + + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an expression in group_by()"); // Data - using _data_t = no_data_t; + using _data_t = group_by_data_t; // Member implementation with data and methods template struct _impl_t { + template + void add_ntc(Expression expression) + { + add(expression); + } + + template + void add(Expression expression) + { + static_assert(_is_dynamic::value, "add() must not be called for static group_by"); + static_assert(is_expression_t::value, "invalid expression argument in group_by::add()"); + static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in group_by::add()"); + + using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; + + _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert + } + + private: + template + void _add_impl(Expression expression, const std::true_type&) + { + return _data._dynamic_expressions.emplace_back(expression); + } + + template + void _add_impl(Expression expression, const std::false_type&); + public: _data_t _data; }; @@ -151,61 +112,100 @@ namespace sqlpp template struct _member_t { - using _data_t = no_data_t; + using _data_t = group_by_data_t; - _impl_t no_group_by; - _impl_t& operator()() { return no_group_by; } - const _impl_t& operator()() const { return no_group_by; } + _impl_t group_by; + _impl_t& operator()() { return group_by; } + const _impl_t& operator()() const { return group_by; } template - static auto _get_member(T t) -> decltype(t.no_group_by) + static auto _get_member(T t) -> decltype(t.group_by) { - return t.no_group_by; + return t.group_by; } }; template struct _methods_t { - using _database_t = typename Policies::_database_t; - template - using _new_statement_t = typename Policies::template _new_statement_t; - - template - auto group_by(Args... args) - -> _new_statement_t> - { - return { *static_cast(this), group_by_data_t{args...} }; - } - - template - auto dynamic_group_by(Args... args) - -> _new_statement_t> - { - static_assert(not std::is_same<_database_t, void>::value, "dynamic_group_by must not be called in a static statement"); - return { *static_cast(this), group_by_data_t<_database_t, Args...>{args...} }; - } }; }; - // Interpreters - template - struct serializer_t> - { - using T = group_by_data_t; + // NO GROUP BY YET + struct no_group_by_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; - static Context& _(const T& t, Context& context) - { - if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty()) - return context; - context << " GROUP BY "; - interpret_tuple(t._expressions, ',', context); - if (sizeof...(Expressions) and not t._dynamic_expressions.empty()) - context << ','; - interpret_list(t._dynamic_expressions, ',', context); - return context; - } + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; + + _impl_t no_group_by; + _impl_t& operator()() { return no_group_by; } + const _impl_t& operator()() const { return no_group_by; } + + template + static auto _get_member(T t) -> decltype(t.no_group_by) + { + return t.no_group_by; + } + }; + + template + struct _methods_t + { + using _database_t = typename Policies::_database_t; + template + using _new_statement_t = typename Policies::template _new_statement_t; + + template + auto group_by(Args... args) + -> _new_statement_t> + { + return { *static_cast(this), group_by_data_t{args...} }; + } + + template + auto dynamic_group_by(Args... args) + -> _new_statement_t> + { + static_assert(not std::is_same<_database_t, void>::value, "dynamic_group_by must not be called in a static statement"); + return { *static_cast(this), group_by_data_t<_database_t, Args...>{args...} }; + } + }; + }; + + // Interpreters + template + struct serializer_t> + { + using T = group_by_data_t; + + static Context& _(const T& t, Context& context) + { + if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty()) + return context; + context << " GROUP BY "; + interpret_tuple(t._expressions, ',', context); + if (sizeof...(Expressions) and not t._dynamic_expressions.empty()) + context << ','; + interpret_list(t._dynamic_expressions, ',', context); + return context; + } + }; } #endif diff --git a/include/sqlpp11/having.h b/include/sqlpp11/having.h index 483b45ae..d50f5600 100644 --- a/include/sqlpp11/having.h +++ b/include/sqlpp11/having.h @@ -36,112 +36,72 @@ namespace sqlpp { - // HAVING DATA - template - struct having_data_t - { - having_data_t(Expressions... expressions): - _expressions(expressions...) - {} - - having_data_t(const having_data_t&) = default; - having_data_t(having_data_t&&) = default; - having_data_t& operator=(const having_data_t&) = default; - having_data_t& operator=(having_data_t&&) = default; - ~having_data_t() = default; - - std::tuple _expressions; - interpretable_list_t _dynamic_expressions; - }; - - // HAVING - template - struct having_t - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits; - - using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - - static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression argument required in having()"); - static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an expression in having()"); - - // Data - using _data_t = having_data_t; - - // Member implementation with data and methods - template - struct _impl_t - { - template - void add_ntc(Expression expression) - { - add(expression); - } - - template - void add(Expression expression) - { - static_assert(_is_dynamic::value, "having::add() can only be called for dynamic_having"); - static_assert(is_expression_t::value, "invalid expression argument in having::add()"); - static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in having::add()"); - - using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; - - _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert - } - - private: - template - void _add_impl(Expression expression, const std::true_type&) - { - return _data._dynamic_expressions.emplace_back(expression); - } - - template - void _add_impl(Expression expression, const std::false_type&); - - public: - _data_t _data; - }; - - // Member template for adding the named member to a statement - template - struct _member_t - { - using _data_t = having_data_t; - - _impl_t having; - _impl_t& operator()() { return having; } - const _impl_t& operator()() const { return having; } - - template - static auto _get_member(T t) -> decltype(t.having) - { - return t.having; - } - }; - - // Additional methods for the statement - template - struct _methods_t - { - }; - }; - - // NO HAVING YET - struct no_having_t + // HAVING DATA + template + struct having_data_t { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; + having_data_t(Expressions... expressions): + _expressions(expressions...) + {} + + having_data_t(const having_data_t&) = default; + having_data_t(having_data_t&&) = default; + having_data_t& operator=(const having_data_t&) = default; + having_data_t& operator=(having_data_t&&) = default; + ~having_data_t() = default; + + std::tuple _expressions; + interpretable_list_t _dynamic_expressions; + }; + + // HAVING + template + struct having_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + + using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; + + static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression argument required in having()"); + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an expression in having()"); // Data - using _data_t = no_data_t; + using _data_t = having_data_t; // Member implementation with data and methods - template + template struct _impl_t { + template + void add_ntc(Expression expression) + { + add(expression); + } + + template + void add(Expression expression) + { + static_assert(_is_dynamic::value, "having::add() can only be called for dynamic_having"); + static_assert(is_expression_t::value, "invalid expression argument in having::add()"); + static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in having::add()"); + + using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; + + _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert + } + + private: + template + void _add_impl(Expression expression, const std::true_type&) + { + return _data._dynamic_expressions.emplace_back(expression); + } + + template + void _add_impl(Expression expression, const std::false_type&); + + public: _data_t _data; }; @@ -149,61 +109,101 @@ namespace sqlpp template struct _member_t { - using _data_t = no_data_t; + using _data_t = having_data_t; - _impl_t no_having; - _impl_t& operator()() { return no_having; } - const _impl_t& operator()() const { return no_having; } + _impl_t having; + _impl_t& operator()() { return having; } + const _impl_t& operator()() const { return having; } template - static auto _get_member(T t) -> decltype(t.no_having) + static auto _get_member(T t) -> decltype(t.having) { - return t.no_having; + return t.having; } }; + // Additional methods for the statement template struct _methods_t { - using _database_t = typename Policies::_database_t; - template - using _new_statement_t = typename Policies::template _new_statement_t; - - template - auto having(Args... args) - -> _new_statement_t> - { - return { *static_cast(this), having_data_t{args...} }; - } - - template - auto dynamic_having(Args... args) - -> _new_statement_t> - { - static_assert(not std::is_same<_database_t, void>::value, "dynamic_having must not be called in a static statement"); - return { *static_cast(this), having_data_t<_database_t, Args...>{args...} }; - } }; }; - // Interpreters - template - struct serializer_t> - { - using T = having_data_t; + // NO HAVING YET + struct no_having_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; - static Context& _(const T& t, Context& context) - { - if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty()) - return context; - context << " HAVING "; - interpret_tuple(t._expressions, " AND ", context); - if (sizeof...(Expressions) and not t._dynamic_expressions.empty()) - context << " AND "; - interpret_list(t._dynamic_expressions, " AND ", context); - return context; - } + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; + + _impl_t no_having; + _impl_t& operator()() { return no_having; } + const _impl_t& operator()() const { return no_having; } + + template + static auto _get_member(T t) -> decltype(t.no_having) + { + return t.no_having; + } + }; + + template + struct _methods_t + { + using _database_t = typename Policies::_database_t; + template + using _new_statement_t = typename Policies::template _new_statement_t; + + template + auto having(Args... args) + -> _new_statement_t> + { + return { *static_cast(this), having_data_t{args...} }; + } + + template + auto dynamic_having(Args... args) + -> _new_statement_t> + { + static_assert(not std::is_same<_database_t, void>::value, "dynamic_having must not be called in a static statement"); + return { *static_cast(this), having_data_t<_database_t, Args...>{args...} }; + } + }; + }; + + // Interpreters + template + struct serializer_t> + { + using T = having_data_t; + + static Context& _(const T& t, Context& context) + { + if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty()) + return context; + context << " HAVING "; + interpret_tuple(t._expressions, " AND ", context); + if (sizeof...(Expressions) and not t._dynamic_expressions.empty()) + context << " AND "; + interpret_list(t._dynamic_expressions, " AND ", context); + return context; + } + }; } #endif diff --git a/include/sqlpp11/in.h b/include/sqlpp11/in.h index 76b9ed77..5ec661b4 100644 --- a/include/sqlpp11/in.h +++ b/include/sqlpp11/in.h @@ -34,55 +34,55 @@ namespace sqlpp { - template - struct in_t: public boolean::template expression_operators>, - public alias_operators> + template + struct in_t: public boolean::template expression_operators>, + public alias_operators> + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + + static constexpr bool _inverted = not NotInverted; + static_assert(sizeof...(Args) > 0, "in() requires at least one argument"); + + struct _name_t { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits; - - static constexpr bool _inverted = not NotInverted; - static_assert(sizeof...(Args) > 0, "in() requires at least one argument"); - - struct _name_t - { - static constexpr const char* _get_name() { return _inverted ? "NOT IN" : "IN"; } - template - struct _member_t - { - T in; - }; - }; - - in_t(Operand operand, Args... args): - _operand(operand), - _args(args...) - {} - - in_t(const in_t&) = default; - in_t(in_t&&) = default; - in_t& operator=(const in_t&) = default; - in_t& operator=(in_t&&) = default; - ~in_t() = default; - - Operand _operand; - std::tuple _args; + static constexpr const char* _get_name() { return _inverted ? "NOT IN" : "IN"; } + template + struct _member_t + { + T in; + }; }; - template - struct serializer_t> - { - using T = in_t; + in_t(Operand operand, Args... args): + _operand(operand), + _args(args...) + {} - static Context& _(const T& t, Context& context) - { - serialize(t._operand, context); - context << (t._inverted ? " NOT IN(" : " IN("); - interpret_tuple(t._args, ',', context); - context << ')'; - return context; - } - }; + in_t(const in_t&) = default; + in_t(in_t&&) = default; + in_t& operator=(const in_t&) = default; + in_t& operator=(in_t&&) = default; + ~in_t() = default; + + Operand _operand; + std::tuple _args; + }; + + template + struct serializer_t> + { + using T = in_t; + + static Context& _(const T& t, Context& context) + { + serialize(t._operand, context); + context << (t._inverted ? " NOT IN(" : " IN("); + interpret_tuple(t._args, ',', context); + context << ')'; + return context; + } + }; } diff --git a/include/sqlpp11/in_fwd.h b/include/sqlpp11/in_fwd.h index 9b2e06a4..3b464307 100644 --- a/include/sqlpp11/in_fwd.h +++ b/include/sqlpp11/in_fwd.h @@ -29,7 +29,7 @@ namespace sqlpp { - template + template struct in_t; } diff --git a/include/sqlpp11/insert.h b/include/sqlpp11/insert.h index eeb08f4b..491d9a8c 100644 --- a/include/sqlpp11/insert.h +++ b/include/sqlpp11/insert.h @@ -43,24 +43,24 @@ namespace sqlpp struct insert_t: public statement_name_t {}; - template - struct serializer_t + template + struct serializer_t + { + using T = insert_name_t; + + static Context& _(const T& t, Context& context) { - using T = insert_name_t; + context << "INSERT "; - static Context& _(const T& t, Context& context) - { - context << "INSERT "; - - return context; - } - }; + return context; + } + }; template using blank_insert_t = statement_t; + insert_t, + no_into_t, + no_insert_value_list_t>; auto insert() -> blank_insert_t diff --git a/include/sqlpp11/insert_value.h b/include/sqlpp11/insert_value.h index d9c0f4e1..1be64b10 100644 --- a/include/sqlpp11/insert_value.h +++ b/include/sqlpp11/insert_value.h @@ -36,85 +36,85 @@ namespace sqlpp { - namespace detail + namespace detail + { + template + struct type_if + { + using type = Type; + }; + + template + struct type_if + { + struct type + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; + }; + }; + } + + template + struct insert_value_t { - template - struct type_if - { - using type = Type; - }; + using _is_insert_value = std::true_type; + using _pure_value_t = typename value_type_of::_cpp_value_type; + using _wrapped_value_t = typename wrap_operand<_pure_value_t>::type; + using _tvin_t = typename detail::type_if, can_be_null_t::value>::type; // static asserts and SFINAE do not work together + using _null_t = typename detail::type_if::value>::type; // static asserts and SFINAE do not work together - template - struct type_if - { - struct type - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; - }; - }; - } + insert_value_t(assignment_t assignment): + _is_null(false), + _is_default(false), + _value(assignment._rhs) + {} - template - struct insert_value_t + insert_value_t(assignment_t assignment): + _is_null(assignment._rhs._is_trivial()), + _is_default(false), + _value(assignment._rhs._value) + {} + + insert_value_t(const assignment_t&): + _is_null(true), + _is_default(false), + _value() + {} + + insert_value_t(const assignment_t&): + _is_null(false), + _is_default(true), + _value() + {} + + insert_value_t(const insert_value_t&) = default; + insert_value_t(insert_value_t&&) = default; + insert_value_t& operator=(const insert_value_t&) = default; + insert_value_t& operator=(insert_value_t&&) = default; + ~insert_value_t() = default; + + bool _is_null; + bool _is_default; + _wrapped_value_t _value; + }; + + template + struct serializer_t> + { + using T = insert_value_t; + + static Context& _(const T& t, Context& context) { - using _is_insert_value = std::true_type; - using _pure_value_t = typename value_type_of::_cpp_value_type; - using _wrapped_value_t = typename wrap_operand<_pure_value_t>::type; - using _tvin_t = typename detail::type_if, can_be_null_t::value>::type; // static asserts and SFINAE do not work together - using _null_t = typename detail::type_if::value>::type; // static asserts and SFINAE do not work together - - insert_value_t(assignment_t assignment): - _is_null(false), - _is_default(false), - _value(assignment._rhs) - {} - - insert_value_t(assignment_t assignment): - _is_null(assignment._rhs._is_trivial()), - _is_default(false), - _value(assignment._rhs._value) - {} - - insert_value_t(const assignment_t&): - _is_null(true), - _is_default(false), - _value() - {} - - insert_value_t(const assignment_t&): - _is_null(false), - _is_default(true), - _value() - {} - - insert_value_t(const insert_value_t&) = default; - insert_value_t(insert_value_t&&) = default; - insert_value_t& operator=(const insert_value_t&) = default; - insert_value_t& operator=(insert_value_t&&) = default; - ~insert_value_t() = default; - - bool _is_null; - bool _is_default; - _wrapped_value_t _value; - }; - - template - struct serializer_t> - { - using T = insert_value_t; - - static Context& _(const T& t, Context& context) - { - if (t._is_null) - context << "NULL"; - else if (t._is_default) - context << "DEFAULT"; - else - serialize(t._value, context); - return context; - } - }; + if (t._is_null) + context << "NULL"; + else if (t._is_default) + context << "DEFAULT"; + else + serialize(t._value, context); + return context; + } + }; } diff --git a/include/sqlpp11/insert_value_list.h b/include/sqlpp11/insert_value_list.h index ea3676f3..831a6752 100644 --- a/include/sqlpp11/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -37,288 +37,141 @@ namespace sqlpp { - struct insert_default_values_data_t - {}; + struct insert_default_values_data_t + {}; - // COLUMN AND VALUE LIST - struct insert_default_values_t + // COLUMN AND VALUE LIST + struct insert_default_values_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; + + // Data + using _data_t = insert_default_values_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = insert_default_values_data_t; + + _impl_t default_values; + _impl_t& operator()() { return default_values; } + const _impl_t& operator()() const { return default_values; } + + template + static auto _get_member(T t) -> decltype(t.default_values) + { + return t.default_values; + } + }; + + template + struct _methods_t + {}; + }; + + template + struct insert_list_data_t { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; - - // Data - using _data_t = insert_default_values_data_t; - - // Member implementation with data and methods - template - struct _impl_t - { - _data_t _data; - }; - - // Member template for adding the named member to a statement - template - struct _member_t - { - using _data_t = insert_default_values_data_t; - - _impl_t default_values; - _impl_t& operator()() { return default_values; } - const _impl_t& operator()() const { return default_values; } - - template - static auto _get_member(T t) -> decltype(t.default_values) - { - return t.default_values; - } - }; - - template - struct _methods_t - {}; - }; - - template - struct insert_list_data_t - { - insert_list_data_t(Assignments... assignments): - _assignments(assignments...), - _columns({assignments._lhs}...), - _values(assignments._rhs...) - {} - - insert_list_data_t(const insert_list_data_t&) = default; - insert_list_data_t(insert_list_data_t&&) = default; - insert_list_data_t& operator=(const insert_list_data_t&) = default; - insert_list_data_t& operator=(insert_list_data_t&&) = default; - ~insert_list_data_t() = default; - - std::tuple...> _columns; - std::tuple _values; - std::tuple _assignments; // FIXME: Need to replace _columns and _values by _assignments (connector-container requires assignments) - interpretable_list_t _dynamic_columns; - interpretable_list_t _dynamic_values; - }; - - template - struct insert_list_t - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits; - - using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - - template class Target> - using copy_assignments_t = Target; // FIXME: Nice idea to copy variadic template arguments? - template class Target, template class Wrap> - using copy_wrapped_assignments_t = Target...>; - - static_assert(_is_dynamic::value or sizeof...(Assignments), "at least one assignment required in set()"); - - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in set()"); - - static_assert(sqlpp::detail::all_t::value...>::value, "at least one argument is not an assignment in set()"); - - static_assert(sqlpp::detail::none_t::value...>::value, "at least one assignment is prohibited by its column definition in set()"); - -#warning: Need to reactivate these checks - /* - using _column_required_tables = typename ::sqlpp::detail::make_joined_set::type; - using _value_required_tables = typename ::sqlpp::detail::make_joined_set::type; - using _provided_tables = ::sqlpp::detail::type_set<>; - using _required_tables = typename ::sqlpp::detail::make_joined_set<_column_required_tables, _value_required_tables>::type; - static_assert(sizeof...(Assignments) ? (_column_required_tables::size::value == 1) : true, "set() contains assignments for tables from several columns"); - static_assert(::sqlpp::detail::is_subset_of<_value_required_tables, _column_required_tables>::value, "set() contains values from foreign tables"); - */ - - // Data - using _data_t = insert_list_data_t; - - // Member implementation with data and methods - template - struct _impl_t - { - template - void add_ntc(Assignment assignment) - { - add(assignment); - } - - template - void add(Assignment assignment) - { - static_assert(_is_dynamic::value, "add must not be called for static from()"); - static_assert(is_assignment_t::value, "add() arguments require to be assigments"); - static_assert(not must_not_insert_t::value, "add() argument must not be used in insert"); - static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables::value, "add() contains a column from a foreign table"); - - using ok = ::sqlpp::detail::all_t< - _is_dynamic::value, - is_assignment_t::value, - not must_not_insert_t::value, - (not TableCheckRequired::value or Policies::template _no_unknown_tables::value)>; - - _add_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert - } - - private: - template - void _add_impl(Assignment assignment, const std::true_type&) - { - _data._dynamic_columns.emplace_back(simple_column_t{assignment._lhs}); - _data._dynamic_values.emplace_back(assignment._rhs); - } - - template - void _add_impl(Assignment assignment, const std::false_type&); - public: - _data_t _data; - }; - - // Member template for adding the named member to a statement - template - struct _member_t - { - using _data_t = insert_list_data_t; - - _impl_t insert_list; - _impl_t& operator()() { return insert_list; } - const _impl_t& operator()() const { return insert_list; } - - template - static auto _get_member(T t) -> decltype(t.insert_list) - { - return t.insert_list; - } - }; - - // Additional methods for the statement - template - struct _methods_t - { - }; - - - - }; - - template - struct column_list_data_t - { - column_list_data_t(Columns... columns): - _columns(simple_column_t{columns}...) + insert_list_data_t(Assignments... assignments): + _assignments(assignments...), + _columns({assignments._lhs}...), + _values(assignments._rhs...) {} - column_list_data_t(const column_list_data_t&) = default; - column_list_data_t(column_list_data_t&&) = default; - column_list_data_t& operator=(const column_list_data_t&) = default; - column_list_data_t& operator=(column_list_data_t&&) = default; - ~column_list_data_t() = default; + insert_list_data_t(const insert_list_data_t&) = default; + insert_list_data_t(insert_list_data_t&&) = default; + insert_list_data_t& operator=(const insert_list_data_t&) = default; + insert_list_data_t& operator=(insert_list_data_t&&) = default; + ~insert_list_data_t() = default; -#warning need to define just one version of value_tuple_t - using _value_tuple_t = std::tuple...>; - std::tuple...> _columns; - std::vector<_value_tuple_t> _insert_values; - }; + std::tuple...> _columns; + std::tuple _values; + std::tuple _assignments; // FIXME: Need to replace _columns and _values by _assignments (connector-container requires assignments) + interpretable_list_t _dynamic_columns; + interpretable_list_t _dynamic_values; + }; - template - struct column_list_t - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits; - - static_assert(sizeof...(Columns), "at least one column required in columns()"); - - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in columns()"); - - static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a column in columns()"); - - static_assert(::sqlpp::detail::none_t::value...>::value, "at least one column argument has a must_not_insert flag in its definition"); - - using _value_tuple_t = std::tuple...>; - - static_assert(required_tables_of::size::value == 1, "columns from multiple tables in columns()"); - - // Data - using _data_t = column_list_data_t; - - // Member implementation with data and methods - template - struct _impl_t - { - template - void add(Assignments... assignments) - { - static_assert(::sqlpp::detail::all_t::value...>::value, "add_values() arguments have to be assignments"); - using _arg_value_tuple = std::tuple...>; - using _args_correct = std::is_same<_arg_value_tuple, _value_tuple_t>; - static_assert(_args_correct::value, "add_values() arguments do not match columns() arguments"); - - using ok = ::sqlpp::detail::all_t< - ::sqlpp::detail::all_t::value...>::value, - _args_correct::value>; - - _add_impl(ok(), assignments...); // dispatch to prevent compile messages after the static_assert - } - - private: - template - void _add_impl(const std::true_type&, Assignments... assignments) - { - return _data._insert_values.emplace_back(insert_value_t{assignments}...); - } - - template - void _add_impl(const std::false_type&, Assignments... assignments); - public: - _data_t _data; - }; - - // Member template for adding the named member to a statement - template - struct _member_t - { - using _data_t = column_list_data_t; - - _impl_t values; - _impl_t& operator()() { return values; } - const _impl_t& operator()() const { return values; } - - template - static auto _get_member(T t) -> decltype(t.values) - { - return t.values; - } - }; - - // Additional methods for the statement - template - struct _methods_t - { - }; - -/* - bool empty() const - { - return _insert_values.empty(); - } - */ - - }; - - // NO HAVING YET - struct no_insert_value_list_t + template + struct insert_list_t { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + + using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; + + template class Target> + using copy_assignments_t = Target; // FIXME: Nice idea to copy variadic template arguments? + template class Target, template class Wrap> + using copy_wrapped_assignments_t = Target...>; + + static_assert(_is_dynamic::value or sizeof...(Assignments), "at least one assignment required in set()"); + + static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in set()"); + + static_assert(sqlpp::detail::all_t::value...>::value, "at least one argument is not an assignment in set()"); + + static_assert(sqlpp::detail::none_t::value...>::value, "at least one assignment is prohibited by its column definition in set()"); + +#warning: Need to reactivate these checks + /* + using _column_required_tables = typename ::sqlpp::detail::make_joined_set::type; + using _value_required_tables = typename ::sqlpp::detail::make_joined_set::type; + using _provided_tables = ::sqlpp::detail::type_set<>; + using _required_tables = typename ::sqlpp::detail::make_joined_set<_column_required_tables, _value_required_tables>::type; + static_assert(sizeof...(Assignments) ? (_column_required_tables::size::value == 1) : true, "set() contains assignments for tables from several columns"); + static_assert(::sqlpp::detail::is_subset_of<_value_required_tables, _column_required_tables>::value, "set() contains values from foreign tables"); + */ // Data - using _data_t = no_data_t; + using _data_t = insert_list_data_t; // Member implementation with data and methods - template + template struct _impl_t { + template + void add_ntc(Assignment assignment) + { + add(assignment); + } + + template + void add(Assignment assignment) + { + static_assert(_is_dynamic::value, "add must not be called for static from()"); + static_assert(is_assignment_t::value, "add() arguments require to be assigments"); + static_assert(not must_not_insert_t::value, "add() argument must not be used in insert"); + static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables::value, "add() contains a column from a foreign table"); + + using ok = ::sqlpp::detail::all_t< + _is_dynamic::value, + is_assignment_t::value, + not must_not_insert_t::value, + (not TableCheckRequired::value or Policies::template _no_unknown_tables::value)>; + + _add_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert + } + + private: + template + void _add_impl(Assignment assignment, const std::true_type&) + { + _data._dynamic_columns.emplace_back(simple_column_t{assignment._lhs}); + _data._dynamic_values.emplace_back(assignment._rhs); + } + + template + void _add_impl(Assignment assignment, const std::false_type&); + public: _data_t _data; }; @@ -326,124 +179,271 @@ namespace sqlpp template struct _member_t { - using _data_t = no_data_t; + using _data_t = insert_list_data_t; - _impl_t no_insert_values; - _impl_t& operator()() { return no_insert_values; } - const _impl_t& operator()() const { return no_insert_values; } + _impl_t insert_list; + _impl_t& operator()() { return insert_list; } + const _impl_t& operator()() const { return insert_list; } template - static auto _get_member(T t) -> decltype(t.no_insert_values) + static auto _get_member(T t) -> decltype(t.insert_list) { - return t.no_insert_values; + return t.insert_list; } }; + // Additional methods for the statement template struct _methods_t { - using _database_t = typename Policies::_database_t; - template - using _new_statement_t = typename Policies::template _new_statement_t; - - auto default_values() - -> _new_statement_t - { - return { *static_cast(this), insert_default_values_data_t{} }; - } - - template - auto columns(Args... args) - -> _new_statement_t> - { - return { *static_cast(this), column_list_data_t{args...} }; - } - - template - auto set(Args... args) - -> _new_statement_t> - { - return { *static_cast(this), insert_list_data_t{args...} }; - } - - template - auto dynamic_set(Args... args) - -> _new_statement_t> - { - static_assert(not std::is_same<_database_t, void>::value, "dynamic_set must not be called in a static statement"); - return { *static_cast(this), insert_list_data_t<_database_t, Args...>{args...} }; - } }; + + + }; - // Interpreters - template - struct serializer_t - { - using T = insert_default_values_data_t; + template + struct column_list_data_t + { + column_list_data_t(Columns... columns): + _columns(simple_column_t{columns}...) + {} - static Context& _(const T& t, Context& context) + column_list_data_t(const column_list_data_t&) = default; + column_list_data_t(column_list_data_t&&) = default; + column_list_data_t& operator=(const column_list_data_t&) = default; + column_list_data_t& operator=(column_list_data_t&&) = default; + ~column_list_data_t() = default; + +#warning need to define just one version of value_tuple_t + using _value_tuple_t = std::tuple...>; + std::tuple...> _columns; + std::vector<_value_tuple_t> _insert_values; + }; + + template + struct column_list_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + + static_assert(sizeof...(Columns), "at least one column required in columns()"); + + static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in columns()"); + + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a column in columns()"); + + static_assert(::sqlpp::detail::none_t::value...>::value, "at least one column argument has a must_not_insert flag in its definition"); + + using _value_tuple_t = std::tuple...>; + + static_assert(required_tables_of::size::value == 1, "columns from multiple tables in columns()"); + + // Data + using _data_t = column_list_data_t; + + // Member implementation with data and methods + template + struct _impl_t { - context << " DEFAULT VALUES"; - return context; - } + template + void add(Assignments... assignments) + { + static_assert(::sqlpp::detail::all_t::value...>::value, "add_values() arguments have to be assignments"); + using _arg_value_tuple = std::tuple...>; + using _args_correct = std::is_same<_arg_value_tuple, _value_tuple_t>; + static_assert(_args_correct::value, "add_values() arguments do not match columns() arguments"); + + using ok = ::sqlpp::detail::all_t< + ::sqlpp::detail::all_t::value...>::value, + _args_correct::value>; + + _add_impl(ok(), assignments...); // dispatch to prevent compile messages after the static_assert + } + + private: + template + void _add_impl(const std::true_type&, Assignments... assignments) + { + return _data._insert_values.emplace_back(insert_value_t{assignments}...); + } + + template + void _add_impl(const std::false_type&, Assignments... assignments); + public: + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = column_list_data_t; + + _impl_t values; + _impl_t& operator()() { return values; } + const _impl_t& operator()() const { return values; } + + template + static auto _get_member(T t) -> decltype(t.values) + { + return t.values; + } + }; + + // Additional methods for the statement + template + struct _methods_t + { + }; + + /* + bool empty() const + { + return _insert_values.empty(); + } + */ + + }; + + // NO HAVING YET + struct no_insert_value_list_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; + + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; }; - template - struct serializer_t> + // Member template for adding the named member to a statement + template + struct _member_t { - using T = column_list_data_t; + using _data_t = no_data_t; - static Context& _(const T& t, Context& context) + _impl_t no_insert_values; + _impl_t& operator()() { return no_insert_values; } + const _impl_t& operator()() const { return no_insert_values; } + + template + static auto _get_member(T t) -> decltype(t.no_insert_values) + { + return t.no_insert_values; + } + }; + + template + struct _methods_t + { + using _database_t = typename Policies::_database_t; + template + using _new_statement_t = typename Policies::template _new_statement_t; + + auto default_values() + -> _new_statement_t + { + return { *static_cast(this), insert_default_values_data_t{} }; + } + + template + auto columns(Args... args) + -> _new_statement_t> + { + return { *static_cast(this), column_list_data_t{args...} }; + } + + template + auto set(Args... args) + -> _new_statement_t> + { + return { *static_cast(this), insert_list_data_t{args...} }; + } + + template + auto dynamic_set(Args... args) + -> _new_statement_t> + { + static_assert(not std::is_same<_database_t, void>::value, "dynamic_set must not be called in a static statement"); + return { *static_cast(this), insert_list_data_t<_database_t, Args...>{args...} }; + } + }; + }; + + // Interpreters + template + struct serializer_t + { + using T = insert_default_values_data_t; + + static Context& _(const T& t, Context& context) + { + context << " DEFAULT VALUES"; + return context; + } + }; + + template + struct serializer_t> + { + using T = column_list_data_t; + + static Context& _(const T& t, Context& context) + { + context << " ("; + interpret_tuple(t._columns, ",", context); + context << ")"; + context << " VALUES "; + bool first = true; + for (const auto& row : t._insert_values) + { + if (not first) + context << ','; + else + first = false; + context << '('; + interpret_tuple(row, ",", context); + context << ')'; + } + + return context; + } + }; + + template + struct serializer_t> + { + using T = insert_list_data_t; + + static Context& _(const T& t, Context& context) + { + if (sizeof...(Assignments) + t._dynamic_columns.size() == 0) + { + serialize(insert_default_values_data_t(), context); + } + else { context << " ("; interpret_tuple(t._columns, ",", context); + if (sizeof...(Assignments) and not t._dynamic_columns.empty()) + context << ','; + interpret_list(t._dynamic_columns, ',', context); + context << ") VALUES("; + interpret_tuple(t._values, ",", context); + if (sizeof...(Assignments) and not t._dynamic_values.empty()) + context << ','; + interpret_list(t._dynamic_values, ',', context); context << ")"; - context << " VALUES "; - bool first = true; - for (const auto& row : t._insert_values) - { - if (not first) - context << ','; - else - first = false; - context << '('; - interpret_tuple(row, ",", context); - context << ')'; - } - - return context; } - }; - - template - struct serializer_t> - { - using T = insert_list_data_t; - - static Context& _(const T& t, Context& context) - { - if (sizeof...(Assignments) + t._dynamic_columns.size() == 0) - { - serialize(insert_default_values_data_t(), context); - } - else - { - context << " ("; - interpret_tuple(t._columns, ",", context); - if (sizeof...(Assignments) and not t._dynamic_columns.empty()) - context << ','; - interpret_list(t._dynamic_columns, ',', context); - context << ") VALUES("; - interpret_tuple(t._values, ",", context); - if (sizeof...(Assignments) and not t._dynamic_values.empty()) - context << ','; - interpret_list(t._dynamic_values, ',', context); - context << ")"; - } - return context; - } - }; + return context; + } + }; } diff --git a/include/sqlpp11/integral.h b/include/sqlpp11/integral.h index 47fc007c..2b52fb6e 100644 --- a/include/sqlpp11/integral.h +++ b/include/sqlpp11/integral.h @@ -45,7 +45,7 @@ namespace sqlpp using _traits = make_traits; using _tag = ::sqlpp::tag::integral; using _cpp_value_type = int64_t; - + struct _parameter_t { using _value_type = integral; @@ -53,12 +53,12 @@ namespace sqlpp _parameter_t(): _value(0), _is_null(true) - {} + {} explicit _parameter_t(const _cpp_value_type& value): _value(value), _is_null(false) - {} + {} _parameter_t& operator=(const _cpp_value_type& value) { @@ -74,7 +74,7 @@ namespace sqlpp } bool is_null() const - { + { return _is_null; } @@ -97,90 +97,90 @@ namespace sqlpp }; template - struct _result_entry_t - { - using _value_type = integral; + struct _result_entry_t + { + using _value_type = integral; - _result_entry_t(): - _is_valid(false), - _is_null(true), - _value(0) + _result_entry_t(): + _is_valid(false), + _is_null(true), + _value(0) {} - _result_entry_t(const char* data, size_t): - _is_valid(true), - _is_null(data == nullptr), - _value(_is_null ? 0 : std::strtoll(data, nullptr, 10)) - {} + _result_entry_t(const char* data, size_t): + _is_valid(true), + _is_null(data == nullptr), + _value(_is_null ? 0 : std::strtoll(data, nullptr, 10)) + {} - void assign(const char* data, size_t) - { - _is_valid = true; - _is_null = data == nullptr; - _value = _is_null ? 0 : std::strtoll(data, nullptr, 10); - } - - void invalidate() - { - _is_valid = false; - _is_null = true; - _value = 0; - } - - void validate() - { - _is_valid = true; - } - - bool is_null() const - { - if (connector_assert_result_validity_t::value) - assert(_is_valid); - else if (not _is_valid) - throw exception("accessing is_null in non-existing row"); - return _is_null; - } - - _cpp_value_type value() const - { - const bool null_value = _is_null and not NullIsTrivial and not connector_null_result_is_trivial_value_t::value; - if (connector_assert_result_validity_t::value) + void assign(const char* data, size_t) { - assert(_is_valid); - assert(not null_value); - } - else - { - if (not _is_valid) - throw exception("accessing value in non-existing row"); - if (null_value) - throw exception("accessing value of NULL field"); - } - return _value; - } - - operator _cpp_value_type() const { return value(); } - - template - void _bind(Target& target, size_t i) - { - target._bind_integral_result(i, &_value, &_is_null); + _is_valid = true; + _is_null = data == nullptr; + _value = _is_null ? 0 : std::strtoll(data, nullptr, 10); } - private: - bool _is_valid; - bool _is_null; - _cpp_value_type _value; - }; + void invalidate() + { + _is_valid = false; + _is_null = true; + _value = 0; + } + + void validate() + { + _is_valid = true; + } + + bool is_null() const + { + if (connector_assert_result_validity_t::value) + assert(_is_valid); + else if (not _is_valid) + throw exception("accessing is_null in non-existing row"); + return _is_null; + } + + _cpp_value_type value() const + { + const bool null_value = _is_null and not NullIsTrivial and not connector_null_result_is_trivial_value_t::value; + if (connector_assert_result_validity_t::value) + { + assert(_is_valid); + assert(not null_value); + } + else + { + if (not _is_valid) + throw exception("accessing value in non-existing row"); + if (null_value) + throw exception("accessing value of NULL field"); + } + return _value; + } + + operator _cpp_value_type() const { return value(); } + + template + void _bind(Target& target, size_t i) + { + target._bind_integral_result(i, &_value, &_is_null); + } + + private: + bool _is_valid; + bool _is_null; + _cpp_value_type _value; + }; template struct _is_valid_operand - { - static constexpr bool value = - is_expression_t::value // expressions are OK - and is_numeric_t::value // the correct value type is required, of course - ; - }; + { + static constexpr bool value = + is_expression_t::value // expressions are OK + and is_numeric_t::value // the correct value type is required, of course + ; + }; template struct expression_operators: public basic_expression_operators @@ -243,50 +243,50 @@ namespace sqlpp template struct column_operators - { - template - auto operator +=(T t) const -> assignment_t, wrap_operand_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + { + template + auto operator +=(T t) const -> assignment_t, wrap_operand_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - return { *static_cast(this), { *static_cast(this), rhs{t} } }; - } + return { *static_cast(this), { *static_cast(this), rhs{t} } }; + } - template - auto operator -=(T t) const -> assignment_t, wrap_operand_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + template + auto operator -=(T t) const -> assignment_t, wrap_operand_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - return { *static_cast(this), { *static_cast(this), rhs{t} } }; - } + return { *static_cast(this), { *static_cast(this), rhs{t} } }; + } - template - auto operator /=(T t) const -> assignment_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + template + auto operator /=(T t) const -> assignment_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - return { *static_cast(this), { *static_cast(this), rhs{t} } }; - } + return { *static_cast(this), { *static_cast(this), rhs{t} } }; + } - template - auto operator *=(T t) const -> assignment_t, wrap_operand_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + template + auto operator *=(T t) const -> assignment_t, wrap_operand_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - return { *static_cast(this), { *static_cast(this), rhs{t} } }; - } - }; + return { *static_cast(this), { *static_cast(this), rhs{t} } }; + } + }; }; template - inline std::ostream& operator<<(std::ostream& os, const integral::_result_entry_t& e) - { - return os << e.value(); - } + inline std::ostream& operator<<(std::ostream& os, const integral::_result_entry_t& e) + { + return os << e.value(); + } } using tinyint = detail::integral; diff --git a/include/sqlpp11/interpret_tuple.h b/include/sqlpp11/interpret_tuple.h index aa12c9b8..04ac5d4a 100644 --- a/include/sqlpp11/interpret_tuple.h +++ b/include/sqlpp11/interpret_tuple.h @@ -50,7 +50,7 @@ namespace sqlpp auto interpret_tuple_impl(const Tuple& t, const Separator& separator, Context& context, const ::sqlpp::detail::index_sequence&) -> Context& { - // Note: A braced-init-list does guarantee the order of evaluation according to 12.6.1 [class.explicit.init] paragraph 2 and 8.5.4 [dcl.init.list] paragraph 4. + // Note: A braced-init-list does guarantee the order of evaluation according to 12.6.1 [class.explicit.init] paragraph 2 and 8.5.4 [dcl.init.list] paragraph 4. // See for example: "http://en.cppreference.com/w/cpp/utility/integer_sequence" // See also: "http://stackoverflow.com/questions/6245735/pretty-print-stdtuple/6245777#6245777" // Beware of gcc-bug: "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51253", otherwise an empty swallow struct could be used diff --git a/include/sqlpp11/interpretable.h b/include/sqlpp11/interpretable.h index faa6a133..28a2413b 100644 --- a/include/sqlpp11/interpretable.h +++ b/include/sqlpp11/interpretable.h @@ -35,94 +35,94 @@ namespace sqlpp { - template - struct interpretable_t + template + struct interpretable_t + { + using _serializer_context_t = typename Db::_serializer_context_t; + using _interpreter_context_t = typename Db::_interpreter_context_t; + + template + interpretable_t(T t): + _impl(std::make_shared<_impl_t>(t)) + {} + + interpretable_t(const interpretable_t&) = default; + interpretable_t(interpretable_t&&) = default; + interpretable_t& operator=(const interpretable_t&) = default; + interpretable_t& operator=(interpretable_t&&) = default; + ~interpretable_t() = default; + + sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const { - using _serializer_context_t = typename Db::_serializer_context_t; - using _interpreter_context_t = typename Db::_interpreter_context_t; + return _impl->serialize(context); + } - template - interpretable_t(T t): - _impl(std::make_shared<_impl_t>(t)) - {} - - interpretable_t(const interpretable_t&) = default; - interpretable_t(interpretable_t&&) = default; - interpretable_t& operator=(const interpretable_t&) = default; - interpretable_t& operator=(interpretable_t&&) = default; - ~interpretable_t() = default; - - sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const - { - return _impl->serialize(context); - } - - // This method only exists if Db::_serializer_context_t and sqlpp::serializer_context_t are not the same - template + // This method only exists if Db::_serializer_context_t and sqlpp::serializer_context_t are not the same + template auto serialize(Context& context) const -> typename std::enable_if::value - and not std::is_same::value, Context&>::type + and not std::is_same::value, Context&>::type { return _impl->db_serialize(context); } - _interpreter_context_t& interpret(_interpreter_context_t& context) const - { - return _impl->interpret(context); - } + _interpreter_context_t& interpret(_interpreter_context_t& context) const + { + return _impl->interpret(context); + } - private: - struct _impl_base - { - virtual sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const = 0; - virtual _serializer_context_t& db_serialize(_serializer_context_t& context) const = 0; - virtual _interpreter_context_t& interpret(_interpreter_context_t& context) const = 0; - }; - - template - struct _impl_t: public _impl_base - { - static_assert(not make_parameter_list_t::type::size::value, "parameters not supported in dynamic statement parts"); - _impl_t(T t): - _t(t) - {} - - sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const - { - sqlpp::serialize(_t, context); - return context; - } - - _serializer_context_t& db_serialize(_serializer_context_t& context) const - { - Db::_serialize_interpretable(_t, context); - return context; - } - - _interpreter_context_t& interpret(_interpreter_context_t& context) const - { - Db::_interpret_interpretable(_t, context); - return context; - } - - T _t; - }; - - std::shared_ptr _impl; + private: + struct _impl_base + { + virtual sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const = 0; + virtual _serializer_context_t& db_serialize(_serializer_context_t& context) const = 0; + virtual _interpreter_context_t& interpret(_interpreter_context_t& context) const = 0; }; - template - struct serializer_t> + template + struct _impl_t: public _impl_base { - using T = interpretable_t; + static_assert(not make_parameter_list_t::type::size::value, "parameters not supported in dynamic statement parts"); + _impl_t(T t): + _t(t) + {} - static Context& _(const T& t, Context& context) + sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const { - t.serialize(context); + sqlpp::serialize(_t, context); return context; } + + _serializer_context_t& db_serialize(_serializer_context_t& context) const + { + Db::_serialize_interpretable(_t, context); + return context; + } + + _interpreter_context_t& interpret(_interpreter_context_t& context) const + { + Db::_interpret_interpretable(_t, context); + return context; + } + + T _t; }; + std::shared_ptr _impl; + }; + + template + struct serializer_t> + { + using T = interpretable_t; + + static Context& _(const T& t, Context& context) + { + t.serialize(context); + return context; + } + }; + } #endif diff --git a/include/sqlpp11/interpretable_list.h b/include/sqlpp11/interpretable_list.h index 8c9367d0..e3641972 100644 --- a/include/sqlpp11/interpretable_list.h +++ b/include/sqlpp11/interpretable_list.h @@ -32,85 +32,85 @@ namespace sqlpp { - template - struct interpretable_list_t + template + struct interpretable_list_t + { + std::vector> _serializables; + + std::size_t size() const { - std::vector> _serializables; + return _serializables.size(); + } - std::size_t size() const - { - return _serializables.size(); - } + bool empty() const + { + return _serializables.empty(); + } - bool empty() const - { - return _serializables.empty(); - } - - template + template void emplace_back(Expr expr) { _serializables.emplace_back(expr); } - }; + }; - template<> - struct interpretable_list_t + template<> + struct interpretable_list_t + { + static constexpr std::size_t size() { - static constexpr std::size_t size() - { - return 0; - } - - static constexpr bool empty() - { - return true; - } - - }; - - template - struct serializable_list_interpreter_t - { - using T = List; - - template - static Context& _(const T& t, const Separator& separator, Context& context) - { - bool first = true; - for (const auto entry : t._serializables) - { - if (not first) - { - context << separator; - first = false; - } - serialize(entry, context); - } - return context; - } - }; - - template - struct serializable_list_interpreter_t> - { - using T = interpretable_list_t; - - template - static Context& _(const T& t, const Separator& separator, Context& context) - { - return context; - } - }; - - template - auto interpret_list(const T& t, const Separator& separator, Context& context) - -> decltype(serializable_list_interpreter_t::_(t, separator, context)) - { - return serializable_list_interpreter_t::_(t, separator, context); + return 0; } + static constexpr bool empty() + { + return true; + } + + }; + + template + struct serializable_list_interpreter_t + { + using T = List; + + template + static Context& _(const T& t, const Separator& separator, Context& context) + { + bool first = true; + for (const auto entry : t._serializables) + { + if (not first) + { + context << separator; + first = false; + } + serialize(entry, context); + } + return context; + } + }; + + template + struct serializable_list_interpreter_t> + { + using T = interpretable_list_t; + + template + static Context& _(const T& t, const Separator& separator, Context& context) + { + return context; + } + }; + + template + auto interpret_list(const T& t, const Separator& separator, Context& context) + -> decltype(serializable_list_interpreter_t::_(t, separator, context)) + { + return serializable_list_interpreter_t::_(t, separator, context); + } + } #endif diff --git a/include/sqlpp11/interpreter.h b/include/sqlpp11/interpreter.h index f58f0940..cd7c9690 100644 --- a/include/sqlpp11/interpreter.h +++ b/include/sqlpp11/interpreter.h @@ -31,14 +31,14 @@ namespace sqlpp { - template - struct interpreter_t + template + struct interpreter_t + { + static void _(const T& t, Context& context) { - static void _(const T& t, Context& context) - { - static_assert(wrong_t::value, "missing interpreter specialization"); - } - }; + static_assert(wrong_t::value, "missing interpreter specialization"); + } + }; } diff --git a/include/sqlpp11/into.h b/include/sqlpp11/into.h index f65857cd..9395e840 100644 --- a/include/sqlpp11/into.h +++ b/include/sqlpp11/into.h @@ -34,110 +34,39 @@ namespace sqlpp { - // A SINGLE TABLE DATA - template - struct into_data_t - { - into_data_t(Table table): - _table(table) - {} - - into_data_t(const into_data_t&) = default; - into_data_t(into_data_t&&) = default; - into_data_t& operator=(const into_data_t&) = default; - into_data_t& operator=(into_data_t&&) = default; - ~into_data_t() = default; - - Table _table; - }; - - // A SINGLE TABLE - template - struct into_t - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits
; - - static_assert(is_table_t
::value, "argument has to be a table"); - static_assert(required_tables_of
::size::value == 0, "table depends on another table"); - - using _data_t = into_data_t; - - struct _name_t {}; - - // Member implementation with data and methods - template - struct _impl_t - { - _data_t _data; - }; - - // Member template for adding the named member to a statement - template - struct _member_t - { - using _data_t = into_data_t; - - _impl_t into; - _impl_t& operator()() { return into; } - const _impl_t& operator()() const { return into; } - - template - static auto _get_member(T t) -> decltype(t.into) - { - return t.into; - } - }; - - // Additional methods for the statement - template - struct _methods_t - { - }; - - template - struct _result_methods_t - { - using _statement_t = typename Policies::_statement_t; - - const _statement_t& _get_statement() const - { - return static_cast(*this); - } - - template - auto _run(Db& db) const -> decltype(db.insert(_get_statement())) - { - _statement_t::_check_consistency(); - - static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run insert directly with parameters, use prepare instead"); - return db.insert(*this); - } - - /* - template - auto _prepare(Db& db) const - -> prepared_insert_t - { - _statement_t::_check_consistency(); - - return {{}, db.prepare_insert(*this)}; - } - */ - }; - }; - - // NO INTO YET - struct no_into_t + // A SINGLE TABLE DATA + template + struct into_data_t { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; + into_data_t(Table table): + _table(table) + {} - // Data - using _data_t = no_data_t; + into_data_t(const into_data_t&) = default; + into_data_t(into_data_t&&) = default; + into_data_t& operator=(const into_data_t&) = default; + into_data_t& operator=(into_data_t&&) = default; + ~into_data_t() = default; + + Table _table; + }; + + // A SINGLE TABLE + template + struct into_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits
; + + static_assert(is_table_t
::value, "argument has to be a table"); + static_assert(required_tables_of
::size::value == 0, "table depends on another table"); + + using _data_t = into_data_t; + + struct _name_t {}; // Member implementation with data and methods - template + template struct _impl_t { _data_t _data; @@ -147,49 +76,120 @@ namespace sqlpp template struct _member_t { - using _data_t = no_data_t; + using _data_t = into_data_t; - _impl_t no_into; - _impl_t& operator()() { return no_into; } - const _impl_t& operator()() const { return no_into; } + _impl_t into; + _impl_t& operator()() { return into; } + const _impl_t& operator()() const { return into; } template - static auto _get_member(T t) -> decltype(t.no_into) + static auto _get_member(T t) -> decltype(t.into) { - return t.no_into; + return t.into; } }; + // Additional methods for the statement template struct _methods_t { - using _database_t = typename Policies::_database_t; - template - using _new_statement_t = typename Policies::template _new_statement_t; + }; - template - auto into(Args... args) - -> _new_statement_t> + template + struct _result_methods_t + { + using _statement_t = typename Policies::_statement_t; + + const _statement_t& _get_statement() const + { + return static_cast(*this); + } + + template + auto _run(Db& db) const -> decltype(db.insert(_get_statement())) { - return { *static_cast(this), into_data_t{args...} }; + _statement_t::_check_consistency(); + + static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run insert directly with parameters, use prepare instead"); + return db.insert(*this); } + + /* + template + auto _prepare(Db& db) const + -> prepared_insert_t + { + _statement_t::_check_consistency(); + + return {{}, db.prepare_insert(*this)}; + } + */ }; }; - // Interpreters - template - struct serializer_t> - { - using T = into_data_t; + // NO INTO YET + struct no_into_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; - static Context& _(const T& t, Context& context) - { - context << " INTO "; - serialize(t._table, context); - return context; - } + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; }; + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; + + _impl_t no_into; + _impl_t& operator()() { return no_into; } + const _impl_t& operator()() const { return no_into; } + + template + static auto _get_member(T t) -> decltype(t.no_into) + { + return t.no_into; + } + }; + + template + struct _methods_t + { + using _database_t = typename Policies::_database_t; + template + using _new_statement_t = typename Policies::template _new_statement_t; + + template + auto into(Args... args) + -> _new_statement_t> + { + return { *static_cast(this), into_data_t{args...} }; + } + }; + }; + + // Interpreters + template + struct serializer_t> + { + using T = into_data_t; + + static Context& _(const T& t, Context& context) + { + context << " INTO "; + serialize(t._table, context); + return context; + } + }; + } #endif diff --git a/include/sqlpp11/is_null.h b/include/sqlpp11/is_null.h index 5dc584dd..1aedf49a 100644 --- a/include/sqlpp11/is_null.h +++ b/include/sqlpp11/is_null.h @@ -33,55 +33,55 @@ namespace sqlpp { - template + template struct is_null_t: public boolean::template expression_operators>, - public alias_operators> + public alias_operators> + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + + static constexpr bool _inverted = not NotInverted; + + struct _value_type: public boolean { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits; - - static constexpr bool _inverted = not NotInverted; - - struct _value_type: public boolean - { - using _is_named_expression = std::true_type; - }; - - struct _name_t - { - static constexpr const char* _get_name() { return _inverted ? "IS NOT NULL" : "IS NULL"; } - template - struct _member_t - { - T in; - }; - }; - - is_null_t(Operand operand): - _operand(operand) - {} - - is_null_t(const is_null_t&) = default; - is_null_t(is_null_t&&) = default; - is_null_t& operator=(const is_null_t&) = default; - is_null_t& operator=(is_null_t&&) = default; - ~is_null_t() = default; - - Operand _operand; + using _is_named_expression = std::true_type; }; - template - struct serializer_t> - { - using T = ::sqlpp::is_null_t; - - static Context& _(const T& t, Context& context) + struct _name_t + { + static constexpr const char* _get_name() { return _inverted ? "IS NOT NULL" : "IS NULL"; } + template + struct _member_t { - serialize(t._operand, context); - context << (t._inverted ? " IS NOT NULL" : " IS NULL"); - return context; - } - }; + T in; + }; + }; + + is_null_t(Operand operand): + _operand(operand) + {} + + is_null_t(const is_null_t&) = default; + is_null_t(is_null_t&&) = default; + is_null_t& operator=(const is_null_t&) = default; + is_null_t& operator=(is_null_t&&) = default; + ~is_null_t() = default; + + Operand _operand; + }; + + template + struct serializer_t> + { + using T = ::sqlpp::is_null_t; + + static Context& _(const T& t, Context& context) + { + serialize(t._operand, context); + context << (t._inverted ? " IS NOT NULL" : " IS NULL"); + return context; + } + }; } diff --git a/include/sqlpp11/is_null_fwd.h b/include/sqlpp11/is_null_fwd.h index 0a866b3d..8d53cc01 100644 --- a/include/sqlpp11/is_null_fwd.h +++ b/include/sqlpp11/is_null_fwd.h @@ -29,7 +29,7 @@ namespace sqlpp { - template + template struct is_null_t; } diff --git a/include/sqlpp11/join.h b/include/sqlpp11/join.h index 811fb0c5..9d0a92f4 100644 --- a/include/sqlpp11/join.h +++ b/include/sqlpp11/join.h @@ -143,22 +143,22 @@ namespace sqlpp On _on; }; - template - struct serializer_t> - { - using T = join_t; + template + struct serializer_t> + { + using T = join_t; - static Context& _(const T& t, Context& context) - { - static_assert(not is_noop::value, "joined tables require on()"); - serialize(t._lhs, context); - context << JoinType::_name; - context << " JOIN "; - serialize(t._rhs, context); - serialize(t._on, context); - return context; - } - }; + static Context& _(const T& t, Context& context) + { + static_assert(not is_noop::value, "joined tables require on()"); + serialize(t._lhs, context); + context << JoinType::_name; + context << " JOIN "; + serialize(t._rhs, context); + serialize(t._on, context); + return context; + } + }; } diff --git a/include/sqlpp11/like.h b/include/sqlpp11/like.h index 10b987ed..46f1572a 100644 --- a/include/sqlpp11/like.h +++ b/include/sqlpp11/like.h @@ -33,55 +33,55 @@ namespace sqlpp { - template - struct like_t: public boolean::template expression_operators>, - public alias_operators> + template + struct like_t: public boolean::template expression_operators>, + public alias_operators> + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + + static_assert(is_text_t::value, "Operand for like() has to be a text"); + static_assert(is_text_t::value, "Pattern for like() has to be a text"); + + struct _name_t { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits; - - static_assert(is_text_t::value, "Operand for like() has to be a text"); - static_assert(is_text_t::value, "Pattern for like() has to be a text"); - - struct _name_t - { - static constexpr const char* _get_name() { return "LIKE"; } - template - struct _member_t - { - T like; - }; - }; - - like_t(Operand operand, Pattern pattern): - _operand(operand), - _pattern(pattern) - {} - - like_t(const like_t&) = default; - like_t(like_t&&) = default; - like_t& operator=(const like_t&) = default; - like_t& operator=(like_t&&) = default; - ~like_t() = default; - - Operand _operand; - Pattern _pattern; + static constexpr const char* _get_name() { return "LIKE"; } + template + struct _member_t + { + T like; + }; }; - template - struct serializer_t> - { - using T = like_t; + like_t(Operand operand, Pattern pattern): + _operand(operand), + _pattern(pattern) + {} - static Context& _(const T& t, Context& context) - { - serialize(t._operand, context); - context << " LIKE("; - serialize(t._pattern, context); - context << ")"; - return context; - } - }; + like_t(const like_t&) = default; + like_t(like_t&&) = default; + like_t& operator=(const like_t&) = default; + like_t& operator=(like_t&&) = default; + ~like_t() = default; + + Operand _operand; + Pattern _pattern; + }; + + template + struct serializer_t> + { + using T = like_t; + + static Context& _(const T& t, Context& context) + { + serialize(t._operand, context); + context << " LIKE("; + serialize(t._pattern, context); + context << ")"; + return context; + } + }; } #endif diff --git a/include/sqlpp11/limit.h b/include/sqlpp11/limit.h index 61e94d06..99a31928 100644 --- a/include/sqlpp11/limit.h +++ b/include/sqlpp11/limit.h @@ -33,151 +33,37 @@ namespace sqlpp { - // LIMIT DATA - template - struct limit_data_t - { - limit_data_t(Limit value): - _value(value) - {} - - limit_data_t(const limit_data_t&) = default; - limit_data_t(limit_data_t&&) = default; - limit_data_t& operator=(const limit_data_t&) = default; - limit_data_t& operator=(limit_data_t&&) = default; - ~limit_data_t() = default; - - Limit _value; - }; - - // LIMIT - template - struct limit_t - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits; - - static_assert(is_integral_t::value, "limit requires an integral value or integral parameter"); - - // Data - using _data_t = limit_data_t; - - // Member implementation with data and methods - template - struct _impl_t - { - _data_t _data; - }; - - // Member template for adding the named member to a statement - template - struct _member_t - { - using _data_t = limit_data_t; - - _impl_t limit; - _impl_t& operator()() { return limit; } - const _impl_t& operator()() const { return limit; } - - template - static auto _get_member(T t) -> decltype(t.limit) - { - return t.limit; - } - }; - - template - struct _methods_t - { - }; - }; - - // DYNAMIC LIMIT DATA - template - struct dynamic_limit_data_t - { - dynamic_limit_data_t(): - _value(noop()) - { - } - - template - dynamic_limit_data_t(Limit value): - _initialized(true), - _value(typename wrap_operand::type(value)) - { - } - - dynamic_limit_data_t(const dynamic_limit_data_t&) = default; - dynamic_limit_data_t(dynamic_limit_data_t&&) = default; - dynamic_limit_data_t& operator=(const dynamic_limit_data_t&) = default; - dynamic_limit_data_t& operator=(dynamic_limit_data_t&&) = default; - ~dynamic_limit_data_t() = default; - - bool _initialized = false; - interpretable_t _value; - }; - - // DYNAMIC LIMIT - template - struct dynamic_limit_t - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; - - // Data - using _data_t = dynamic_limit_data_t; - - // Member implementation with data and methods - template - struct _impl_t - { - template - void set(Limit value) - { - // FIXME: Make sure that Limit does not require external tables? Need to read up on SQL - using arg_t = typename wrap_operand::type; - _data._value = arg_t{value}; - _data._initialized = true; - } - public: - _data_t _data; - }; - - // Member template for adding the named member to a statement - template - struct _member_t - { - using _data_t = dynamic_limit_data_t; - - _impl_t limit; - _impl_t& operator()() { return limit; } - const _impl_t& operator()() const { return limit; } - - template - static auto _get_member(T t) -> decltype(t.limit) - { - return t.limit; - } - }; - - // Additional methods for the statement - template - struct _methods_t - { - }; - }; - - struct no_limit_t + // LIMIT DATA + template + struct limit_data_t { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; + limit_data_t(Limit value): + _value(value) + {} + + limit_data_t(const limit_data_t&) = default; + limit_data_t(limit_data_t&&) = default; + limit_data_t& operator=(const limit_data_t&) = default; + limit_data_t& operator=(limit_data_t&&) = default; + ~limit_data_t() = default; + + Limit _value; + }; + + // LIMIT + template + struct limit_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + + static_assert(is_integral_t::value, "limit requires an integral value or integral parameter"); // Data - using _data_t = no_data_t; + using _data_t = limit_data_t; // Member implementation with data and methods - template + template struct _impl_t { _data_t _data; @@ -187,71 +73,185 @@ namespace sqlpp template struct _member_t { - using _data_t = no_data_t; + using _data_t = limit_data_t; - _impl_t no_limit; - _impl_t& operator()() { return no_limit; } - const _impl_t& operator()() const { return no_limit; } + _impl_t limit; + _impl_t& operator()() { return limit; } + const _impl_t& operator()() const { return limit; } template - static auto _get_member(T t) -> decltype(t.no_limit) + static auto _get_member(T t) -> decltype(t.limit) { - return t.no_limit; + return t.limit; } }; template struct _methods_t { - using _database_t = typename Policies::_database_t; - template - using _new_statement_t = typename Policies::template _new_statement_t; - - template - auto limit(Arg arg) - -> _new_statement_t::type>> - { - return { *static_cast(this), limit_data_t::type>{{arg}} }; - } - - auto dynamic_limit() - -> _new_statement_t> - { - static_assert(not std::is_same<_database_t, void>::value, "dynamic_limit must not be called in a static statement"); - return { *static_cast(this), dynamic_limit_data_t<_database_t>{} }; - } }; }; - // Interpreters - template - struct serializer_t> + // DYNAMIC LIMIT DATA + template + struct dynamic_limit_data_t + { + dynamic_limit_data_t(): + _value(noop()) { - using T = dynamic_limit_data_t; + } - static Context& _(const T& t, Context& context) + template + dynamic_limit_data_t(Limit value): + _initialized(true), + _value(typename wrap_operand::type(value)) + { + } + + dynamic_limit_data_t(const dynamic_limit_data_t&) = default; + dynamic_limit_data_t(dynamic_limit_data_t&&) = default; + dynamic_limit_data_t& operator=(const dynamic_limit_data_t&) = default; + dynamic_limit_data_t& operator=(dynamic_limit_data_t&&) = default; + ~dynamic_limit_data_t() = default; + + bool _initialized = false; + interpretable_t _value; + }; + + // DYNAMIC LIMIT + template + struct dynamic_limit_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; + + // Data + using _data_t = dynamic_limit_data_t; + + // Member implementation with data and methods + template + struct _impl_t { - if (t._initialized) - { - context << " LIMIT "; - serialize(t._value, context); - } - return context; - } + template + void set(Limit value) + { + // FIXME: Make sure that Limit does not require external tables? Need to read up on SQL + using arg_t = typename wrap_operand::type; + _data._value = arg_t{value}; + _data._initialized = true; + } + public: + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = dynamic_limit_data_t; + + _impl_t limit; + _impl_t& operator()() { return limit; } + const _impl_t& operator()() const { return limit; } + + template + static auto _get_member(T t) -> decltype(t.limit) + { + return t.limit; + } + }; + + // Additional methods for the statement + template + struct _methods_t + { + }; + }; + + struct no_limit_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; + + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; }; - template - struct serializer_t> + // Member template for adding the named member to a statement + template + struct _member_t { - using T = limit_data_t; + using _data_t = no_data_t; - static Context& _(const T& t, Context& context) + _impl_t no_limit; + _impl_t& operator()() { return no_limit; } + const _impl_t& operator()() const { return no_limit; } + + template + static auto _get_member(T t) -> decltype(t.no_limit) + { + return t.no_limit; + } + }; + + template + struct _methods_t + { + using _database_t = typename Policies::_database_t; + template + using _new_statement_t = typename Policies::template _new_statement_t; + + template + auto limit(Arg arg) + -> _new_statement_t::type>> + { + return { *static_cast(this), limit_data_t::type>{{arg}} }; + } + + auto dynamic_limit() + -> _new_statement_t> + { + static_assert(not std::is_same<_database_t, void>::value, "dynamic_limit must not be called in a static statement"); + return { *static_cast(this), dynamic_limit_data_t<_database_t>{} }; + } + }; + }; + + // Interpreters + template + struct serializer_t> + { + using T = dynamic_limit_data_t; + + static Context& _(const T& t, Context& context) + { + if (t._initialized) { context << " LIMIT "; serialize(t._value, context); - return context; } - }; + return context; + } + }; + + template + struct serializer_t> + { + using T = limit_data_t; + + static Context& _(const T& t, Context& context) + { + context << " LIMIT "; + serialize(t._value, context); + return context; + } + }; } #endif diff --git a/include/sqlpp11/max.h b/include/sqlpp11/max.h index 78cb12f9..46489282 100644 --- a/include/sqlpp11/max.h +++ b/include/sqlpp11/max.h @@ -31,53 +31,53 @@ namespace sqlpp { - template + template struct max_t: public value_type_of::template expression_operators>, - public alias_operators> + public alias_operators> + { + using _traits = make_traits, ::sqlpp::tag::expression, ::sqlpp::tag::named_expression>; + using _recursive_traits = make_recursive_traits; + + static_assert(is_expression_t::value, "max() requires a value expression as argument"); + + struct _name_t { - using _traits = make_traits, ::sqlpp::tag::expression, ::sqlpp::tag::named_expression>; - using _recursive_traits = make_recursive_traits; - - static_assert(is_expression_t::value, "max() requires a value expression as argument"); - - struct _name_t - { - static constexpr const char* _get_name() { return "MAX"; } - template - struct _member_t - { - T max; - T& operator()() { return max; } - const T& operator()() const { return max; } - }; - }; - - max_t(Expr expr): - _expr(expr) - {} - - max_t(const max_t&) = default; - max_t(max_t&&) = default; - max_t& operator=(const max_t&) = default; - max_t& operator=(max_t&&) = default; - ~max_t() = default; - - Expr _expr; + static constexpr const char* _get_name() { return "MAX"; } + template + struct _member_t + { + T max; + T& operator()() { return max; } + const T& operator()() const { return max; } + }; }; - template - struct serializer_t> - { - using T = max_t; + max_t(Expr expr): + _expr(expr) + {} - static Context& _(const T& t, Context& context) - { - context << "MAX("; - serialize(t._expr, context); - context << ")"; - return context; - } - }; + max_t(const max_t&) = default; + max_t(max_t&&) = default; + max_t& operator=(const max_t&) = default; + max_t& operator=(max_t&&) = default; + ~max_t() = default; + + Expr _expr; + }; + + template + struct serializer_t> + { + using T = max_t; + + static Context& _(const T& t, Context& context) + { + context << "MAX("; + serialize(t._expr, context); + context << ")"; + return context; + } + }; template auto max(T t) -> typename max_t> diff --git a/include/sqlpp11/min.h b/include/sqlpp11/min.h index 28e72f21..0ae1248a 100644 --- a/include/sqlpp11/min.h +++ b/include/sqlpp11/min.h @@ -31,53 +31,53 @@ namespace sqlpp { - template + template struct min_t: public value_type_of::template expression_operators>, - public alias_operators> + public alias_operators> + { + using _traits = make_traits, ::sqlpp::tag::expression, ::sqlpp::tag::named_expression>; + using _recursive_traits = make_recursive_traits; + + static_assert(is_expression_t::value, "min() requires a value expression as argument"); + + struct _name_t { - using _traits = make_traits, ::sqlpp::tag::expression, ::sqlpp::tag::named_expression>; - using _recursive_traits = make_recursive_traits; - - static_assert(is_expression_t::value, "min() requires a value expression as argument"); - - struct _name_t - { - static constexpr const char* _get_name() { return "MIN"; } - template - struct _member_t - { - T min; - T& operator()() { return min; } - const T& operator()() const { return min; } - }; - }; - - min_t(Expr expr): - _expr(expr) - {} - - min_t(const min_t&) = default; - min_t(min_t&&) = default; - min_t& operator=(const min_t&) = default; - min_t& operator=(min_t&&) = default; - ~min_t() = default; - - Expr _expr; + static constexpr const char* _get_name() { return "MIN"; } + template + struct _member_t + { + T min; + T& operator()() { return min; } + const T& operator()() const { return min; } + }; }; - template - struct serializer_t> - { - using T = min_t; + min_t(Expr expr): + _expr(expr) + {} - static Context& _(const T& t, Context& context) - { - context << "MIN("; - serialize(t._expr, context); - context << ")"; - return context; - } - }; + min_t(const min_t&) = default; + min_t(min_t&&) = default; + min_t& operator=(const min_t&) = default; + min_t& operator=(min_t&&) = default; + ~min_t() = default; + + Expr _expr; + }; + + template + struct serializer_t> + { + using T = min_t; + + static Context& _(const T& t, Context& context) + { + context << "MIN("; + serialize(t._expr, context); + context << ")"; + return context; + } + }; template auto min(T t) -> typename min_t> diff --git a/include/sqlpp11/multi_column.h b/include/sqlpp11/multi_column.h index 6484ba96..52de9d5f 100644 --- a/include/sqlpp11/multi_column.h +++ b/include/sqlpp11/multi_column.h @@ -110,28 +110,28 @@ namespace sqlpp std::tuple _columns; }; - template - struct serializer_t> + template + struct serializer_t> + { + using T = multi_column_t; + + static void _(const T& t, Context& context) { - using T = multi_column_t; + static_assert(wrong_t::value, "multi_column must be used with an alias"); + } + }; - static void _(const T& t, Context& context) - { - static_assert(wrong_t::value, "multi_column must be used with an alias"); - } - }; + template + struct serializer_t> + { + using T = multi_column_alias_t; - template - struct serializer_t> + static Context& _(const T& t, Context& context) { - using T = multi_column_alias_t; - - static Context& _(const T& t, Context& context) - { - interpret_tuple(t._columns, ',', context); - return context; - } - }; + interpret_tuple(t._columns, ',', context); + return context; + } + }; namespace detail { diff --git a/include/sqlpp11/named_interpretable.h b/include/sqlpp11/named_interpretable.h index 8e91d06c..4aa93fa2 100644 --- a/include/sqlpp11/named_interpretable.h +++ b/include/sqlpp11/named_interpretable.h @@ -33,104 +33,104 @@ namespace sqlpp { - template - struct named_interpretable_t + template + struct named_interpretable_t + { + using _serializer_context_t = typename Db::_serializer_context_t; + using _interpreter_context_t = typename Db::_interpreter_context_t; + + template + named_interpretable_t(T t): + _impl(std::make_shared<_impl_t>(t)) + {} + + named_interpretable_t(const named_interpretable_t&) = default; + named_interpretable_t(named_interpretable_t&&) = default; + named_interpretable_t& operator=(const named_interpretable_t&) = default; + named_interpretable_t& operator=(named_interpretable_t&&) = default; + ~named_interpretable_t() = default; + + sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const { - using _serializer_context_t = typename Db::_serializer_context_t; - using _interpreter_context_t = typename Db::_interpreter_context_t; + return _impl->serialize(context); + } - template - named_interpretable_t(T t): - _impl(std::make_shared<_impl_t>(t)) - {} - - named_interpretable_t(const named_interpretable_t&) = default; - named_interpretable_t(named_interpretable_t&&) = default; - named_interpretable_t& operator=(const named_interpretable_t&) = default; - named_interpretable_t& operator=(named_interpretable_t&&) = default; - ~named_interpretable_t() = default; - - sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const - { - return _impl->serialize(context); - } - - // This method only exists if Db::_serializer_context_t and sqlpp::serializer_context_t are not the same - template + // This method only exists if Db::_serializer_context_t and sqlpp::serializer_context_t are not the same + template auto serialize(Context& context) const -> typename std::enable_if::value - and not std::is_same::value, Context&>::type + and not std::is_same::value, Context&>::type { return _impl->db_serialize(context); } + _interpreter_context_t& interpret(_interpreter_context_t& context) const + { + return _impl->interpret(context); + } + + std::string _get_name() const + { + _impl->_get_name(); + } + + private: + struct _impl_base + { + virtual sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const = 0; + virtual _serializer_context_t& db_serialize(_serializer_context_t& context) const = 0; + virtual _interpreter_context_t& interpret(_interpreter_context_t& context) const = 0; + virtual std::string _get_name() const = 0; + }; + + template + struct _impl_t: public _impl_base + { + static_assert(not make_parameter_list_t::type::size::value, "parameters not supported in dynamic statement parts"); + _impl_t(T t): + _t(t) + {} + + sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const + { + sqlpp::serialize(_t, context); + return context; + } + + _serializer_context_t& db_serialize(_serializer_context_t& context) const + { + Db::_serialize_interpretable(_t, context); + return context; + } + _interpreter_context_t& interpret(_interpreter_context_t& context) const { - return _impl->interpret(context); + Db::_interpret_interpretable(_t, context); + return context; } std::string _get_name() const { - _impl->_get_name(); + return T::_name_t::_get_name(); } - private: - struct _impl_base - { - virtual sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const = 0; - virtual _serializer_context_t& db_serialize(_serializer_context_t& context) const = 0; - virtual _interpreter_context_t& interpret(_interpreter_context_t& context) const = 0; - virtual std::string _get_name() const = 0; - }; - - template - struct _impl_t: public _impl_base - { - static_assert(not make_parameter_list_t::type::size::value, "parameters not supported in dynamic statement parts"); - _impl_t(T t): - _t(t) - {} - - sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const - { - sqlpp::serialize(_t, context); - return context; - } - - _serializer_context_t& db_serialize(_serializer_context_t& context) const - { - Db::_serialize_interpretable(_t, context); - return context; - } - - _interpreter_context_t& interpret(_interpreter_context_t& context) const - { - Db::_interpret_interpretable(_t, context); - return context; - } - - std::string _get_name() const - { - return T::_name_t::_get_name(); - } - - T _t; - }; - - std::shared_ptr _impl; + T _t; }; - template - struct serializer_t> + std::shared_ptr _impl; + }; + + template + struct serializer_t> + { + using T = named_interpretable_t; + + static Context& _(const T& t, Context& context) { - using T = named_interpretable_t; - - static Context& _(const T& t, Context& context) - { - t.serialize(context); - return context; - } - }; + t.serialize(context); + return context; + } + }; } diff --git a/include/sqlpp11/noop.h b/include/sqlpp11/noop.h index 57ca5e14..74198fd0 100644 --- a/include/sqlpp11/noop.h +++ b/include/sqlpp11/noop.h @@ -34,44 +34,44 @@ namespace sqlpp { #warning: Need extra include file for no_data - struct no_data_t {}; + struct no_data_t {}; - template - struct serializer_t - { - using T = no_data_t; - - static Context& _(const T& t, Context& context) - { - return context; - } - }; - - struct noop + template + struct serializer_t { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; + using T = no_data_t; - struct _name_t {}; - - template - struct _result_methods_t - {}; + static Context& _(const T& t, Context& context) + { + return context; + } }; - template - struct serializer_t + struct noop + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; + + struct _name_t {}; + + template + struct _result_methods_t + {}; + }; + + template + struct serializer_t + { + using T = noop; + + static Context& _(const T& t, Context& context) { - using T = noop; + return context; + } + }; - static Context& _(const T& t, Context& context) - { - return context; - } - }; - - template - struct is_noop: std::is_same {}; + template + struct is_noop: std::is_same {}; } #endif diff --git a/include/sqlpp11/noop_fwd.h b/include/sqlpp11/noop_fwd.h index 4936e858..0c87c75e 100644 --- a/include/sqlpp11/noop_fwd.h +++ b/include/sqlpp11/noop_fwd.h @@ -29,9 +29,9 @@ namespace sqlpp { - struct noop; + struct noop; - template - struct is_noop; + template + struct is_noop; } #endif diff --git a/include/sqlpp11/null.h b/include/sqlpp11/null.h index f78ce12d..a3309b15 100644 --- a/include/sqlpp11/null.h +++ b/include/sqlpp11/null.h @@ -37,17 +37,17 @@ namespace sqlpp using _recursive_traits = make_recursive_traits<>; }; - template - struct serializer_t - { - using Operand = null_t; + template + struct serializer_t + { + using Operand = null_t; - static Context& _(const Operand& t, Context& context) - { - context << "NULL"; - return context; - } - }; + static Context& _(const Operand& t, Context& context) + { + context << "NULL"; + return context; + } + }; constexpr null_t null = {}; diff --git a/include/sqlpp11/offset.h b/include/sqlpp11/offset.h index 1a9eb8e2..9d89674c 100644 --- a/include/sqlpp11/offset.h +++ b/include/sqlpp11/offset.h @@ -33,161 +33,37 @@ namespace sqlpp { - // OFFSET DATA - template - struct offset_data_t - { - offset_data_t(Offset value): - _value(value) - {} - - offset_data_t(const offset_data_t&) = default; - offset_data_t(offset_data_t&&) = default; - offset_data_t& operator=(const offset_data_t&) = default; - offset_data_t& operator=(offset_data_t&&) = default; - ~offset_data_t() = default; - - Offset _value; - }; - - // OFFSET - template - struct offset_t - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits; - - static_assert(is_integral_t::value, "offset requires an integral value or integral parameter"); - - // Data - using _data_t = offset_data_t; - - // Member implementation with data and methods - template - struct _impl_t - { - _data_t _data; - }; - - // Member template for adding the named member to a statement - template - struct _member_t - { - using _data_t = offset_data_t; - - _impl_t offset; - _impl_t& operator()() { return offset; } - const _impl_t& operator()() const { return offset; } - - template - static auto _get_member(T t) -> decltype(t.offset) - { - return t.offset; - } - }; - - template - struct _methods_t - { - }; - }; - - // DYNAMIC OFFSET DATA - template - struct dynamic_offset_data_t - { - dynamic_offset_data_t(): - _value(noop()) - { - } - - template - dynamic_offset_data_t(Offset value): - _initialized(true), - _value(typename wrap_operand::type(value)) - { - } - - dynamic_offset_data_t(const dynamic_offset_data_t&) = default; - dynamic_offset_data_t(dynamic_offset_data_t&&) = default; - dynamic_offset_data_t& operator=(const dynamic_offset_data_t&) = default; - dynamic_offset_data_t& operator=(dynamic_offset_data_t&&) = default; - ~dynamic_offset_data_t() = default; - - bool _initialized = false; - interpretable_t _value; - }; - - // DYNAMIC OFFSET - template - struct dynamic_offset_t - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; - - // Data - using _data_t = dynamic_offset_data_t; - - // Member implementation with data and methods - template - struct _impl_t - { - template - void set(Offset value) - { - // FIXME: Make sure that Offset does not require external tables? Need to read up on SQL - using arg_t = typename wrap_operand::type; - _data._value = arg_t{value}; - _data._initialized = true; - } - public: - _data_t _data; - }; - - // Member template for adding the named member to a statement - template - struct _member_t - { - using _data_t = dynamic_offset_data_t; - - _impl_t offset; - _impl_t& operator()() { return offset; } - const _impl_t& operator()() const { return offset; } - - template - static auto _get_member(T t) -> decltype(t.offset) - { - return t.offset; - } - }; - - template - struct _methods_t - { - template - void set_offset(Offset value) - { - // FIXME: Make sure that Offset does not require external tables? Need to read up on SQL - using arg_t = typename wrap_operand::type; - static_cast(this)->_offset()._value = arg_t{value}; - static_cast(this)->_offset()._initialized = true; - } - }; - - bool _initialized = false; - interpretable_t _value; - }; - - struct no_offset_t + // OFFSET DATA + template + struct offset_data_t { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; + offset_data_t(Offset value): + _value(value) + {} + + offset_data_t(const offset_data_t&) = default; + offset_data_t(offset_data_t&&) = default; + offset_data_t& operator=(const offset_data_t&) = default; + offset_data_t& operator=(offset_data_t&&) = default; + ~offset_data_t() = default; + + Offset _value; + }; + + // OFFSET + template + struct offset_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + + static_assert(is_integral_t::value, "offset requires an integral value or integral parameter"); // Data - using _data_t = no_data_t; + using _data_t = offset_data_t; // Member implementation with data and methods - template + template struct _impl_t { _data_t _data; @@ -197,71 +73,195 @@ namespace sqlpp template struct _member_t { - using _data_t = no_data_t; + using _data_t = offset_data_t; - _impl_t no_offset; - _impl_t& operator()() { return no_offset; } - const _impl_t& operator()() const { return no_offset; } + _impl_t offset; + _impl_t& operator()() { return offset; } + const _impl_t& operator()() const { return offset; } template - static auto _get_member(T t) -> decltype(t.no_offset) + static auto _get_member(T t) -> decltype(t.offset) { - return t.no_offset; + return t.offset; } }; template struct _methods_t { - using _database_t = typename Policies::_database_t; - template - using _new_statement_t = typename Policies::template _new_statement_t; - - template - auto offset(Arg arg) - -> _new_statement_t::type>> - { - return { *static_cast(this), offset_data_t::type>{{arg}} }; - } - - auto dynamic_offset() - -> _new_statement_t> - { - static_assert(not std::is_same<_database_t, void>::value, "dynamic_offset must not be called in a static statement"); - return { *static_cast(this), dynamic_offset_data_t<_database_t>{} }; - } }; }; - // Interpreters - template - struct serializer_t> + // DYNAMIC OFFSET DATA + template + struct dynamic_offset_data_t + { + dynamic_offset_data_t(): + _value(noop()) { - using T = offset_data_t; + } - static Context& _(const T& t, Context& context) + template + dynamic_offset_data_t(Offset value): + _initialized(true), + _value(typename wrap_operand::type(value)) + { + } + + dynamic_offset_data_t(const dynamic_offset_data_t&) = default; + dynamic_offset_data_t(dynamic_offset_data_t&&) = default; + dynamic_offset_data_t& operator=(const dynamic_offset_data_t&) = default; + dynamic_offset_data_t& operator=(dynamic_offset_data_t&&) = default; + ~dynamic_offset_data_t() = default; + + bool _initialized = false; + interpretable_t _value; + }; + + // DYNAMIC OFFSET + template + struct dynamic_offset_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; + + // Data + using _data_t = dynamic_offset_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + template + void set(Offset value) + { + // FIXME: Make sure that Offset does not require external tables? Need to read up on SQL + using arg_t = typename wrap_operand::type; + _data._value = arg_t{value}; + _data._initialized = true; + } + public: + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = dynamic_offset_data_t; + + _impl_t offset; + _impl_t& operator()() { return offset; } + const _impl_t& operator()() const { return offset; } + + template + static auto _get_member(T t) -> decltype(t.offset) + { + return t.offset; + } + }; + + template + struct _methods_t + { + template + void set_offset(Offset value) + { + // FIXME: Make sure that Offset does not require external tables? Need to read up on SQL + using arg_t = typename wrap_operand::type; + static_cast(this)->_offset()._value = arg_t{value}; + static_cast(this)->_offset()._initialized = true; + } + }; + + bool _initialized = false; + interpretable_t _value; + }; + + struct no_offset_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; + + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; + + _impl_t no_offset; + _impl_t& operator()() { return no_offset; } + const _impl_t& operator()() const { return no_offset; } + + template + static auto _get_member(T t) -> decltype(t.no_offset) + { + return t.no_offset; + } + }; + + template + struct _methods_t + { + using _database_t = typename Policies::_database_t; + template + using _new_statement_t = typename Policies::template _new_statement_t; + + template + auto offset(Arg arg) + -> _new_statement_t::type>> + { + return { *static_cast(this), offset_data_t::type>{{arg}} }; + } + + auto dynamic_offset() + -> _new_statement_t> + { + static_assert(not std::is_same<_database_t, void>::value, "dynamic_offset must not be called in a static statement"); + return { *static_cast(this), dynamic_offset_data_t<_database_t>{} }; + } + }; + }; + + // Interpreters + template + struct serializer_t> + { + using T = offset_data_t; + + static Context& _(const T& t, Context& context) + { + context << " OFFSET "; + serialize(t._value, context); + return context; + } + }; + + template + struct serializer_t> + { + using T = dynamic_offset_data_t; + + static Context& _(const T& t, Context& context) + { + if (t._initialized) { context << " OFFSET "; serialize(t._value, context); - return context; } - }; - - template - struct serializer_t> - { - using T = dynamic_offset_data_t; - - static Context& _(const T& t, Context& context) - { - if (t._initialized) - { - context << " OFFSET "; - serialize(t._value, context); - } - return context; - } - }; + return context; + } + }; } #endif diff --git a/include/sqlpp11/on.h b/include/sqlpp11/on.h index 224cc652..26b93a9f 100644 --- a/include/sqlpp11/on.h +++ b/include/sqlpp11/on.h @@ -56,23 +56,23 @@ namespace sqlpp interpretable_list_t _dynamic_expressions; }; - template - struct serializer_t> - { - using T = on_t; + template + struct serializer_t> + { + using T = on_t; - static Context& _(const T& t, Context& context) - { - if (sizeof...(Expr) == 0 and t._dynamic_expressions.empty()) - return context; - context << " ON "; - interpret_tuple(t._expressions, " AND ", context); - if (sizeof...(Expr) and not t._dynamic_expressions.empty()) - context << " AND "; - interpret_list(t._dynamic_expressions, " AND ", context); + static Context& _(const T& t, Context& context) + { + if (sizeof...(Expr) == 0 and t._dynamic_expressions.empty()) return context; - } - }; + context << " ON "; + interpret_tuple(t._expressions, " AND ", context); + if (sizeof...(Expr) and not t._dynamic_expressions.empty()) + context << " AND "; + interpret_list(t._dynamic_expressions, " AND ", context); + return context; + } + }; } diff --git a/include/sqlpp11/order_by.h b/include/sqlpp11/order_by.h index f431224f..0f9fdc75 100644 --- a/include/sqlpp11/order_by.h +++ b/include/sqlpp11/order_by.h @@ -37,113 +37,74 @@ namespace sqlpp { - // ORDER BY DATA - template - struct order_by_data_t - { - order_by_data_t(Expressions... expressions): - _expressions(expressions...) - {} - - order_by_data_t(const order_by_data_t&) = default; - order_by_data_t(order_by_data_t&&) = default; - order_by_data_t& operator=(const order_by_data_t&) = default; - order_by_data_t& operator=(order_by_data_t&&) = default; - ~order_by_data_t() = default; - - std::tuple _expressions; - interpretable_list_t _dynamic_expressions; - }; - - // ORDER BY - template - struct order_by_t - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits; - - using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - - static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression (e.g. a column) required in order_by()"); - - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in order_by()"); - - static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an expression in order_by()"); - - // Data - using _data_t = order_by_data_t; - - // Member implementation with data and methods - template - struct _impl_t - { - template - void add_ntc(Expression expression) - { - add(expression); - } - - template - void add(Expression expression) - { - static_assert(_is_dynamic::value, "add() must not be called for static order_by"); - static_assert(is_expression_t::value, "invalid expression argument in order_by::add()"); - static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in order_by::add()"); - - using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; - - _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert - } - - private: - template - void _add_impl(Expression expression, const std::true_type&) - { - return _data._dynamic_expressions.emplace_back(expression); - } - - template - void _add_impl(Expression expression, const std::false_type&); - public: - _data_t _data; - }; - - // Member template for adding the named member to a statement - template - struct _member_t - { - using _data_t = order_by_data_t; - - _impl_t order_by; - _impl_t& operator()() { return order_by; } - const _impl_t& operator()() const { return order_by; } - - template - static auto _get_member(T t) -> decltype(t.order_by) - { - return t.order_by; - } - }; - - template - struct _methods_t - { - }; - }; - - // NO ORDER BY YET - struct no_order_by_t + // ORDER BY DATA + template + struct order_by_data_t { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; + order_by_data_t(Expressions... expressions): + _expressions(expressions...) + {} + + order_by_data_t(const order_by_data_t&) = default; + order_by_data_t(order_by_data_t&&) = default; + order_by_data_t& operator=(const order_by_data_t&) = default; + order_by_data_t& operator=(order_by_data_t&&) = default; + ~order_by_data_t() = default; + + std::tuple _expressions; + interpretable_list_t _dynamic_expressions; + }; + + // ORDER BY + template + struct order_by_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + + using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; + + static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression (e.g. a column) required in order_by()"); + + static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in order_by()"); + + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an expression in order_by()"); // Data - using _data_t = no_data_t; + using _data_t = order_by_data_t; // Member implementation with data and methods template struct _impl_t { + template + void add_ntc(Expression expression) + { + add(expression); + } + + template + void add(Expression expression) + { + static_assert(_is_dynamic::value, "add() must not be called for static order_by"); + static_assert(is_expression_t::value, "invalid expression argument in order_by::add()"); + static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in order_by::add()"); + + using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; + + _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert + } + + private: + template + void _add_impl(Expression expression, const std::true_type&) + { + return _data._dynamic_expressions.emplace_back(expression); + } + + template + void _add_impl(Expression expression, const std::false_type&); + public: _data_t _data; }; @@ -151,61 +112,100 @@ namespace sqlpp template struct _member_t { - using _data_t = no_data_t; + using _data_t = order_by_data_t; - _impl_t no_order_by; - _impl_t& operator()() { return no_order_by; } - const _impl_t& operator()() const { return no_order_by; } + _impl_t order_by; + _impl_t& operator()() { return order_by; } + const _impl_t& operator()() const { return order_by; } template - static auto _get_member(T t) -> decltype(t.no_order_by) + static auto _get_member(T t) -> decltype(t.order_by) { - return t.no_order_by; + return t.order_by; } }; template struct _methods_t { - using _database_t = typename Policies::_database_t; - template - using _new_statement_t = typename Policies::template _new_statement_t; - - template - auto order_by(Args... args) - -> _new_statement_t> - { - return { *static_cast(this), order_by_data_t{args...} }; - } - - template - auto dynamic_order_by(Args... args) - -> _new_statement_t> - { - static_assert(not std::is_same<_database_t, void>::value, "dynamic_order_by must not be called in a static statement"); - return { *static_cast(this), order_by_data_t<_database_t, Args...>{args...} }; - } }; }; - // Interpreters - template - struct serializer_t> - { - using T = order_by_data_t; + // NO ORDER BY YET + struct no_order_by_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; - static Context& _(const T& t, Context& context) - { - if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty()) - return context; - context << " ORDER BY "; - interpret_tuple(t._expressions, ',', context); - if (sizeof...(Expressions) and not t._dynamic_expressions.empty()) - context << ','; - interpret_list(t._dynamic_expressions, ',', context); - return context; - } + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; + + _impl_t no_order_by; + _impl_t& operator()() { return no_order_by; } + const _impl_t& operator()() const { return no_order_by; } + + template + static auto _get_member(T t) -> decltype(t.no_order_by) + { + return t.no_order_by; + } + }; + + template + struct _methods_t + { + using _database_t = typename Policies::_database_t; + template + using _new_statement_t = typename Policies::template _new_statement_t; + + template + auto order_by(Args... args) + -> _new_statement_t> + { + return { *static_cast(this), order_by_data_t{args...} }; + } + + template + auto dynamic_order_by(Args... args) + -> _new_statement_t> + { + static_assert(not std::is_same<_database_t, void>::value, "dynamic_order_by must not be called in a static statement"); + return { *static_cast(this), order_by_data_t<_database_t, Args...>{args...} }; + } + }; + }; + + // Interpreters + template + struct serializer_t> + { + using T = order_by_data_t; + + static Context& _(const T& t, Context& context) + { + if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty()) + return context; + context << " ORDER BY "; + interpret_tuple(t._expressions, ',', context); + if (sizeof...(Expressions) and not t._dynamic_expressions.empty()) + context << ','; + interpret_list(t._dynamic_expressions, ',', context); + return context; + } + }; } #endif diff --git a/include/sqlpp11/parameter.h b/include/sqlpp11/parameter.h index b582b805..3cf45236 100644 --- a/include/sqlpp11/parameter.h +++ b/include/sqlpp11/parameter.h @@ -34,7 +34,7 @@ namespace sqlpp { template - struct parameter_t: public ValueType::template expression_operators> + struct parameter_t: public ValueType::template expression_operators> { using _traits = make_traits; struct _recursive_traits @@ -57,17 +57,17 @@ namespace sqlpp ~parameter_t() = default; }; - template - struct serializer_t> - { - using T = parameter_t; + template + struct serializer_t> + { + using T = parameter_t; - static Context& _(const T& t, Context& context) - { - context << "?"; - return context; - } - }; + static Context& _(const T& t, Context& context) + { + context << "?"; + return context; + } + }; template auto parameter(const NamedExpr&) diff --git a/include/sqlpp11/policy_update.h b/include/sqlpp11/policy_update.h index 5183767b..ecb61181 100644 --- a/include/sqlpp11/policy_update.h +++ b/include/sqlpp11/policy_update.h @@ -31,24 +31,24 @@ namespace sqlpp { - template - struct policy_update_impl - { - template - using _policy_t = typename std::conditional::value, Replacement, T>::type; - }; + template + struct policy_update_impl + { + template + using _policy_t = typename std::conditional::value, Replacement, T>::type; + }; - template - using policy_update_t = typename policy_update_impl::template _policy_t; + template + using policy_update_t = typename policy_update_impl::template _policy_t; - template - struct update_policies_impl - { - using type = typename Original::template _policy_update_t; - }; + template + struct update_policies_impl + { + using type = typename Original::template _policy_update_t; + }; - template - using update_policies_t = typename update_policies_impl::type; + template + using update_policies_t = typename update_policies_impl::type; } diff --git a/include/sqlpp11/prepared_insert.h b/include/sqlpp11/prepared_insert.h index 63a995df..c6f963e7 100644 --- a/include/sqlpp11/prepared_insert.h +++ b/include/sqlpp11/prepared_insert.h @@ -40,9 +40,9 @@ namespace sqlpp auto _run(Db& db) const -> size_t - { - return db.run_prepared_insert(*this); - } + { + return db.run_prepared_insert(*this); + } void _bind_params() const { diff --git a/include/sqlpp11/prepared_remove.h b/include/sqlpp11/prepared_remove.h index 21e72986..593f75ce 100644 --- a/include/sqlpp11/prepared_remove.h +++ b/include/sqlpp11/prepared_remove.h @@ -40,9 +40,9 @@ namespace sqlpp auto _run(Db& db) const -> size_t - { - return db.run_prepared_insert(*this); - } + { + return db.run_prepared_insert(*this); + } void _bind_params() const { diff --git a/include/sqlpp11/prepared_select.h b/include/sqlpp11/prepared_select.h index 0cdb56b4..fab451ca 100644 --- a/include/sqlpp11/prepared_select.h +++ b/include/sqlpp11/prepared_select.h @@ -42,9 +42,9 @@ namespace sqlpp auto _run(Database& db) const -> result_t - { - return {db.run_prepared_select(*this), _dynamic_names}; - } + { + return {db.run_prepared_select(*this), _dynamic_names}; + } void _bind_params() const { diff --git a/include/sqlpp11/prepared_update.h b/include/sqlpp11/prepared_update.h index a6206e9e..071ee404 100644 --- a/include/sqlpp11/prepared_update.h +++ b/include/sqlpp11/prepared_update.h @@ -40,9 +40,9 @@ namespace sqlpp auto _run(Db& db) const -> size_t - { - return db.run_prepared_insert(*this); - } + { + return db.run_prepared_insert(*this); + } void _bind_params() const { diff --git a/include/sqlpp11/remove.h b/include/sqlpp11/remove.h index 54ffcbc1..f3b0a722 100644 --- a/include/sqlpp11/remove.h +++ b/include/sqlpp11/remove.h @@ -79,26 +79,26 @@ namespace sqlpp }; - template - struct serializer_t + template + struct serializer_t + { + using T = remove_name_t; + + static Context& _(const T& t, Context& context) { - using T = remove_name_t; + context << "DELETE"; - static Context& _(const T& t, Context& context) - { - context << "DELETE"; - - return context; - } - }; + return context; + } + }; template using blank_remove_t = statement_t; + remove_t, + no_from_t, + no_using_t, + no_extra_tables_t, + no_where_t>; auto remove() -> blank_remove_t diff --git a/include/sqlpp11/result.h b/include/sqlpp11/result.h index 314ffc26..f24eee85 100644 --- a/include/sqlpp11/result.h +++ b/include/sqlpp11/result.h @@ -45,12 +45,12 @@ namespace sqlpp result_t() = default; template - result_t(db_result_t&& result, const DynamicNames& dynamic_names): - _result(std::move(result)), - _result_row(dynamic_names) - { - _result.next(_result_row); - } + result_t(db_result_t&& result, const DynamicNames& dynamic_names): + _result(std::move(result)), + _result_row(dynamic_names) + { + _result.next(_result_row); + } result_t(const result_t&) = delete; result_t(result_t&&) = default; diff --git a/include/sqlpp11/result_row.h b/include/sqlpp11/result_row.h index 2f31c117..ce4d4eb3 100644 --- a/include/sqlpp11/result_row.h +++ b/include/sqlpp11/result_row.h @@ -43,48 +43,48 @@ namespace sqlpp template struct result_field: public NamedExpr::_name_t::template _member_t::template _result_entry_t> + { + using _field = typename NamedExpr::_name_t::template _member_t::template _result_entry_t>; + + result_field() = default; + result_field(const char_result_row_t& char_result_row_t): + _field({{char_result_row_t.data[index], char_result_row_t.len[index]}}) + { + } + + result_field& operator=(const char_result_row_t& char_result_row_t) { - using _field = typename NamedExpr::_name_t::template _member_t::template _result_entry_t>; + _field::operator()().assign(char_result_row_t.data[index], char_result_row_t.len[index]); + return *this; + } - result_field() = default; - result_field(const char_result_row_t& char_result_row_t): - _field({{char_result_row_t.data[index], char_result_row_t.len[index]}}) - { - } + void validate() + { + _field::operator()().validate(); + } - result_field& operator=(const char_result_row_t& char_result_row_t) - { - _field::operator()().assign(char_result_row_t.data[index], char_result_row_t.len[index]); - return *this; - } + void invalidate() + { + _field::operator()().invalidate(); + } - void validate() - { - _field::operator()().validate(); - } - - void invalidate() - { - _field::operator()().invalidate(); - } - - template + template void _bind(Target& target) { _field::operator()()._bind(target, index); } - }; + }; template struct result_field>>: - public AliasProvider::_name_t::template _member_t, NamedExprs...>> + public AliasProvider::_name_t::template _member_t, NamedExprs...>> { using _multi_field = typename AliasProvider::_name_t::template _member_t, NamedExprs...>>; result_field() = default; result_field(const char_result_row_t& char_result_row_t): _multi_field({char_result_row_t}) - {} + {} result_field& operator=(const char_result_row_t& char_result_row_t) { @@ -103,15 +103,15 @@ namespace sqlpp } template - void _bind(Target& target) - { - _multi_field::operator()()._bind(target); - } + void _bind(Target& target) + { + _multi_field::operator()()._bind(target); + } }; template struct result_row_impl, NamedExprs...>: - public result_field... + public result_field... { static constexpr std::size_t _last_index = LastIndex; result_row_impl() = default; @@ -140,17 +140,17 @@ namespace sqlpp } template - void _bind(Target& target) - { - using swallow = int[]; - (void) swallow{(result_field::_bind(target), 0)...}; - } + void _bind(Target& target) + { + using swallow = int[]; + (void) swallow{(result_field::_bind(target), 0)...}; + } }; } template - struct result_row_t: public detail::result_row_impl, NamedExprs...> + struct result_row_t: public detail::result_row_impl, NamedExprs...> { using _impl = detail::result_row_impl, NamedExprs...>; bool _is_valid; @@ -163,9 +163,9 @@ namespace sqlpp } template - result_row_t(const DynamicNames&): - _impl(), - _is_valid(false) + result_row_t(const DynamicNames&): + _impl(), + _is_valid(false) { } @@ -216,7 +216,7 @@ namespace sqlpp }; template - struct dynamic_result_row_t: public detail::result_row_impl, NamedExprs...> + struct dynamic_result_row_t: public detail::result_row_impl, NamedExprs...> { using _impl = detail::result_row_impl, NamedExprs...>; using _field_type = detail::text::_result_entry_t; diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index c014abe4..0c5b320f 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -51,32 +51,32 @@ namespace sqlpp struct select_t: public statement_name_t {}; - template - struct serializer_t + template + struct serializer_t + { + using T = select_name_t; + + static Context& _(const T& t, Context& context) { - using T = select_name_t; + context << "SELECT "; - static Context& _(const T& t, Context& context) - { - context << "SELECT "; - - return context; - } - }; + return context; + } + }; template using blank_select_t = statement_t; + select_t, + no_select_flag_list_t, + no_select_column_list_t, + no_from_t, + no_extra_tables_t, + no_where_t, + no_group_by_t, + no_having_t, + no_order_by_t, + no_limit_t, + no_offset_t>; blank_select_t select() // FIXME: These should be constexpr diff --git a/include/sqlpp11/select_column_list.h b/include/sqlpp11/select_column_list.h index efdaf8ed..7dc7937c 100644 --- a/include/sqlpp11/select_column_list.h +++ b/include/sqlpp11/select_column_list.h @@ -59,256 +59,256 @@ namespace sqlpp }; } - template - struct dynamic_select_column_list - { - using _names_t = std::vector; - std::vector> _dynamic_columns; - _names_t _dynamic_expression_names; + template + struct dynamic_select_column_list + { + using _names_t = std::vector; + std::vector> _dynamic_columns; + _names_t _dynamic_expression_names; - template - void emplace_back(Expr expr) - { - _dynamic_expression_names.push_back(Expr::_name_t::_get_name()); - _dynamic_columns.emplace_back(expr); - } - - bool empty() const + template + void emplace_back(Expr expr) { - return _dynamic_columns.empty(); + _dynamic_expression_names.push_back(Expr::_name_t::_get_name()); + _dynamic_columns.emplace_back(expr); } - }; - template<> - struct dynamic_select_column_list + bool empty() const { - struct _names_t + return _dynamic_columns.empty(); + } + }; + + template<> + struct dynamic_select_column_list + { + struct _names_t + { + static constexpr size_t size() { return 0; } + }; + _names_t _dynamic_expression_names; + + static constexpr bool empty() + { + return true; + } + }; + + template + struct serializer_t> + { + using T = dynamic_select_column_list; + + static Context& _(const T& t, Context& context) + { + bool first = true; + for (const auto column : t._dynamic_columns) { - static constexpr size_t size() { return 0; } + if (first) + first = false; + else + context << ','; + serialize(column, context); + } + return context; + } + }; + + template + struct serializer_t> + { + using T = dynamic_select_column_list; + + static Context& _(const T& t, Context& context) + { + return context; + } + }; + + // SELECTED COLUMNS DATA + template + struct select_column_list_data_t + { + using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; + + select_column_list_data_t(Columns... columns): + _columns(columns...) + {} + + select_column_list_data_t(std::tuple columns): + _columns(columns) + {} + + select_column_list_data_t(const select_column_list_data_t&) = default; + select_column_list_data_t(select_column_list_data_t&&) = default; + select_column_list_data_t& operator=(const select_column_list_data_t&) = default; + select_column_list_data_t& operator=(select_column_list_data_t&&) = default; + ~select_column_list_data_t() = default; + + std::tuple _columns; + dynamic_select_column_list _dynamic_columns; + }; + + + // SELECTED COLUMNS + template + struct select_column_list_t + { + using _traits = typename ::sqlpp::detail::select_traits::_traits; + using _recursive_traits = make_recursive_traits; + + using _name_t = typename ::sqlpp::detail::select_traits::_name_t; + + using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; + + static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected"); + + static_assert(::sqlpp::detail::all_t<(is_named_expression_t::value or is_multi_column_t::value)...>::value, "at least one argument is not a named expression"); + + static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate name detected"); + + struct _column_type {}; + + // Data + using _data_t = select_column_list_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + template + void add_ntc(NamedExpression namedExpression) + { + add(namedExpression); + } + + template + void add(NamedExpression namedExpression) + { + static_assert(_is_dynamic::value, "selected_columns::add() can only be called for dynamic_column"); + static_assert(is_named_expression_t::value, "invalid named expression argument in selected_columns::add()"); + static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "named expression uses tables unknown to this statement in selected_columns::add()"); + using column_names = ::sqlpp::detail::make_type_set_t; + static_assert(not ::sqlpp::detail::is_element_of::value, "a column of this name is present in the select already"); + + using ok = ::sqlpp::detail::all_t< + _is_dynamic::value, + is_named_expression_t::value + >; + + _add_impl(namedExpression, ok()); // dispatch to prevent compile messages after the static_assert + } + + //private: + template + void _add_impl(NamedExpression namedExpression, const std::true_type&) + { + return _data._dynamic_columns.emplace_back(namedExpression); + } + + template + void _add_column_impl(NamedExpression namedExpression, const std::false_type&); + + public: + _data_t _data; }; - _names_t _dynamic_expression_names; - static constexpr bool empty() + // Member template for adding the named member to a statement + template + struct _member_t { - return true; - } - }; + using _data_t = select_column_list_data_t; - template - struct serializer_t> - { - using T = dynamic_select_column_list; - - static Context& _(const T& t, Context& context) - { - bool first = true; - for (const auto column : t._dynamic_columns) - { - if (first) - first = false; - else - context << ','; - serialize(column, context); - } - return context; - } - }; - - template - struct serializer_t> - { - using T = dynamic_select_column_list; - - static Context& _(const T& t, Context& context) - { - return context; - } - }; - - // SELECTED COLUMNS DATA - template - struct select_column_list_data_t - { - using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - - select_column_list_data_t(Columns... columns): - _columns(columns...) - {} - - select_column_list_data_t(std::tuple columns): - _columns(columns) - {} - - select_column_list_data_t(const select_column_list_data_t&) = default; - select_column_list_data_t(select_column_list_data_t&&) = default; - select_column_list_data_t& operator=(const select_column_list_data_t&) = default; - select_column_list_data_t& operator=(select_column_list_data_t&&) = default; - ~select_column_list_data_t() = default; - - std::tuple _columns; - dynamic_select_column_list _dynamic_columns; - }; - - - // SELECTED COLUMNS - template - struct select_column_list_t - { - using _traits = typename ::sqlpp::detail::select_traits::_traits; - using _recursive_traits = make_recursive_traits; - - using _name_t = typename ::sqlpp::detail::select_traits::_name_t; - - using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected"); - - static_assert(::sqlpp::detail::all_t<(is_named_expression_t::value or is_multi_column_t::value)...>::value, "at least one argument is not a named expression"); - - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate name detected"); - - struct _column_type {}; - - // Data - using _data_t = select_column_list_data_t; - - // Member implementation with data and methods - template - struct _impl_t - { - template - void add_ntc(NamedExpression namedExpression) - { - add(namedExpression); - } - - template - void add(NamedExpression namedExpression) - { - static_assert(_is_dynamic::value, "selected_columns::add() can only be called for dynamic_column"); - static_assert(is_named_expression_t::value, "invalid named expression argument in selected_columns::add()"); - static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "named expression uses tables unknown to this statement in selected_columns::add()"); - using column_names = ::sqlpp::detail::make_type_set_t; - static_assert(not ::sqlpp::detail::is_element_of::value, "a column of this name is present in the select already"); - - using ok = ::sqlpp::detail::all_t< - _is_dynamic::value, - is_named_expression_t::value - >; - - _add_impl(namedExpression, ok()); // dispatch to prevent compile messages after the static_assert - } - - //private: - template - void _add_impl(NamedExpression namedExpression, const std::true_type&) - { - return _data._dynamic_columns.emplace_back(namedExpression); - } - - template - void _add_column_impl(NamedExpression namedExpression, const std::false_type&); - - public: - _data_t _data; - }; - - // Member template for adding the named member to a statement - template - struct _member_t - { - using _data_t = select_column_list_data_t; - - _impl_t selected_columns; - _impl_t& operator()() { return selected_columns; } - const _impl_t& operator()() const { return selected_columns; } + _impl_t selected_columns; + _impl_t& operator()() { return selected_columns; } + const _impl_t& operator()() const { return selected_columns; } template static auto _get_member(T t) -> decltype(t.selected_columns) { return t.selected_columns; } - }; + }; - // Additional methods for the statement - template - struct _methods_t + // Additional methods for the statement + template + struct _methods_t + { + }; + + // Result methods + template + struct _result_methods_t + { + using _statement_t = typename Policies::_statement_t; + + const _statement_t& _get_statement() const { - }; + return static_cast(*this); + } - // Result methods - template - struct _result_methods_t + template + using _result_row_t = typename std::conditional<_is_dynamic::value, + dynamic_result_row_t...>, + result_row_t...>>::type; + + using _dynamic_names_t = typename dynamic_select_column_list::_names_t; + + template + struct _deferred_table_t + { + using table = select_pseudo_table_t<_statement_t, Columns...>; + using alias = typename table::template _alias_t; + }; + + template + using _table_t = typename _deferred_table_t::table; + + template + using _alias_t = typename _deferred_table_t::alias; + + template + _alias_t as(const AliasProvider& aliasProvider) const + { + static_assert(Policies::_can_be_used_as_table::value, "statement cannot be used as table, e.g. due to missing tables"); + return _table_t(_get_statement()).as(aliasProvider); + } + + const _dynamic_names_t& get_dynamic_names() const { - using _statement_t = typename Policies::_statement_t; + return _get_statement().selected_columns._data._dynamic_columns._dynamic_expression_names; + } - const _statement_t& _get_statement() const + size_t get_no_of_result_columns() const + { + return sizeof...(Columns) + get_dynamic_names().size(); + } + + // Execute + template + auto _run(Db& db) const + -> result_t> { - return static_cast(*this); + _statement_t::_check_consistency(); + static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run select directly with parameters, use prepare instead"); + + return {db.select(_get_statement()), get_dynamic_names()}; } - - template - using _result_row_t = typename std::conditional<_is_dynamic::value, - dynamic_result_row_t...>, - result_row_t...>>::type; - - using _dynamic_names_t = typename dynamic_select_column_list::_names_t; - - template - struct _deferred_table_t - { - using table = select_pseudo_table_t<_statement_t, Columns...>; - using alias = typename table::template _alias_t; - }; - - template - using _table_t = typename _deferred_table_t::table; - - template - using _alias_t = typename _deferred_table_t::alias; - - template - _alias_t as(const AliasProvider& aliasProvider) const - { - static_assert(Policies::_can_be_used_as_table::value, "statement cannot be used as table, e.g. due to missing tables"); - return _table_t(_get_statement()).as(aliasProvider); - } - - const _dynamic_names_t& get_dynamic_names() const - { - return _get_statement().selected_columns._data._dynamic_columns._dynamic_expression_names; - } - - size_t get_no_of_result_columns() const - { - return sizeof...(Columns) + get_dynamic_names().size(); - } - - // Execute - template - auto _run(Db& db) const - -> result_t> - { - _statement_t::_check_consistency(); - static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run select directly with parameters, use prepare instead"); - - return {db.select(_get_statement()), get_dynamic_names()}; - } #if 0 - // Prepare - template - auto _prepare(Db& db) const - -> prepared_select_t - { - _statement_t::_check_consistency(); + // Prepare + template + auto _prepare(Db& db) const + -> prepared_select_t + { + _statement_t::_check_consistency(); - return {{}, get_dynamic_names(), db.prepare_select(*this)}; - } + return {{}, get_dynamic_names(), db.prepare_select(*this)}; + } #endif - }; + }; - }; + }; namespace detail { @@ -318,84 +318,84 @@ namespace sqlpp decltype(std::tuple_cat(as_tuple::_(std::declval())...))>; } - struct no_select_column_list_t - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; + struct no_select_column_list_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; - struct _name_t {}; + struct _name_t {}; - // Data - using _data_t = no_data_t; + // Data + using _data_t = no_data_t; - // Member implementation with data and methods - template - struct _impl_t - { - _data_t _data; - }; - - // Member template for adding the named member to a statement - template - struct _member_t - { - using _data_t = no_data_t; - - _impl_t no_selected_columns; - _impl_t& operator()() { return no_selected_columns; } - const _impl_t& operator()() const { return no_selected_columns; } - - template - static auto _get_member(T t) -> decltype(t.no_selected_columns) - { - return t.no_selected_columns; - } - }; - - // Additional methods for the statement - template - struct _methods_t - { - using _database_t = typename Policies::_database_t; - template - using _new_statement_t = typename Policies::template _new_statement_t; - - template - auto columns(Args... args) - -> _new_statement_t<::sqlpp::detail::make_select_column_list_t> - { - return { *static_cast(this), typename ::sqlpp::detail::make_select_column_list_t::_data_t{std::tuple_cat(::sqlpp::detail::as_tuple::_(args)...)} }; - } - - template - auto dynamic_columns(Args... args) - -> _new_statement_t<::sqlpp::detail::make_select_column_list_t<_database_t, Args...>> - { - static_assert(not std::is_same<_database_t, void>::value, "dynamic_columns must not be called in a static statement"); - return { *static_cast(this), typename ::sqlpp::detail::make_select_column_list_t<_database_t, Args...>::_data_t{std::tuple_cat(::sqlpp::detail::as_tuple::_(args)...)} }; - } - }; - }; - - // Interpreters - template - struct serializer_t> + // Member implementation with data and methods + template + struct _impl_t { - using T = select_column_list_data_t; - - static Context& _(const T& t, Context& context) - { - // check for at least one expression - static_assert(T::_is_dynamic::value or sizeof...(Columns), "at least one select expression required"); - - interpret_tuple(t._columns, ',', context); - if (sizeof...(Columns) and not t._dynamic_columns.empty()) - context << ','; - serialize(t._dynamic_columns, context); - return context; - } + _data_t _data; }; + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; + + _impl_t no_selected_columns; + _impl_t& operator()() { return no_selected_columns; } + const _impl_t& operator()() const { return no_selected_columns; } + + template + static auto _get_member(T t) -> decltype(t.no_selected_columns) + { + return t.no_selected_columns; + } + }; + + // Additional methods for the statement + template + struct _methods_t + { + using _database_t = typename Policies::_database_t; + template + using _new_statement_t = typename Policies::template _new_statement_t; + + template + auto columns(Args... args) + -> _new_statement_t<::sqlpp::detail::make_select_column_list_t> + { + return { *static_cast(this), typename ::sqlpp::detail::make_select_column_list_t::_data_t{std::tuple_cat(::sqlpp::detail::as_tuple::_(args)...)} }; + } + + template + auto dynamic_columns(Args... args) + -> _new_statement_t<::sqlpp::detail::make_select_column_list_t<_database_t, Args...>> + { + static_assert(not std::is_same<_database_t, void>::value, "dynamic_columns must not be called in a static statement"); + return { *static_cast(this), typename ::sqlpp::detail::make_select_column_list_t<_database_t, Args...>::_data_t{std::tuple_cat(::sqlpp::detail::as_tuple::_(args)...)} }; + } + }; + }; + + // Interpreters + template + struct serializer_t> + { + using T = select_column_list_data_t; + + static Context& _(const T& t, Context& context) + { + // check for at least one expression + static_assert(T::_is_dynamic::value or sizeof...(Columns), "at least one select expression required"); + + interpret_tuple(t._columns, ',', context); + if (sizeof...(Columns) and not t._dynamic_columns.empty()) + context << ','; + serialize(t._dynamic_columns, context); + return context; + } + }; + } #endif diff --git a/include/sqlpp11/select_flag_list.h b/include/sqlpp11/select_flag_list.h index 9b0414e3..8147e5d2 100644 --- a/include/sqlpp11/select_flag_list.h +++ b/include/sqlpp11/select_flag_list.h @@ -36,112 +36,72 @@ namespace sqlpp { - // SELECTED FLAGS DATA - template - struct select_flag_list_data_t - { - select_flag_list_data_t(Flags... flags): - _flags(flags...) - {} - - select_flag_list_data_t(const select_flag_list_data_t&) = default; - select_flag_list_data_t(select_flag_list_data_t&&) = default; - select_flag_list_data_t& operator=(const select_flag_list_data_t&) = default; - select_flag_list_data_t& operator=(select_flag_list_data_t&&) = default; - ~select_flag_list_data_t() = default; - - std::tuple _flags; - interpretable_list_t _dynamic_flags; - }; - - // SELECT FLAGS - template - struct select_flag_list_t - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits; - - using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in select flag list"); - - static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a select flag in select flag list"); - - // Data - using _data_t = select_flag_list_data_t; - - // Member implementation with data and methods - template - struct _impl_t - { - template - void add_ntc(Flag flag) - { - add(flag); - } - - template - void add(Flag flag) - { - static_assert(_is_dynamic::value, "select_flags::add() must not be called for static select flags"); - static_assert(is_select_flag_t::value, "invalid select flag argument in select_flags::add()"); - static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "flag uses tables unknown to this statement in select_flags::add()"); - - using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_select_flag_t::value>; - - _add_impl(flag, ok()); // dispatch to prevent compile messages after the static_assert - } - - private: - template - void _add_impl(Flag flag, const std::true_type&) - { - return _data._dynamic_flags.emplace_back(flag); - } - - template - void _add_impl(Flag flag, const std::false_type&); - public: - _data_t _data; - }; - - // Member template for adding the named member to a statement - template - struct _member_t - { - using _data_t = select_flag_list_data_t; - - _impl_t select_flags; - _impl_t& operator()() { return select_flags; } - const _impl_t& operator()() const { return select_flags; } - - template - static auto _get_member(T t) -> decltype(t.select_flags) - { - return t.select_flags; - } - }; - - // Additional methods for the statement - template - struct _methods_t - { - }; - - }; - - struct no_select_flag_list_t + // SELECTED FLAGS DATA + template + struct select_flag_list_data_t { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; + select_flag_list_data_t(Flags... flags): + _flags(flags...) + {} + + select_flag_list_data_t(const select_flag_list_data_t&) = default; + select_flag_list_data_t(select_flag_list_data_t&&) = default; + select_flag_list_data_t& operator=(const select_flag_list_data_t&) = default; + select_flag_list_data_t& operator=(select_flag_list_data_t&&) = default; + ~select_flag_list_data_t() = default; + + std::tuple _flags; + interpretable_list_t _dynamic_flags; + }; + + // SELECT FLAGS + template + struct select_flag_list_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + + using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; + + static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in select flag list"); + + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a select flag in select flag list"); // Data - using _data_t = no_data_t; + using _data_t = select_flag_list_data_t; // Member implementation with data and methods template struct _impl_t { + template + void add_ntc(Flag flag) + { + add(flag); + } + + template + void add(Flag flag) + { + static_assert(_is_dynamic::value, "select_flags::add() must not be called for static select flags"); + static_assert(is_select_flag_t::value, "invalid select flag argument in select_flags::add()"); + static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "flag uses tables unknown to this statement in select_flags::add()"); + + using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_select_flag_t::value>; + + _add_impl(flag, ok()); // dispatch to prevent compile messages after the static_assert + } + + private: + template + void _add_impl(Flag flag, const std::true_type&) + { + return _data._dynamic_flags.emplace_back(flag); + } + + template + void _add_impl(Flag flag, const std::false_type&); + public: _data_t _data; }; @@ -149,62 +109,102 @@ namespace sqlpp template struct _member_t { - using _data_t = no_data_t; + using _data_t = select_flag_list_data_t; - _impl_t no_select_flags; - _impl_t& operator()() { return no_select_flags; } - const _impl_t& operator()() const { return no_select_flags; } + _impl_t select_flags; + _impl_t& operator()() { return select_flags; } + const _impl_t& operator()() const { return select_flags; } template - static auto _get_member(T t) -> decltype(t.no_select_flags) + static auto _get_member(T t) -> decltype(t.select_flags) { - return t.no_select_flags; + return t.select_flags; } }; + // Additional methods for the statement template struct _methods_t { - using _database_t = typename Policies::_database_t; - template - using _new_statement_t = typename Policies::template _new_statement_t; - - template - auto flags(Args... args) - -> _new_statement_t> - { - return { *static_cast(this), select_flag_list_data_t{args...} }; - } - - template - auto dynamic_flags(Args... args) - -> _new_statement_t> - { - static_assert(not std::is_same<_database_t, void>::value, "dynamic_flags must not be called in a static statement"); - return { *static_cast(this), select_flag_list_data_t<_database_t, Args...>{args...} }; - } }; + }; + struct no_select_flag_list_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; - // Interpreters - template - struct serializer_t> + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t { - using T = select_flag_list_data_t; - - static Context& _(const T& t, Context& context) - { - interpret_tuple(t._flags, ' ', context); - if (sizeof...(Flags)) - context << ' '; - interpret_list(t._dynamic_flags, ',', context); - if (not t._dynamic_flags.empty()) - context << ' '; - return context; - } + _data_t _data; }; + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; + + _impl_t no_select_flags; + _impl_t& operator()() { return no_select_flags; } + const _impl_t& operator()() const { return no_select_flags; } + + template + static auto _get_member(T t) -> decltype(t.no_select_flags) + { + return t.no_select_flags; + } + }; + + template + struct _methods_t + { + using _database_t = typename Policies::_database_t; + template + using _new_statement_t = typename Policies::template _new_statement_t; + + template + auto flags(Args... args) + -> _new_statement_t> + { + return { *static_cast(this), select_flag_list_data_t{args...} }; + } + + template + auto dynamic_flags(Args... args) + -> _new_statement_t> + { + static_assert(not std::is_same<_database_t, void>::value, "dynamic_flags must not be called in a static statement"); + return { *static_cast(this), select_flag_list_data_t<_database_t, Args...>{args...} }; + } + }; + }; + + + // Interpreters + template + struct serializer_t> + { + using T = select_flag_list_data_t; + + static Context& _(const T& t, Context& context) + { + interpret_tuple(t._flags, ' ', context); + if (sizeof...(Flags)) + context << ' '; + interpret_list(t._dynamic_flags, ',', context); + if (not t._dynamic_flags.empty()) + context << ' '; + return context; + } + }; + } diff --git a/include/sqlpp11/select_flags.h b/include/sqlpp11/select_flags.h index e082680f..4b07d6be 100644 --- a/include/sqlpp11/select_flags.h +++ b/include/sqlpp11/select_flags.h @@ -42,15 +42,15 @@ namespace sqlpp }; static constexpr all_t all = {}; - template - struct serializer_t + template + struct serializer_t + { + static Context& _(const all_t&, Context& context) { - static Context& _(const all_t&, Context& context) - { - context << "ALL"; - return context; - } - }; + context << "ALL"; + return context; + } + }; struct distinct_t { @@ -59,15 +59,15 @@ namespace sqlpp }; static constexpr distinct_t distinct = {}; - template - struct serializer_t + template + struct serializer_t + { + static Context& _(const distinct_t&, Context& context) { - static Context& _(const distinct_t&, Context& context) - { - context << "DISTINCT"; - return context; - } - }; + context << "DISTINCT"; + return context; + } + }; struct straight_join_t { @@ -76,15 +76,15 @@ namespace sqlpp }; static constexpr straight_join_t straight_join = {}; - template - struct serializer_t + template + struct serializer_t + { + static Context& _(const straight_join_t&, Context& context) { - static Context& _(const straight_join_t&, Context& context) - { - context << "STRAIGHT_JOIN"; - return context; - } - }; + context << "STRAIGHT_JOIN"; + return context; + } + }; } diff --git a/include/sqlpp11/select_pseudo_table.h b/include/sqlpp11/select_pseudo_table.h index efd9d4d3..3378035a 100644 --- a/include/sqlpp11/select_pseudo_table.h +++ b/include/sqlpp11/select_pseudo_table.h @@ -42,13 +42,13 @@ namespace sqlpp using _name_t = typename Expr::_name_t; struct _column_type { - using _must_not_insert = std::true_type; - using _must_not_update = std::true_type; + using _must_not_insert = std::true_type; + using _must_not_update = std::true_type; }; }; template< - typename Select, + typename Select, typename... NamedExpr > struct select_pseudo_table_t: public sqlpp::table_t - struct serializer_t> - { - using T = select_pseudo_table_t; + template + struct serializer_t> + { + using T = select_pseudo_table_t; - static Context& _(const T& t, Context& context) - { - serialize(t._select, context); - return context; - } - }; + static Context& _(const T& t, Context& context) + { + serialize(t._select, context); + return context; + } + }; } diff --git a/include/sqlpp11/serialize.h b/include/sqlpp11/serialize.h index c8641ae7..e7331320 100644 --- a/include/sqlpp11/serialize.h +++ b/include/sqlpp11/serialize.h @@ -39,13 +39,13 @@ namespace sqlpp } /* - template - auto serialize(const T& t, Context& context) - -> decltype(serializer_t::_(t, context)) - { - return serializer_t::_(t, context); - } - */ + template + auto serialize(const T& t, Context& context) + -> decltype(serializer_t::_(t, context)) + { + return serializer_t::_(t, context); + } + */ } diff --git a/include/sqlpp11/serializer.h b/include/sqlpp11/serializer.h index c263b393..682c9602 100644 --- a/include/sqlpp11/serializer.h +++ b/include/sqlpp11/serializer.h @@ -31,14 +31,14 @@ namespace sqlpp { - template - struct serializer_t + template + struct serializer_t + { + static void _(const T& t, Context& context) { - static void _(const T& t, Context& context) - { - static_assert(wrong_t::value, "missing serializer specialization"); - } - }; + static_assert(wrong_t::value, "missing serializer specialization"); + } + }; } diff --git a/include/sqlpp11/simple_column.h b/include/sqlpp11/simple_column.h index bdf74345..34f030e3 100644 --- a/include/sqlpp11/simple_column.h +++ b/include/sqlpp11/simple_column.h @@ -31,29 +31,29 @@ namespace sqlpp { - template - struct simple_column_t - { - Column _column; - }; + template + struct simple_column_t + { + Column _column; + }; - template - struct serializer_t> - { - using T = simple_column_t; + template + struct serializer_t> + { + using T = simple_column_t; - static Context& _(const T& t, Context& context) - { - context << t._column._get_name(); - return context; - } - }; - - template - simple_column_t simple_column(Column c) + static Context& _(const T& t, Context& context) { - return {c}; + context << t._column._get_name(); + return context; } + }; + + template + simple_column_t simple_column(Column c) + { + return {c}; + } } #endif diff --git a/include/sqlpp11/single_table.h b/include/sqlpp11/single_table.h index 23544dba..0f760e10 100644 --- a/include/sqlpp11/single_table.h +++ b/include/sqlpp11/single_table.h @@ -34,129 +34,39 @@ namespace sqlpp { - // A SINGLE TABLE DATA - template - struct single_table_data_t - { - single_table_data_t(Table table): - _table(table) - {} - - single_table_data_t(const single_table_data_t&) = default; - single_table_data_t(single_table_data_t&&) = default; - single_table_data_t& operator=(const single_table_data_t&) = default; - single_table_data_t& operator=(single_table_data_t&&) = default; - ~single_table_data_t() = default; - - Table _table; - }; - - // A SINGLE TABLE - template - struct single_table_t - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits
; - - static_assert(is_table_t
::value, "argument has to be a table"); - static_assert(required_tables_of
::size::value == 0, "table depends on another table"); - - using _data_t = single_table_data_t; - - struct _name_t {}; - - // Member implementation with data and methods - template - struct _impl_t - { - _data_t _data; - }; - - // Member template for adding the named member to a statement - template - struct _member_t - { - using _data_t = single_table_data_t; - - _impl_t from; - _impl_t& operator()() { return from; } - const _impl_t& operator()() const { return from; } - - template - static auto _get_member(T t) -> decltype(t.from) - { - return t.from; - } - }; - - // Additional methods for the statement - template - struct _methods_t - { - }; - - template - struct _result_methods_t - { - using _statement_t = typename Policies::_statement_t; - - const _statement_t& _get_statement() const - { - return static_cast(*this); - } - - static constexpr size_t _get_static_no_of_parameters() - { -#warning need to fix this - return 0; - //return _parameter_list_t::size::value; - } - - size_t _get_no_of_parameters() const - { -#warning need to fix this - return 0; - //return _parameter_list_t::size::value; - } - - void _check_consistency() const - { - // FIXME: Read up on what is allowed/prohibited in INSERT - } - - template - auto _run(Db& db) const -> decltype(db.insert(_get_statement())) - { - _check_consistency(); - - static_assert(_get_static_no_of_parameters() == 0, "cannot run insert directly with parameters, use prepare instead"); - return db.insert(*this); - } - - /* - template - auto _prepare(Db& db) const - -> prepared_insert_t - { - _check_consistency(); - - return {{}, db.prepare_insert(*this)}; - } - */ - }; - }; - - // NO INTO YET - struct no_single_table_t + // A SINGLE TABLE DATA + template + struct single_table_data_t { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; + single_table_data_t(Table table): + _table(table) + {} - // Data - using _data_t = no_data_t; + single_table_data_t(const single_table_data_t&) = default; + single_table_data_t(single_table_data_t&&) = default; + single_table_data_t& operator=(const single_table_data_t&) = default; + single_table_data_t& operator=(single_table_data_t&&) = default; + ~single_table_data_t() = default; + + Table _table; + }; + + // A SINGLE TABLE + template + struct single_table_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits
; + + static_assert(is_table_t
::value, "argument has to be a table"); + static_assert(required_tables_of
::size::value == 0, "table depends on another table"); + + using _data_t = single_table_data_t; + + struct _name_t {}; // Member implementation with data and methods - template + template struct _impl_t { _data_t _data; @@ -166,49 +76,139 @@ namespace sqlpp template struct _member_t { - using _data_t = no_data_t; + using _data_t = single_table_data_t; - _impl_t no_from; - _impl_t& operator()() { return no_from; } - const _impl_t& operator()() const { return no_from; } + _impl_t from; + _impl_t& operator()() { return from; } + const _impl_t& operator()() const { return from; } template - static auto _get_member(T t) -> decltype(t.no_from) + static auto _get_member(T t) -> decltype(t.from) { - return t.no_from; + return t.from; } }; + // Additional methods for the statement template struct _methods_t { - using _database_t = typename Policies::_database_t; - template - using _new_statement_t = typename Policies::template _new_statement_t; + }; -#warning: remove can operate on several tables at once, so it should not use single_table anyway - template - auto from(Args... args) - -> _new_statement_t> + template + struct _result_methods_t + { + using _statement_t = typename Policies::_statement_t; + + const _statement_t& _get_statement() const + { + return static_cast(*this); + } + + static constexpr size_t _get_static_no_of_parameters() + { +#warning need to fix this + return 0; + //return _parameter_list_t::size::value; + } + + size_t _get_no_of_parameters() const + { +#warning need to fix this + return 0; + //return _parameter_list_t::size::value; + } + + void _check_consistency() const + { + // FIXME: Read up on what is allowed/prohibited in INSERT + } + + template + auto _run(Db& db) const -> decltype(db.insert(_get_statement())) { - return { *static_cast(this), single_table_data_t{args...} }; + _check_consistency(); + + static_assert(_get_static_no_of_parameters() == 0, "cannot run insert directly with parameters, use prepare instead"); + return db.insert(*this); } + + /* + template + auto _prepare(Db& db) const + -> prepared_insert_t + { + _check_consistency(); + + return {{}, db.prepare_insert(*this)}; + } + */ }; }; - // Interpreters - template - struct serializer_t> - { - using T = single_table_data_t; + // NO INTO YET + struct no_single_table_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; - static Context& _(const T& t, Context& context) - { - serialize(t._table, context); - return context; - } + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; }; + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; + + _impl_t no_from; + _impl_t& operator()() { return no_from; } + const _impl_t& operator()() const { return no_from; } + + template + static auto _get_member(T t) -> decltype(t.no_from) + { + return t.no_from; + } + }; + + template + struct _methods_t + { + using _database_t = typename Policies::_database_t; + template + using _new_statement_t = typename Policies::template _new_statement_t; + +#warning: remove can operate on several tables at once, so it should not use single_table anyway + template + auto from(Args... args) + -> _new_statement_t> + { + return { *static_cast(this), single_table_data_t{args...} }; + } + }; + }; + + // Interpreters + template + struct serializer_t> + { + using T = single_table_data_t; + + static Context& _(const T& t, Context& context) + { + serialize(t._table, context); + return context; + } + }; + } #endif diff --git a/include/sqlpp11/some.h b/include/sqlpp11/some.h index 2b1fb002..1fb864c8 100644 --- a/include/sqlpp11/some.h +++ b/include/sqlpp11/some.h @@ -32,7 +32,7 @@ namespace sqlpp { - template + template struct some_t { using _traits = make_traits, ::sqlpp::tag::multi_expression>; @@ -63,19 +63,19 @@ namespace sqlpp Select _select; }; - template - struct serializer_t> - { - using T = some_t; - static Context& _(const T& t, Context& context) - { - context << "SOME("; - serialize(t._select, context); - context << ")"; - return context; - } - }; + static Context& _(const T& t, Context& context) + { + context << "SOME("; + serialize(t._select, context); + context << ")"; + return context; + } + }; template auto some(T t) -> typename some_t> diff --git a/include/sqlpp11/sort_order.h b/include/sqlpp11/sort_order.h index a7e8bdea..ae8d92bd 100644 --- a/include/sqlpp11/sort_order.h +++ b/include/sqlpp11/sort_order.h @@ -46,26 +46,26 @@ namespace sqlpp Expression _expression; }; - template - struct serializer_t> - { - using T = sort_order_t; + template + struct serializer_t> + { + using T = sort_order_t; - static Context& _(const T& t, Context& context) + static Context& _(const T& t, Context& context) + { + serialize(t._expression, context); + switch(SortType) { - serialize(t._expression, context); - switch(SortType) - { - case sort_type::asc: - context << " ASC"; - break; - default: - context << " DESC"; - break; - } - return context; + case sort_type::asc: + context << " ASC"; + break; + default: + context << " DESC"; + break; } - }; + return context; + } + }; } diff --git a/include/sqlpp11/statement.h b/include/sqlpp11/statement.h index e875ac20..790206a1 100644 --- a/include/sqlpp11/statement.h +++ b/include/sqlpp11/statement.h @@ -80,7 +80,7 @@ namespace sqlpp using _required_tables = detail::make_difference_set_t< _all_required_tables, _all_provided_tables // Hint: extra_tables are not used here because they are just a helper for dynamic .add_*() - >; + >; using _result_type_provider = detail::get_last_if; @@ -95,7 +95,7 @@ namespace sqlpp is_select_column_list_t<_result_type_provider>::value and _required_tables::size::value == 0, std::true_type, std::false_type - >::type; + >::type; using _value_type = typename std::conditional< detail::none_t::value...>::value, @@ -121,82 +121,82 @@ namespace sqlpp } template - struct statement_t: - public Policies::template _member_t>..., - public detail::statement_policies_t::_value_type::template expression_operators>, - public detail::statement_policies_t::_result_methods_t, - public detail::statement_policies_t::_methods_t + typename... Policies + > + struct statement_t: + public Policies::template _member_t>..., + public detail::statement_policies_t::_value_type::template expression_operators>, + public detail::statement_policies_t::_result_methods_t, + public detail::statement_policies_t::_methods_t { - using _policies_t = typename detail::statement_policies_t; + using _policies_t = typename detail::statement_policies_t; - using _traits = make_traits, ::sqlpp::tag::select, tag::expression_if, tag::named_expression_if>; - using _recursive_traits = typename _policies_t::_recursive_traits; + using _traits = make_traits, ::sqlpp::tag::select, tag::expression_if, tag::named_expression_if>; + using _recursive_traits = typename _policies_t::_recursive_traits; - using _result_type_provider = typename _policies_t::_result_type_provider; + using _result_type_provider = typename _policies_t::_result_type_provider; - using _requires_braces = std::true_type; + using _requires_braces = std::true_type; - using _name_t = typename _result_type_provider::_name_t; + using _name_t = typename _result_type_provider::_name_t; - // Constructors - statement_t() - {} + // Constructors + statement_t() + {} - template - statement_t(Statement statement, Term term): - Policies::template _member_t<_policies_t>{ - typename Policies::template _impl_t<_policies_t>{ - detail::pick_arg>(statement, term) - }}... - //Policies::template _member_t<_policies_t>{{detail::pick_arg>(statement, term)}}... - {} + template + statement_t(Statement statement, Term term): + Policies::template _member_t<_policies_t>{ + typename Policies::template _impl_t<_policies_t>{ + detail::pick_arg>(statement, term) + }}... + //Policies::template _member_t<_policies_t>{{detail::pick_arg>(statement, term)}}... + {} - statement_t(const statement_t& r) = default; - statement_t(statement_t&& r) = default; - statement_t& operator=(const statement_t& r) = default; - statement_t& operator=(statement_t&& r) = default; - ~statement_t() = default; + statement_t(const statement_t& r) = default; + statement_t(statement_t&& r) = default; + statement_t& operator=(const statement_t& r) = default; + statement_t& operator=(statement_t&& r) = default; + ~statement_t() = default; - static constexpr size_t _get_static_no_of_parameters() - { + static constexpr size_t _get_static_no_of_parameters() + { #warning need to fix this - return 0; - //return _parameter_list_t::size::value; - } + return 0; + //return _parameter_list_t::size::value; + } - size_t _get_no_of_parameters() const - { - return _get_static_no_of_parameters(); - } + size_t _get_no_of_parameters() const + { + return _get_static_no_of_parameters(); + } - static void _check_consistency() - { - // FIXME: Check each "methods" or each member... + static void _check_consistency() + { + // FIXME: Check each "methods" or each member... #warning check for missing terms here, and for missing tables - static_assert(not required_tables_of<_policies_t>::size::value, "one sub expression requires tables which are otherwise not known in the statement"); + static_assert(not required_tables_of<_policies_t>::size::value, "one sub expression requires tables which are otherwise not known in the statement"); + } + + + }; + + template + struct serializer_t> + { + using T = statement_t; + using P = ::sqlpp::detail::statement_policies_t; + + static Context& _(const T& t, Context& context) + { + using swallow = int[]; + (void) swallow{(serialize(static_cast&>(t)()._data, context), 0)...}; + + return context; } - - }; - template - struct serializer_t> - { - using T = statement_t; - using P = ::sqlpp::detail::statement_policies_t; - - static Context& _(const T& t, Context& context) - { - using swallow = int[]; - (void) swallow{(serialize(static_cast&>(t)()._data, context), 0)...}; - - return context; - } - }; - - template + template struct statement_name_t { using _traits = make_traits; diff --git a/include/sqlpp11/sum.h b/include/sqlpp11/sum.h index 9bfca5d9..d22f008f 100644 --- a/include/sqlpp11/sum.h +++ b/include/sqlpp11/sum.h @@ -31,59 +31,59 @@ namespace sqlpp { - template + template struct sum_t: public value_type_of::template expression_operators>, - public alias_operators> + public alias_operators> + { + using _traits = make_traits, ::sqlpp::tag::expression, ::sqlpp::tag::named_expression>; + using _recursive_traits = make_recursive_traits; + + static_assert(is_noop::value or std::is_same::value, "sum() used with flag other than 'distinct'"); + static_assert(is_numeric_t::value, "sum() requires a numeric expression as argument"); + + struct _name_t { - using _traits = make_traits, ::sqlpp::tag::expression, ::sqlpp::tag::named_expression>; - using _recursive_traits = make_recursive_traits; - - static_assert(is_noop::value or std::is_same::value, "sum() used with flag other than 'distinct'"); - static_assert(is_numeric_t::value, "sum() requires a numeric expression as argument"); - - struct _name_t - { - static constexpr const char* _get_name() { return "SUM"; } - template - struct _member_t - { - T sum; - T& operator()() { return sum; } - const T& operator()() const { return sum; } - }; - }; - - sum_t(Expr expr): - _expr(expr) - {} - - sum_t(const sum_t&) = default; - sum_t(sum_t&&) = default; - sum_t& operator=(const sum_t&) = default; - sum_t& operator=(sum_t&&) = default; - ~sum_t() = default; - - Expr _expr; + static constexpr const char* _get_name() { return "SUM"; } + template + struct _member_t + { + T sum; + T& operator()() { return sum; } + const T& operator()() const { return sum; } + }; }; - template - struct serializer_t> - { - using T = sum_t; + sum_t(Expr expr): + _expr(expr) + {} - static Context& _(const T& t, Context& context) + sum_t(const sum_t&) = default; + sum_t(sum_t&&) = default; + sum_t& operator=(const sum_t&) = default; + sum_t& operator=(sum_t&&) = default; + ~sum_t() = default; + + Expr _expr; + }; + + template + struct serializer_t> + { + using T = sum_t; + + static Context& _(const T& t, Context& context) + { + context << "SUM("; + if (std::is_same::value) { - context << "SUM("; - if (std::is_same::value) - { - serialize(Flag(), context); - context << ' '; - } - serialize(t._expr, context); - context << ")"; - return context; + serialize(Flag(), context); + context << ' '; } - }; + serialize(t._expr, context); + context << ")"; + return context; + } + }; template auto sum(T t) -> typename sum_t> diff --git a/include/sqlpp11/table.h b/include/sqlpp11/table.h index fa2e1043..9dc4183f 100644 --- a/include/sqlpp11/table.h +++ b/include/sqlpp11/table.h @@ -40,7 +40,7 @@ namespace sqlpp struct table_base_t {}; template - struct table_t: public table_base_t, public ColumnSpec::_name_t::template _member_t>... + struct table_t: public table_base_t, public ColumnSpec::_name_t::template _member_t>... { using _traits = make_traits; @@ -101,17 +101,17 @@ namespace sqlpp } }; - template - struct serializer_t::value and not is_pseudo_table_t::value, void>::type> - { - using T = X; + template + struct serializer_t::value and not is_pseudo_table_t::value, void>::type> + { + using T = X; - static Context& _(const T& t, Context& context) - { - context << T::_name_t::_get_name(); - return context; - } - }; + static Context& _(const T& t, Context& context) + { + context << T::_name_t::_get_name(); + return context; + } + }; } diff --git a/include/sqlpp11/table_alias.h b/include/sqlpp11/table_alias.h index d8bc5ba5..ff1a3e19 100644 --- a/include/sqlpp11/table_alias.h +++ b/include/sqlpp11/table_alias.h @@ -61,19 +61,19 @@ namespace sqlpp Table _table; }; - template - struct serializer_t> - { - using T = table_alias_t; + template + struct serializer_t> + { + using T = table_alias_t; - static Context& _(const T& t, Context& context) - { - context << "("; - serialize(t._table, context); - context << ") AS " << T::_name_t::_get_name(); - return context; - } - }; + static Context& _(const T& t, Context& context) + { + context << "("; + serialize(t._table, context); + context << ") AS " << T::_name_t::_get_name(); + return context; + } + }; } diff --git a/include/sqlpp11/text.h b/include/sqlpp11/text.h index 1d533dcb..0e0c6a53 100644 --- a/include/sqlpp11/text.h +++ b/include/sqlpp11/text.h @@ -51,12 +51,12 @@ namespace sqlpp _parameter_t(): _value(""), _is_null(true) - {} + {} _parameter_t(const _cpp_value_type& value): _value(value), _is_null(false) - {} + {} _parameter_t& operator=(const _cpp_value_type& value) { @@ -73,7 +73,7 @@ namespace sqlpp } bool is_null() const - { + { return _is_null; } @@ -96,94 +96,94 @@ namespace sqlpp }; template - struct _result_entry_t - { - _result_entry_t(): - _is_valid(false), - _value_ptr(nullptr), - _len(0) + struct _result_entry_t + { + _result_entry_t(): + _is_valid(false), + _value_ptr(nullptr), + _len(0) {} - _result_entry_t(char* data, size_t len): - _is_valid(true), - _value_ptr(data), - _len(_value_ptr ? 0 : len) - {} + _result_entry_t(char* data, size_t len): + _is_valid(true), + _value_ptr(data), + _len(_value_ptr ? 0 : len) + {} - void assign(const char* data, size_t len) - { - _is_valid = true; - _value_ptr = data; - _len = _value_ptr ? len: 0; - } - - void validate() - { - _is_valid = true; - } - - void invalidate() - { - _is_valid = false; - _value_ptr = nullptr; - _len = 0; - } - - bool operator==(const _cpp_value_type& rhs) const { return value() == rhs; } - bool operator!=(const _cpp_value_type& rhs) const { return not operator==(rhs); } - - bool is_null() const - { - if (connector_assert_result_validity_t::value) - assert(_is_valid); - else if (not _is_valid) - throw exception("accessing is_null in non-existing row"); - return _value_ptr == nullptr; - } - - _cpp_value_type value() const - { - const bool null_value = _value_ptr == nullptr and not NullIsTrivial and not connector_null_result_is_trivial_value_t::value; - if (connector_assert_result_validity_t::value) + void assign(const char* data, size_t len) { - assert(_is_valid); - assert(not null_value); - } - else - { - if (not _is_valid) - throw exception("accessing value in non-existing row"); - if (null_value) - throw exception("accessing value of NULL field"); - } - if (_value_ptr) - return std::string(_value_ptr, _value_ptr + _len); - else - return ""; - } - - operator _cpp_value_type() const { return value(); } - - template - void _bind(Target& target, size_t i) - { - target._bind_text_result(i, &_value_ptr, &_len); + _is_valid = true; + _value_ptr = data; + _len = _value_ptr ? len: 0; } - private: - bool _is_valid; - const char* _value_ptr; - size_t _len; - }; + void validate() + { + _is_valid = true; + } + + void invalidate() + { + _is_valid = false; + _value_ptr = nullptr; + _len = 0; + } + + bool operator==(const _cpp_value_type& rhs) const { return value() == rhs; } + bool operator!=(const _cpp_value_type& rhs) const { return not operator==(rhs); } + + bool is_null() const + { + if (connector_assert_result_validity_t::value) + assert(_is_valid); + else if (not _is_valid) + throw exception("accessing is_null in non-existing row"); + return _value_ptr == nullptr; + } + + _cpp_value_type value() const + { + const bool null_value = _value_ptr == nullptr and not NullIsTrivial and not connector_null_result_is_trivial_value_t::value; + if (connector_assert_result_validity_t::value) + { + assert(_is_valid); + assert(not null_value); + } + else + { + if (not _is_valid) + throw exception("accessing value in non-existing row"); + if (null_value) + throw exception("accessing value of NULL field"); + } + if (_value_ptr) + return std::string(_value_ptr, _value_ptr + _len); + else + return ""; + } + + operator _cpp_value_type() const { return value(); } + + template + void _bind(Target& target, size_t i) + { + target._bind_text_result(i, &_value_ptr, &_len); + } + + private: + bool _is_valid; + const char* _value_ptr; + size_t _len; + }; template struct _is_valid_operand - { - static constexpr bool value = - is_expression_t::value // expressions are OK - and is_text_t::value // the correct value type is required, of course - ; - }; + { + static constexpr bool value = + is_expression_t::value // expressions are OK + and is_text_t::value // the correct value type is required, of course + ; + }; template struct expression_operators: public basic_expression_operators @@ -209,23 +209,23 @@ namespace sqlpp template struct column_operators - { - template - auto operator +=(T t) const -> assignment_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + { + template + auto operator +=(T t) const -> assignment_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - return { *static_cast(this), { *static_cast(this), rhs{t} } }; - } - }; + return { *static_cast(this), { *static_cast(this), rhs{t} } }; + } + }; }; template - inline std::ostream& operator<<(std::ostream& os, const text::_result_entry_t& e) - { - return os << e.value(); - } + inline std::ostream& operator<<(std::ostream& os, const text::_result_entry_t& e) + { + return os << e.value(); + } } using text = detail::text; diff --git a/include/sqlpp11/transaction.h b/include/sqlpp11/transaction.h index a2b1dfbc..b0d456cc 100644 --- a/include/sqlpp11/transaction.h +++ b/include/sqlpp11/transaction.h @@ -35,56 +35,56 @@ namespace sqlpp static constexpr bool report_auto_rollback = true; template - class transaction_t - { - Db& _db; - const bool _report_unfinished_transaction; - bool _finished = false; - - public: - transaction_t(Db& db, bool report_unfinished_transaction): - _db(db), - _report_unfinished_transaction(report_unfinished_transaction) + class transaction_t { - _db.start_transaction(); - } + Db& _db; + const bool _report_unfinished_transaction; + bool _finished = false; - transaction_t(const transaction_t&) = delete; - transaction_t(transaction_t&&) = default; - transaction_t& operator=(const transaction_t&) = delete; - transaction_t& operator=(transaction_t&&) = delete; - - ~transaction_t() - { - if (not _finished) + public: + transaction_t(Db& db, bool report_unfinished_transaction): + _db(db), + _report_unfinished_transaction(report_unfinished_transaction) { - try + _db.start_transaction(); + } + + transaction_t(const transaction_t&) = delete; + transaction_t(transaction_t&&) = default; + transaction_t& operator=(const transaction_t&) = delete; + transaction_t& operator=(transaction_t&&) = delete; + + ~transaction_t() + { + if (not _finished) { - _db.rollback_transaction(_report_unfinished_transaction); - } - catch(const std::exception& e) - { - _db.report_rollback_failure(std::string("auto rollback failed: ") + e.what()); - } - catch(...) - { - _db.report_rollback_failure("auto rollback failed with unknown exception"); + try + { + _db.rollback_transaction(_report_unfinished_transaction); + } + catch(const std::exception& e) + { + _db.report_rollback_failure(std::string("auto rollback failed: ") + e.what()); + } + catch(...) + { + _db.report_rollback_failure("auto rollback failed with unknown exception"); + } } } - } - void commit() - { - _finished = true; - _db.commit_transaction(); - } + void commit() + { + _finished = true; + _db.commit_transaction(); + } - void rollback() - { - _finished = true; - _db.rollback_transaction(false); - } - }; + void rollback() + { + _finished = true; + _db.rollback_transaction(false); + } + }; template transaction_t start_transaction(Db& db, bool report_unfinished_transaction = report_auto_rollback) diff --git a/include/sqlpp11/tvin.h b/include/sqlpp11/tvin.h index 823706c1..82e23b3d 100644 --- a/include/sqlpp11/tvin.h +++ b/include/sqlpp11/tvin.h @@ -61,16 +61,16 @@ namespace sqlpp Operand _value; }; - template - struct serializer_t> - { - using T = tvin_t; + template + struct serializer_t> + { + using T = tvin_t; - static void _(const T& t, Context& context) - { - static_assert(wrong_t::value, "tvin() must not be used with anything but =, ==, != and !"); - } - }; + static void _(const T& t, Context& context) + { + static_assert(wrong_t::value, "tvin() must not be used with anything but =, ==, != and !"); + } + }; template struct maybe_tvin_t @@ -118,31 +118,31 @@ namespace sqlpp typename tvin_t::_operand_t _value; }; - template - struct serializer_t> - { - using T = maybe_tvin_t; + template + struct serializer_t> + { + using T = maybe_tvin_t; - static Context& _(const T& t, Context& context) + static Context& _(const T& t, Context& context) + { + if (t._is_trivial()) { - if (t._is_trivial()) - { - context << "NULL"; - } - else - { - serialize(t._value, context); - } - return context; + context << "NULL"; } - }; + else + { + serialize(t._value, context); + } + return context; + } + }; template auto tvin(Operand operand) -> tvin_t::type> { using _operand_t = typename wrap_operand::type; static_assert(std::is_same<_operand_t, text_operand>::value - or not std::is_same<_operand_t, Operand>::value, "tvin() used with invalid type (only string and primitive types allowed)"); + or not std::is_same<_operand_t, Operand>::value, "tvin() used with invalid type (only string and primitive types allowed)"); return {{operand}}; } diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index 6df505f4..1dc73f39 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -36,57 +36,57 @@ namespace sqlpp namespace detail\ {\ template\ - struct is_##name##_impl: std::false_type {};\ + struct is_##name##_impl: std::false_type {};\ template\ - struct is_##name##_impl::value>::type>: std::true_type {};\ + struct is_##name##_impl::value>::type>: std::true_type {};\ }\ namespace tag\ {\ struct name{};\ };\ template\ - using is_##name##_t = detail::is_element_of; + using is_##name##_t = detail::is_element_of; #define SQLPP_IS_COLUMN_TRAIT_GENERATOR(name) \ namespace detail\ {\ template\ - struct name##_impl { using type = std::false_type; };\ + struct name##_impl { using type = std::false_type; };\ template\ - struct name##_impl::value>::type> { using type = std::true_type; };\ + struct name##_impl::value>::type> { using type = std::true_type; };\ }\ template\ - using name##_t = typename detail::name##_impl::type; + using name##_t = typename detail::name##_impl::type; #define SQLPP_TYPE_TRAIT_GENERATOR(name) \ namespace detail\ {\ template\ - struct name##_impl: std::false_type {};\ + struct name##_impl: std::false_type {};\ template\ - struct name##_impl::value>::type>: std::true_type {};\ + struct name##_impl::value>::type>: std::true_type {};\ }\ template\ - struct name##_t: detail::name##_impl {}; + struct name##_t: detail::name##_impl {}; #define SQLPP_CONNECTOR_TRAIT_GENERATOR(name) \ namespace detail\ {\ template\ - struct connector_##name##_impl: std::false_type {};\ + struct connector_##name##_impl: std::false_type {};\ template\ - struct connector_##name##_impl::value>::type>: std::true_type {};\ + struct connector_##name##_impl::value>::type>: std::true_type {};\ }\ template\ - struct connector_##name##_t: detail::connector_##name##_impl {}; + struct connector_##name##_t: detail::connector_##name##_impl {}; SQLPP_IS_VALUE_TRAIT_GENERATOR(boolean); SQLPP_IS_VALUE_TRAIT_GENERATOR(integral); SQLPP_IS_VALUE_TRAIT_GENERATOR(floating_point); template using is_numeric_t = detail::any_t< - detail::is_element_of::value, - detail::is_element_of::value>; + detail::is_element_of::value, + detail::is_element_of::value>; SQLPP_IS_VALUE_TRAIT_GENERATOR(text); SQLPP_IS_VALUE_TRAIT_GENERATOR(wrapped_value); SQLPP_IS_VALUE_TRAIT_GENERATOR(expression); diff --git a/include/sqlpp11/update.h b/include/sqlpp11/update.h index e598d69b..88e7fdc1 100644 --- a/include/sqlpp11/update.h +++ b/include/sqlpp11/update.h @@ -70,34 +70,34 @@ namespace sqlpp auto _prepare(Db& db) const -> prepared_update_t { - _statement_t::_check_consistency(); + _statement_t::_check_consistency(); - return {{}, db.prepare_update(*this)}; + return {{}, db.prepare_update(*this)}; } */ }; }; - template - struct serializer_t + template + struct serializer_t + { + using T = update_name_t; + + static Context& _(const T& t, Context& context) { - using T = update_name_t; + context << "UPDATE "; - static Context& _(const T& t, Context& context) - { - context << "UPDATE "; - - return context; - } - }; + return context; + } + }; template using blank_update_t = statement_t; + update_t, + no_single_table_t, + no_update_list_t, + no_where_t>; template constexpr auto update(Table table) diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index a311bef0..9b3c9626 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -34,127 +34,88 @@ namespace sqlpp { - // UPDATE ASSIGNMENTS DATA - template - struct update_list_data_t - { - update_list_data_t(Assignments... assignments): - _assignments(assignments...) - {} + // UPDATE ASSIGNMENTS DATA + template + struct update_list_data_t + { + update_list_data_t(Assignments... assignments): + _assignments(assignments...) + {} - update_list_data_t(const update_list_data_t&) = default; - update_list_data_t(update_list_data_t&&) = default; - update_list_data_t& operator=(const update_list_data_t&) = default; - update_list_data_t& operator=(update_list_data_t&&) = default; - ~update_list_data_t() = default; + update_list_data_t(const update_list_data_t&) = default; + update_list_data_t(update_list_data_t&&) = default; + update_list_data_t& operator=(const update_list_data_t&) = default; + update_list_data_t& operator=(update_list_data_t&&) = default; + ~update_list_data_t() = default; - std::tuple _assignments; - typename interpretable_list_t _dynamic_assignments; - }; + std::tuple _assignments; + typename interpretable_list_t _dynamic_assignments; + }; - // UPDATE ASSIGNMENTS - template - struct update_list_t - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits; - using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; + // UPDATE ASSIGNMENTS + template + struct update_list_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - static_assert(_is_dynamic::value or sizeof...(Assignments), "at least one assignment expression required in set()"); + static_assert(_is_dynamic::value or sizeof...(Assignments), "at least one assignment expression required in set()"); - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in set()"); + static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in set()"); - static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an assignment in set()"); + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an assignment in set()"); - static_assert(::sqlpp::detail::none_t::value...>::value, "at least one assignment is prohibited by its column definition in set()"); + static_assert(::sqlpp::detail::none_t::value...>::value, "at least one assignment is prohibited by its column definition in set()"); #warning reactivate tests - /* - using _column_table_set = typename ::sqlpp::detail::make_joined_set::type; - using _value_table_set = typename ::sqlpp::detail::make_joined_set::type; - using _table_set = typename ::sqlpp::detail::make_joined_set<_column_table_set, _value_table_set>::type; - static_assert(sizeof...(Assignments) ? (_column_table_set::size::value == 1) : true, "set() contains assignments for tables from several columns"); - static_assert(::sqlpp::detail::is_subset_of<_value_table_set, _column_table_set>::value, "set() contains values from foreign tables"); - */ - - // Data - using _data_t = update_list_data_t; - - // Member implementation with data and methods - template - struct _impl_t - { - template - void add_ntc(Assignment assignment) - { - add(assignment); - } - - template - void add(Assignment assignment) - { - static_assert(_is_dynamic::value, "add must not be called for static from()"); - static_assert(is_assignment_t::value, "invalid assignment argument in add()"); - static_assert(sqlpp::detail::not_t::value, "add() argument must not be updated"); - static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "assignment uses tables unknown to this statement in add()"); - - using ok = ::sqlpp::detail::all_t< - _is_dynamic::value, - is_assignment_t::value, - not must_not_update_t::value>; - - _add_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert - } - - private: - template - void _add_impl(Assignment assignment, const std::true_type&) - { - return _data._dynamic_assignments.emplace_back(assignment); - } - - template - void _add_impl(Assignment assignment, const std::false_type&); - public: - _data_t _data; - }; - - // Member template for adding the named member to a statement - template - struct _member_t - { - using _data_t = update_list_data_t; - - _impl_t assignments; - _impl_t& operator()() { return assignments; } - const _impl_t& operator()() const { return assignments; } - - template - static auto _get_member(T t) -> decltype(t.assignments) - { - return t.assignments; - } - }; - - // Additional methods for the statement - template - struct _methods_t - { - }; - }; - - struct no_update_list_t - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; + /* + using _column_table_set = typename ::sqlpp::detail::make_joined_set::type; + using _value_table_set = typename ::sqlpp::detail::make_joined_set::type; + using _table_set = typename ::sqlpp::detail::make_joined_set<_column_table_set, _value_table_set>::type; + static_assert(sizeof...(Assignments) ? (_column_table_set::size::value == 1) : true, "set() contains assignments for tables from several columns"); + static_assert(::sqlpp::detail::is_subset_of<_value_table_set, _column_table_set>::value, "set() contains values from foreign tables"); + */ // Data - using _data_t = no_data_t; + using _data_t = update_list_data_t; // Member implementation with data and methods - template + template struct _impl_t { + template + void add_ntc(Assignment assignment) + { + add(assignment); + } + + template + void add(Assignment assignment) + { + static_assert(_is_dynamic::value, "add must not be called for static from()"); + static_assert(is_assignment_t::value, "invalid assignment argument in add()"); + static_assert(sqlpp::detail::not_t::value, "add() argument must not be updated"); + static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "assignment uses tables unknown to this statement in add()"); + + using ok = ::sqlpp::detail::all_t< + _is_dynamic::value, + is_assignment_t::value, + not must_not_update_t::value>; + + _add_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert + } + + private: + template + void _add_impl(Assignment assignment, const std::true_type&) + { + return _data._dynamic_assignments.emplace_back(assignment); + } + + template + void _add_impl(Assignment assignment, const std::false_type&); + public: _data_t _data; }; @@ -162,59 +123,98 @@ namespace sqlpp template struct _member_t { - using _data_t = no_data_t; + using _data_t = update_list_data_t; - _impl_t no_assignments; - _impl_t& operator()() { return no_assignments; } - const _impl_t& operator()() const { return no_assignments; } + _impl_t assignments; + _impl_t& operator()() { return assignments; } + const _impl_t& operator()() const { return assignments; } template - static auto _get_member(T t) -> decltype(t.no_assignments) + static auto _get_member(T t) -> decltype(t.assignments) { - return t.no_assignments; + return t.assignments; } }; + // Additional methods for the statement template struct _methods_t { - using _database_t = typename Policies::_database_t; - template - using _new_statement_t = typename Policies::template _new_statement_t; - - template - auto set(Args... args) - -> _new_statement_t> - { - return { *static_cast(this), update_list_data_t{args...} }; - } - - template - auto dynamic_set(Args... args) - -> _new_statement_t> - { - static_assert(not std::is_same<_database_t, void>::value, "dynamic_set must not be called in a static statement"); - return { *static_cast(this), update_list_data_t<_database_t, Args...>{args...} }; - } }; }; - // Interpreters - template - struct serializer_t> - { - using T = update_list_data_t; + struct no_update_list_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; - static Context& _(const T& t, Context& context) - { - context << " SET "; - interpret_tuple(t._assignments, ",", context); - if (sizeof...(Assignments) and not t._dynamic_assignments.empty()) - context << ','; - interpret_list(t._dynamic_assignments, ',', context); - return context; - } + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; + + _impl_t no_assignments; + _impl_t& operator()() { return no_assignments; } + const _impl_t& operator()() const { return no_assignments; } + + template + static auto _get_member(T t) -> decltype(t.no_assignments) + { + return t.no_assignments; + } + }; + + template + struct _methods_t + { + using _database_t = typename Policies::_database_t; + template + using _new_statement_t = typename Policies::template _new_statement_t; + + template + auto set(Args... args) + -> _new_statement_t> + { + return { *static_cast(this), update_list_data_t{args...} }; + } + + template + auto dynamic_set(Args... args) + -> _new_statement_t> + { + static_assert(not std::is_same<_database_t, void>::value, "dynamic_set must not be called in a static statement"); + return { *static_cast(this), update_list_data_t<_database_t, Args...>{args...} }; + } + }; + }; + + // Interpreters + template + struct serializer_t> + { + using T = update_list_data_t; + + static Context& _(const T& t, Context& context) + { + context << " SET "; + interpret_tuple(t._assignments, ",", context); + if (sizeof...(Assignments) and not t._dynamic_assignments.empty()) + context << ','; + interpret_list(t._dynamic_assignments, ',', context); + return context; + } + }; } #endif diff --git a/include/sqlpp11/using.h b/include/sqlpp11/using.h index 6aabd249..0d345906 100644 --- a/include/sqlpp11/using.h +++ b/include/sqlpp11/using.h @@ -35,108 +35,68 @@ namespace sqlpp { - // USING DATA - template - struct using_data_t - { - using_data_t(Tables... tables): - _tables(tables...) - {} - - using_data_t(const using_data_t&) = default; - using_data_t(using_data_t&&) = default; - using_data_t& operator=(const using_data_t&) = default; - using_data_t& operator=(using_data_t&&) = default; - ~using_data_t() = default; - - std::tuple _tables; - interpretable_list_t _dynamic_tables; - }; - - // USING - template - struct using_t - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits; - - using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - - static_assert(_is_dynamic::value or sizeof...(Tables), "at least one table argument required in using()"); - - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in using()"); - - static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an table in using()"); - - // Data - using _data_t = using_data_t; - - // Member implementation with data and methods - template - struct _impl_t - { - template - void add(Table table) - { - static_assert(_is_dynamic::value, "add must not be called for static using()"); - static_assert(is_table_t
::value, "invalid table argument in add()"); - - using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_table_t
::value>; - - _add_impl(table, ok()); // dispatch to prevent compile messages after the static_assert - } - - private: - template - void _add_impl(Table table, const std::true_type&) - { - return _data._dynamic_tables.emplace_back(table); - } - - template - void _add_impl(Table table, const std::false_type&); - - public: - _data_t _data; - }; - - // Member template for adding the named member to a statement - template - struct _member_t - { - using _data_t = using_data_t; - - _impl_t using_; - _impl_t& operator()() { return using_; } - const _impl_t& operator()() const { return using_; } - - template - static auto _get_member(T t) -> decltype(t.using_) - { - return t.using_; - } - }; - - // Additional methods for the statement - template - struct _methods_t - { - }; - }; - - // NO USING YET - struct no_using_t + // USING DATA + template + struct using_data_t { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; + using_data_t(Tables... tables): + _tables(tables...) + {} + + using_data_t(const using_data_t&) = default; + using_data_t(using_data_t&&) = default; + using_data_t& operator=(const using_data_t&) = default; + using_data_t& operator=(using_data_t&&) = default; + ~using_data_t() = default; + + std::tuple _tables; + interpretable_list_t _dynamic_tables; + }; + + // USING + template + struct using_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + + using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; + + static_assert(_is_dynamic::value or sizeof...(Tables), "at least one table argument required in using()"); + + static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in using()"); + + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an table in using()"); // Data - using _data_t = no_data_t; + using _data_t = using_data_t; // Member implementation with data and methods - template + template struct _impl_t { + template + void add(Table table) + { + static_assert(_is_dynamic::value, "add must not be called for static using()"); + static_assert(is_table_t
::value, "invalid table argument in add()"); + + using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_table_t
::value>; + + _add_impl(table, ok()); // dispatch to prevent compile messages after the static_assert + } + + private: + template + void _add_impl(Table table, const std::true_type&) + { + return _data._dynamic_tables.emplace_back(table); + } + + template + void _add_impl(Table table, const std::false_type&); + + public: _data_t _data; }; @@ -144,61 +104,101 @@ namespace sqlpp template struct _member_t { - using _data_t = no_data_t; + using _data_t = using_data_t; - _impl_t no_using; - _impl_t& operator()() { return no_using; } - const _impl_t& operator()() const { return no_using; } + _impl_t using_; + _impl_t& operator()() { return using_; } + const _impl_t& operator()() const { return using_; } template - static auto _get_member(T t) -> decltype(t.no_using) + static auto _get_member(T t) -> decltype(t.using_) { - return t.no_using; + return t.using_; } }; + // Additional methods for the statement template struct _methods_t { - using _database_t = typename Policies::_database_t; - template - using _new_statement_t = typename Policies::template _new_statement_t; - - template - auto using_(Args... args) - -> _new_statement_t> - { - return { *static_cast(this), using_data_t{args...} }; - } - - template - auto dynamic_using(Args... args) - -> _new_statement_t> - { - static_assert(not std::is_same<_database_t, void>::value, "dynamic_using must not be called in a static statement"); - return { *static_cast(this), using_data_t<_database_t, Args...>{args...} }; - } }; }; - // Interpreters - template - struct serializer_t> - { - using T = using_data_t; + // NO USING YET + struct no_using_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; - static Context& _(const T& t, Context& context) - { - if (sizeof...(Tables) == 0 and t._dynamic_tables.empty()) - return context; - context << " USING "; - interpret_tuple(t._tables, ',', context); - if (sizeof...(Tables) and not t._dynamic_tables.empty()) - context << ','; - interpret_list(t._dynamic_tables, ',', context); - return context; - } + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; }; + + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; + + _impl_t no_using; + _impl_t& operator()() { return no_using; } + const _impl_t& operator()() const { return no_using; } + + template + static auto _get_member(T t) -> decltype(t.no_using) + { + return t.no_using; + } + }; + + template + struct _methods_t + { + using _database_t = typename Policies::_database_t; + template + using _new_statement_t = typename Policies::template _new_statement_t; + + template + auto using_(Args... args) + -> _new_statement_t> + { + return { *static_cast(this), using_data_t{args...} }; + } + + template + auto dynamic_using(Args... args) + -> _new_statement_t> + { + static_assert(not std::is_same<_database_t, void>::value, "dynamic_using must not be called in a static statement"); + return { *static_cast(this), using_data_t<_database_t, Args...>{args...} }; + } + }; + }; + + // Interpreters + template + struct serializer_t> + { + using T = using_data_t; + + static Context& _(const T& t, Context& context) + { + if (sizeof...(Tables) == 0 and t._dynamic_tables.empty()) + return context; + context << " USING "; + interpret_tuple(t._tables, ',', context); + if (sizeof...(Tables) and not t._dynamic_tables.empty()) + context << ','; + interpret_list(t._dynamic_tables, ',', context); + return context; + } + }; } #endif diff --git a/include/sqlpp11/value_type.h b/include/sqlpp11/value_type.h index e7f38198..2fa3bee1 100644 --- a/include/sqlpp11/value_type.h +++ b/include/sqlpp11/value_type.h @@ -32,7 +32,7 @@ namespace sqlpp { - template - using value_type_t = value_type_of>; + template + using value_type_t = value_type_of>; } #endif diff --git a/include/sqlpp11/verbatim_table.h b/include/sqlpp11/verbatim_table.h index 39799bfe..7d6d15e4 100644 --- a/include/sqlpp11/verbatim_table.h +++ b/include/sqlpp11/verbatim_table.h @@ -63,17 +63,17 @@ namespace sqlpp std::string _name; }; - template - struct serializer_t - { - using T = verbatim_table_t; + template + struct serializer_t + { + using T = verbatim_table_t; - static Context& _(const T& t, Context& context) - { - context << t._name; - return context; - } - }; + static Context& _(const T& t, Context& context) + { + context << t._name; + return context; + } + }; verbatim_table_t verbatim_table(std::string name) diff --git a/include/sqlpp11/where.h b/include/sqlpp11/where.h index 93331606..8c9446e7 100644 --- a/include/sqlpp11/where.h +++ b/include/sqlpp11/where.h @@ -36,157 +36,116 @@ namespace sqlpp { - // WHERE DATA - template - struct where_data_t - { - where_data_t(Expressions... expressions): - _expressions(expressions...) - {} + // WHERE DATA + template + struct where_data_t + { + where_data_t(Expressions... expressions): + _expressions(expressions...) + {} - where_data_t(const where_data_t&) = default; - where_data_t(where_data_t&&) = default; - where_data_t& operator=(const where_data_t&) = default; - where_data_t& operator=(where_data_t&&) = default; - ~where_data_t() = default; + where_data_t(const where_data_t&) = default; + where_data_t(where_data_t&&) = default; + where_data_t& operator=(const where_data_t&) = default; + where_data_t& operator=(where_data_t&&) = default; + ~where_data_t() = default; - std::tuple _expressions; - interpretable_list_t _dynamic_expressions; - }; + std::tuple _expressions; + interpretable_list_t _dynamic_expressions; + }; - // WHERE(EXPR) - template - struct where_t - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits; + // WHERE(EXPR) + template + struct where_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; #warning: is_dynamic should be using a template alias (making it easier to replace the logic) - using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; + using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression argument required in where()"); - static_assert(sqlpp::detail::none_t::value...>::value, "at least one argument is an assignment in where()"); - static_assert(sqlpp::detail::all_t::value...>::value, "at least one argument is not valid expression in where()"); + static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression argument required in where()"); + static_assert(sqlpp::detail::none_t::value...>::value, "at least one argument is an assignment in where()"); + static_assert(sqlpp::detail::all_t::value...>::value, "at least one argument is not valid expression in where()"); - // Data - using _data_t = where_data_t; + // Data + using _data_t = where_data_t; - // Member implementation with data and methods - template - struct _impl_t - { - template - void add_ntc(Expression expression) - { - add(expression); - } + // Member implementation with data and methods + template + struct _impl_t + { + template + void add_ntc(Expression expression) + { + add(expression); + } - template - void add(Expression expression) - { - static_assert(_is_dynamic::value, "where::add() can only be called for dynamic_where"); - static_assert(is_expression_t::value, "invalid expression argument in where::add()"); - static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in where::add()"); + template + void add(Expression expression) + { + static_assert(_is_dynamic::value, "where::add() can only be called for dynamic_where"); + static_assert(is_expression_t::value, "invalid expression argument in where::add()"); + static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in where::add()"); - using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; + using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; - _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert - } + _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert + } - private: - template - void _add_impl(Expression expression, const std::true_type&) - { - return _data._dynamic_expressions.emplace_back(expression); - } + private: + template + void _add_impl(Expression expression, const std::true_type&) + { + return _data._dynamic_expressions.emplace_back(expression); + } - template - void _add_impl(Expression expression, const std::false_type&); + template + void _add_impl(Expression expression, const std::false_type&); - public: - _data_t _data; - }; + public: + _data_t _data; + }; - // Member template for adding the named member to a statement - template - struct _member_t - { - using _data_t = where_data_t; + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = where_data_t; - _impl_t where; - _impl_t& operator()() { return where; } - const _impl_t& operator()() const { return where; } + _impl_t where; + _impl_t& operator()() { return where; } + const _impl_t& operator()() const { return where; } - template - static auto _get_member(T t) -> decltype(t.where) - { - return t.where; - } - }; + template + static auto _get_member(T t) -> decltype(t.where) + { + return t.where; + } + }; - // Additional methods for the statement - template - struct _methods_t - { - }; - }; + // Additional methods for the statement + template + struct _methods_t + { + }; + }; - template<> - struct where_data_t - { - bool _condition; - }; + template<> + struct where_data_t + { + bool _condition; + }; - // WHERE(BOOL) - template<> - struct where_t - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; - - // Data - using _data_t = where_data_t; - - // Member implementation with data and methods - template - struct _impl_t - { - _data_t _data; - }; - - // Member template for adding the named member to a statement - template - struct _member_t - { - using _data_t = where_data_t; - - _impl_t where; - _impl_t& operator()() { return where; } - const _impl_t& operator()() const { return where; } - - template - static auto _get_member(T t) -> decltype(t.where) - { - return t.where; - } - }; - - // Additional methods for the statement - template - struct _methods_t - { - }; - - }; - - // NO WHERE YET - struct no_where_t + // WHERE(BOOL) + template<> + struct where_t { using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; // Data - using _data_t = no_data_t; + using _data_t = where_data_t; // Member implementation with data and methods template @@ -199,16 +158,16 @@ namespace sqlpp template struct _member_t { - using _data_t = no_data_t; + using _data_t = where_data_t; - _impl_t no_where; - _impl_t& operator()() { return no_where; } - const _impl_t& operator()() const { return no_where; } + _impl_t where; + _impl_t& operator()() { return where; } + const _impl_t& operator()() const { return where; } template - static auto _get_member(T t) -> decltype(t.no_where) + static auto _get_member(T t) -> decltype(t.where) { - return t.no_where; + return t.where; } }; @@ -216,59 +175,100 @@ namespace sqlpp template struct _methods_t { - using _database_t = typename Policies::_database_t; - template - using _new_statement_t = typename Policies::template _new_statement_t; - - template - auto where(Args... args) - -> _new_statement_t> - { - return { *static_cast(this), where_data_t{args...} }; - } - - template - auto dynamic_where(Args... args) - -> _new_statement_t> - { - static_assert(not std::is_same<_database_t, void>::value, "dynamic_where must not be called in a static statement"); - return { *static_cast(this), where_data_t<_database_t, Args...>{args...} }; - } }; + }; - // Interpreters - template - struct serializer_t> - { - using T = where_data_t; + // NO WHERE YET + struct no_where_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; - static Context& _(const T& t, Context& context) - { - if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty()) - return context; - context << " WHERE "; - interpret_tuple(t._expressions, " AND ", context); - if (sizeof...(Expressions) and not t._dynamic_expressions.empty()) - context << " AND "; - interpret_list(t._dynamic_expressions, " AND ", context); - return context; - } + // Data + using _data_t = no_data_t; + + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; }; - template - struct serializer_t> + // Member template for adding the named member to a statement + template + struct _member_t { - using T = where_data_t; + using _data_t = no_data_t; - static Context& _(const T& t, Context& context) - { - if (not t._condition) - context << " WHERE NULL"; - return context; - } + _impl_t no_where; + _impl_t& operator()() { return no_where; } + const _impl_t& operator()() const { return no_where; } + + template + static auto _get_member(T t) -> decltype(t.no_where) + { + return t.no_where; + } }; + // Additional methods for the statement + template + struct _methods_t + { + using _database_t = typename Policies::_database_t; + template + using _new_statement_t = typename Policies::template _new_statement_t; + + template + auto where(Args... args) + -> _new_statement_t> + { + return { *static_cast(this), where_data_t{args...} }; + } + + template + auto dynamic_where(Args... args) + -> _new_statement_t> + { + static_assert(not std::is_same<_database_t, void>::value, "dynamic_where must not be called in a static statement"); + return { *static_cast(this), where_data_t<_database_t, Args...>{args...} }; + } + }; + }; + + // Interpreters + template + struct serializer_t> + { + using T = where_data_t; + + static Context& _(const T& t, Context& context) + { + if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty()) + return context; + context << " WHERE "; + interpret_tuple(t._expressions, " AND ", context); + if (sizeof...(Expressions) and not t._dynamic_expressions.empty()) + context << " AND "; + interpret_list(t._dynamic_expressions, " AND ", context); + return context; + } + }; + + template + struct serializer_t> + { + using T = where_data_t; + + static Context& _(const T& t, Context& context) + { + if (not t._condition) + context << " WHERE NULL"; + return context; + } + }; + } #endif diff --git a/include/sqlpp11/wrap_operand.h b/include/sqlpp11/wrap_operand.h index e5be8c06..177f9294 100644 --- a/include/sqlpp11/wrap_operand.h +++ b/include/sqlpp11/wrap_operand.h @@ -41,193 +41,193 @@ namespace sqlpp struct text; } - struct boolean_operand + struct boolean_operand + { + using _traits = make_traits<::sqlpp::detail::boolean, ::sqlpp::tag::expression, ::sqlpp::tag::wrapped_value>; + using _recursive_traits = make_recursive_traits<>; + + using _value_t = bool; + + boolean_operand(): + _t{} + {} + + boolean_operand(_value_t t): + _t(t) + {} + + boolean_operand(const boolean_operand&) = default; + boolean_operand(boolean_operand&&) = default; + boolean_operand& operator=(const boolean_operand&) = default; + boolean_operand& operator=(boolean_operand&&) = default; + ~boolean_operand() = default; + + bool _is_trivial() const { return _t == false; } + + _value_t _t; + }; + + template + struct serializer_t { - using _traits = make_traits<::sqlpp::detail::boolean, ::sqlpp::tag::expression, ::sqlpp::tag::wrapped_value>; - using _recursive_traits = make_recursive_traits<>; + using Operand = boolean_operand; - using _value_t = bool; - - boolean_operand(): - _t{} - {} - - boolean_operand(_value_t t): - _t(t) - {} - - boolean_operand(const boolean_operand&) = default; - boolean_operand(boolean_operand&&) = default; - boolean_operand& operator=(const boolean_operand&) = default; - boolean_operand& operator=(boolean_operand&&) = default; - ~boolean_operand() = default; - - bool _is_trivial() const { return _t == false; } - - _value_t _t; + static Context& _(const Operand& t, Context& context) + { + context << t._t; + return context; + } }; - template - struct serializer_t - { - using Operand = boolean_operand; + struct integral_operand + { + using _traits = make_traits<::sqlpp::detail::integral, ::sqlpp::tag::expression, ::sqlpp::tag::wrapped_value>; + using _recursive_traits = make_recursive_traits<>; - static Context& _(const Operand& t, Context& context) - { - context << t._t; - return context; - } - }; + using _value_t = int64_t; - struct integral_operand + integral_operand(): + _t{} + {} + + integral_operand(_value_t t): + _t(t) + {} + + integral_operand(const integral_operand&) = default; + integral_operand(integral_operand&&) = default; + integral_operand& operator=(const integral_operand&) = default; + integral_operand& operator=(integral_operand&&) = default; + ~integral_operand() = default; + + bool _is_trivial() const { return _t == 0; } + + _value_t _t; + }; + + template + struct serializer_t { - using _traits = make_traits<::sqlpp::detail::integral, ::sqlpp::tag::expression, ::sqlpp::tag::wrapped_value>; - using _recursive_traits = make_recursive_traits<>; + using Operand = integral_operand; - using _value_t = int64_t; - - integral_operand(): - _t{} - {} - - integral_operand(_value_t t): - _t(t) - {} - - integral_operand(const integral_operand&) = default; - integral_operand(integral_operand&&) = default; - integral_operand& operator=(const integral_operand&) = default; - integral_operand& operator=(integral_operand&&) = default; - ~integral_operand() = default; - - bool _is_trivial() const { return _t == 0; } - - _value_t _t; + static Context& _(const Operand& t, Context& context) + { + context << t._t; + return context; + } }; - template - struct serializer_t - { - using Operand = integral_operand; - static Context& _(const Operand& t, Context& context) - { - context << t._t; - return context; - } - }; + struct floating_point_operand + { + using _traits = make_traits<::sqlpp::detail::floating_point, ::sqlpp::tag::expression, ::sqlpp::tag::wrapped_value>; + using _recursive_traits = make_recursive_traits<>; + using _value_t = double; - struct floating_point_operand + floating_point_operand(): + _t{} + {} + + floating_point_operand(_value_t t): + _t(t) + {} + + floating_point_operand(const floating_point_operand&) = default; + floating_point_operand(floating_point_operand&&) = default; + floating_point_operand& operator=(const floating_point_operand&) = default; + floating_point_operand& operator=(floating_point_operand&&) = default; + ~floating_point_operand() = default; + + bool _is_trivial() const { return _t == 0; } + + _value_t _t; + }; + + template + struct serializer_t { - using _traits = make_traits<::sqlpp::detail::floating_point, ::sqlpp::tag::expression, ::sqlpp::tag::wrapped_value>; - using _recursive_traits = make_recursive_traits<>; + using Operand = floating_point_operand; - using _value_t = double; - - floating_point_operand(): - _t{} - {} - - floating_point_operand(_value_t t): - _t(t) - {} - - floating_point_operand(const floating_point_operand&) = default; - floating_point_operand(floating_point_operand&&) = default; - floating_point_operand& operator=(const floating_point_operand&) = default; - floating_point_operand& operator=(floating_point_operand&&) = default; - ~floating_point_operand() = default; - - bool _is_trivial() const { return _t == 0; } - - _value_t _t; + static Context& _(const Operand& t, Context& context) + { + context << t._t; + return context; + } }; - template - struct serializer_t - { - using Operand = floating_point_operand; + struct text_operand + { + using _traits = make_traits<::sqlpp::detail::text, ::sqlpp::tag::expression, ::sqlpp::tag::wrapped_value>; + using _recursive_traits = make_recursive_traits<>; - static Context& _(const Operand& t, Context& context) - { - context << t._t; - return context; - } - }; + using _value_t = std::string; - struct text_operand + text_operand(): + _t{} + {} + + text_operand(_value_t t): + _t(t) + {} + + text_operand(const text_operand&) = default; + text_operand(text_operand&&) = default; + text_operand& operator=(const text_operand&) = default; + text_operand& operator=(text_operand&&) = default; + ~text_operand() = default; + + bool _is_trivial() const { return _t.empty(); } + + _value_t _t; + }; + + template + struct serializer_t { - using _traits = make_traits<::sqlpp::detail::text, ::sqlpp::tag::expression, ::sqlpp::tag::wrapped_value>; - using _recursive_traits = make_recursive_traits<>; + using Operand = text_operand; - using _value_t = std::string; - - text_operand(): - _t{} - {} - - text_operand(_value_t t): - _t(t) - {} - - text_operand(const text_operand&) = default; - text_operand(text_operand&&) = default; - text_operand& operator=(const text_operand&) = default; - text_operand& operator=(text_operand&&) = default; - ~text_operand() = default; - - bool _is_trivial() const { return _t.empty(); } - - _value_t _t; + static Context& _(const Operand& t, Context& context) + { + context << '\'' << context.escape(t._t) << '\''; + return context; + } }; - template - struct serializer_t - { - using Operand = text_operand; + template + struct wrap_operand + { + using type = T; + }; - static Context& _(const Operand& t, Context& context) - { - context << '\'' << context.escape(t._t) << '\''; - return context; - } - }; + template<> + struct wrap_operand + { + using type = boolean_operand; + }; - template - struct wrap_operand - { - using type = T; - }; + template + struct wrap_operand::value>::type> + { + using type = integral_operand; + }; - template<> - struct wrap_operand - { - using type = boolean_operand; - }; + template + struct wrap_operand::value>::type> + { + using type = floating_point_operand; + }; - template - struct wrap_operand::value>::type> - { - using type = integral_operand; - }; + template + struct wrap_operand::value>::type> + { + using type = text_operand; + }; - template - struct wrap_operand::value>::type> - { - using type = floating_point_operand; - }; + // FIXME: Need to allow std::ref arguments - template - struct wrap_operand::value>::type> - { - using type = text_operand; - }; - - // FIXME: Need to allow std::ref arguments - - template - using wrap_operand_t = typename wrap_operand::type; + template + using wrap_operand_t = typename wrap_operand::type; } diff --git a/include/sqlpp11/wrong.h b/include/sqlpp11/wrong.h index af7ce7f4..9249673e 100644 --- a/include/sqlpp11/wrong.h +++ b/include/sqlpp11/wrong.h @@ -31,18 +31,18 @@ namespace sqlpp { - namespace detail - { - // A template that always returns false - // To be used with static assert, for instance, to ensure it - // fires only when the template is instantiated. - template - struct wrong - { - using type = std::false_type; - }; - } + namespace detail + { + // A template that always returns false + // To be used with static assert, for instance, to ensure it + // fires only when the template is instantiated. template - using wrong_t = typename detail::wrong::type; + struct wrong + { + using type = std::false_type; + }; + } + template + using wrong_t = typename detail::wrong::type; } #endif From ef6c7e0c0dee784faccf1d8abe5263f7683ed6e4 Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 14 Jun 2014 07:49:43 +0200 Subject: [PATCH 35/65] Removed a few obsolete "typename" --- include/sqlpp11/any.h | 2 +- include/sqlpp11/avg.h | 4 ++-- include/sqlpp11/count.h | 4 ++-- include/sqlpp11/exists.h | 2 +- include/sqlpp11/max.h | 2 +- include/sqlpp11/min.h | 2 +- include/sqlpp11/some.h | 2 +- include/sqlpp11/sum.h | 4 ++-- include/sqlpp11/update_list.h | 2 +- tests/CMakeLists.txt | 6 +++--- 10 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/sqlpp11/any.h b/include/sqlpp11/any.h index c2f6258f..a193b825 100644 --- a/include/sqlpp11/any.h +++ b/include/sqlpp11/any.h @@ -78,7 +78,7 @@ namespace sqlpp }; template - auto any(T t) -> typename any_t> + auto any(T t) -> any_t> { static_assert(is_select_t>::value, "any() requires a select expression as argument"); static_assert(is_expression_t>::value, "any() requires a single column select expression as argument"); diff --git a/include/sqlpp11/avg.h b/include/sqlpp11/avg.h index 46bba2b3..e4470be9 100644 --- a/include/sqlpp11/avg.h +++ b/include/sqlpp11/avg.h @@ -86,14 +86,14 @@ namespace sqlpp }; template - auto avg(T t) -> typename avg_t> + auto avg(T t) -> avg_t> { static_assert(is_numeric_t>::value, "avg() requires a value expression as argument"); return { t }; } template - auto avg(const sqlpp::distinct_t&, T t) -> typename avg_t> + auto avg(const sqlpp::distinct_t&, T t) -> avg_t> { static_assert(is_numeric_t>::value, "avg() requires a value expression as argument"); return { t }; diff --git a/include/sqlpp11/count.h b/include/sqlpp11/count.h index 3e61bb53..af24e47b 100644 --- a/include/sqlpp11/count.h +++ b/include/sqlpp11/count.h @@ -87,14 +87,14 @@ namespace sqlpp }; template - auto count(T t) -> typename count_t> + auto count(T t) -> count_t> { static_assert(is_expression_t>::value, "count() requires an expression as argument"); return { t }; } template - auto count(const sqlpp::distinct_t&, T t) -> typename count_t> + auto count(const sqlpp::distinct_t&, T t) -> count_t> { static_assert(is_expression_t>::value, "count() requires an expression as argument"); return { t }; diff --git a/include/sqlpp11/exists.h b/include/sqlpp11/exists.h index ca993727..54f28208 100644 --- a/include/sqlpp11/exists.h +++ b/include/sqlpp11/exists.h @@ -81,7 +81,7 @@ namespace sqlpp template - auto exists(T t) -> typename exists_t> + auto exists(T t) -> exists_t> { static_assert(is_select_t>::value, "exists() requires a select expression as argument"); return { t }; diff --git a/include/sqlpp11/max.h b/include/sqlpp11/max.h index 46489282..a96dfe4d 100644 --- a/include/sqlpp11/max.h +++ b/include/sqlpp11/max.h @@ -80,7 +80,7 @@ namespace sqlpp }; template - auto max(T t) -> typename max_t> + auto max(T t) -> max_t> { static_assert(is_expression_t>::value, "max() requires a value expression as argument"); return { t }; diff --git a/include/sqlpp11/min.h b/include/sqlpp11/min.h index 0ae1248a..3993bf81 100644 --- a/include/sqlpp11/min.h +++ b/include/sqlpp11/min.h @@ -80,7 +80,7 @@ namespace sqlpp }; template - auto min(T t) -> typename min_t> + auto min(T t) -> min_t> { static_assert(is_expression_t>::value, "min() requires a value expression as argument"); return { t }; diff --git a/include/sqlpp11/some.h b/include/sqlpp11/some.h index 1fb864c8..41519e5e 100644 --- a/include/sqlpp11/some.h +++ b/include/sqlpp11/some.h @@ -78,7 +78,7 @@ namespace sqlpp }; template - auto some(T t) -> typename some_t> + auto some(T t) -> some_t> { static_assert(is_select_t>::value, "some() requires a single column select expression as argument"); static_assert(is_expression_t>::value, "some() requires a single column select expression as argument"); diff --git a/include/sqlpp11/sum.h b/include/sqlpp11/sum.h index d22f008f..89045be9 100644 --- a/include/sqlpp11/sum.h +++ b/include/sqlpp11/sum.h @@ -86,14 +86,14 @@ namespace sqlpp }; template - auto sum(T t) -> typename sum_t> + auto sum(T t) -> sum_t> { static_assert(is_numeric_t>::value, "sum() requires a numeric expression as argument"); return { t }; } template - auto sum(const sqlpp::distinct_t&, T t) -> typename sum_t> + auto sum(const sqlpp::distinct_t&, T t) -> sum_t> { static_assert(is_numeric_t>::value, "sum() requires a numeric expression as argument"); return { t }; diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index 9b3c9626..e09be547 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -49,7 +49,7 @@ namespace sqlpp ~update_list_data_t() = default; std::tuple _assignments; - typename interpretable_list_t _dynamic_assignments; + interpretable_list_t _dynamic_assignments; }; // UPDATE ASSIGNMENTS diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9de5e4e2..9ea24a1f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,9 +8,9 @@ endmacro () #build_and_run(InterpretTest) build_and_run(InsertTest) -#build_and_run(RemoveTest) -#build_and_run(UpdateTest) -#build_and_run(SelectTest) +build_and_run(RemoveTest) +build_and_run(UpdateTest) +build_and_run(SelectTest) #build_and_run(SelectTypeTest) #build_and_run(FunctionTest) #build_and_run(PreparedTest) From ca76ccbf6583b5190b3d09ae4beac7296c05a0e4 Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 14 Jun 2014 10:15:42 +0200 Subject: [PATCH 36/65] Minor fix. --- tests/SelectTypeTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/SelectTypeTest.cpp b/tests/SelectTypeTest.cpp index 396c569b..8e19ec4e 100644 --- a/tests/SelectTypeTest.cpp +++ b/tests/SelectTypeTest.cpp @@ -337,7 +337,7 @@ int main() static_assert(sqlpp::is_select_flag_t::value, "sqlpp::all has to be a select_flag"); - using T = sqlpp::vendor::wrap_operand::type; + using T = sqlpp::wrap_operand::type; static_assert(sqlpp::is_regular::value, "type requirement"); static_assert(sqlpp::is_expression_t::value, "T has to be an expression"); static_assert(sqlpp::is_numeric_t::value, "T has to be numeric"); From e775e6165e9ddcd74ed36755866833c2ec095e5f Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 14 Jun 2014 10:17:21 +0200 Subject: [PATCH 37/65] Removed obsolete namespace specifier in test after removing namespace vendor --- tests/InterpretTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/InterpretTest.cpp b/tests/InterpretTest.cpp index 08c33f94..528bf21f 100644 --- a/tests/InterpretTest.cpp +++ b/tests/InterpretTest.cpp @@ -101,7 +101,7 @@ int main() serialize(remove_from(t).using_(t).where(t.alpha == sqlpp::tvin(0)), printer).str(); // functions - sqlpp::serialize(sqlpp::value(7), printer).str();// FIXME: Maybe the vendor namespace is not a good idea? argument lives in namespace vendor + serialize(sqlpp::value(7), printer).str(); 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(); From 3d26f9a686b536c9e2fc238c2492e8a8d5ae091f Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 14 Jun 2014 17:44:22 +0200 Subject: [PATCH 38/65] Re-animated prepared statements --- include/sqlpp11/into.h | 16 ++++++------- include/sqlpp11/parameter_list.h | 34 +--------------------------- include/sqlpp11/prepared_select.h | 2 +- include/sqlpp11/remove.h | 8 +++---- include/sqlpp11/select_column_list.h | 4 +--- include/sqlpp11/single_table.h | 8 +++---- include/sqlpp11/statement.h | 2 +- include/sqlpp11/type_traits.h | 20 ++++++++++++++++ include/sqlpp11/update.h | 8 +++---- tests/CMakeLists.txt | 10 ++++---- tests/PreparedTest.cpp | 30 ++++++++++++------------ 11 files changed, 60 insertions(+), 82 deletions(-) diff --git a/include/sqlpp11/into.h b/include/sqlpp11/into.h index 9395e840..fe07b073 100644 --- a/include/sqlpp11/into.h +++ b/include/sqlpp11/into.h @@ -114,16 +114,14 @@ namespace sqlpp return db.insert(*this); } - /* - template - auto _prepare(Db& db) const - -> prepared_insert_t - { - _statement_t::_check_consistency(); + template + auto _prepare(Db& db) const + -> prepared_insert_t + { + _statement_t::_check_consistency(); - return {{}, db.prepare_insert(*this)}; - } - */ + return {{}, db.prepare_insert(*this)}; + } }; }; diff --git a/include/sqlpp11/parameter_list.h b/include/sqlpp11/parameter_list.h index e7386d2a..c023e3f7 100644 --- a/include/sqlpp11/parameter_list.h +++ b/include/sqlpp11/parameter_list.h @@ -64,40 +64,8 @@ namespace sqlpp } }; - namespace detail - { - template - struct get_parameter_tuple - { - using type = std::tuple<>; - }; - - template - struct get_parameter_tuple::value, void>::type> - { - using type = std::tuple; - }; - - template - struct get_parameter_tuple, void> - { - // cat together parameter tuples - using type = decltype(std::tuple_cat(std::declval::type>()...)); - }; - - template - struct get_parameter_tuple::value, void>::type> - { - using type = typename get_parameter_tuple::type; - }; - - } - template - struct make_parameter_list_t - { - using type = parameter_list_t::type>; - }; + using make_parameter_list_t = parameter_list_t>; } diff --git a/include/sqlpp11/prepared_select.h b/include/sqlpp11/prepared_select.h index fab451ca..da958a73 100644 --- a/include/sqlpp11/prepared_select.h +++ b/include/sqlpp11/prepared_select.h @@ -36,7 +36,7 @@ namespace sqlpp struct prepared_select_t { using _result_row_t = typename Select::template _result_row_t; - using _parameter_list_t = typename Select::_parameter_list_t; + using _parameter_list_t = parameters_of; + using _parameter_list_t = make_parameter_list_t
; static_assert(is_table_t
::value, "argument has to be a table"); @@ -97,53 +97,6 @@ namespace sqlpp { }; - template - struct _result_methods_t - { - using _statement_t = typename Policies::_statement_t; - - const _statement_t& _get_statement() const - { - return static_cast(*this); - } - - static constexpr size_t _get_static_no_of_parameters() - { -#warning need to fix this - return 0; - //return _parameter_list_t::size::value; - } - - size_t _get_no_of_parameters() const - { -#warning need to fix this - return 0; - //return _parameter_list_t::size::value; - } - - void _check_consistency() const - { - // FIXME: Read up on what is allowed/prohibited in INSERT - } - - template - auto _run(Db& db) const -> decltype(db.insert(_get_statement())) - { - _check_consistency(); - - static_assert(_get_static_no_of_parameters() == 0, "cannot run insert directly with parameters, use prepare instead"); - return db.insert(_get_statement()); - } - - template - auto _prepare(Db& db) const - -> prepared_insert_t - { - _check_consistency(); - - return {{}, db.prepare_insert(_get_statement())}; - } - }; }; // NO INTO YET diff --git a/include/sqlpp11/update.h b/include/sqlpp11/update.h index f08e79a6..58bb2b74 100644 --- a/include/sqlpp11/update.h +++ b/include/sqlpp11/update.h @@ -62,7 +62,7 @@ namespace sqlpp _statement_t::_check_consistency(); static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run update directly with parameters, use prepare instead"); - return db.update(*this); + return db.update(_get_statement()); } template @@ -71,7 +71,7 @@ namespace sqlpp { _statement_t::_check_consistency(); - return {{}, db.prepare_update(*this)}; + return {{}, db.prepare_update(_get_statement())}; } }; }; From 35f9dab17107ce34358f941b7dc2545fe67011aa Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 22 Jun 2014 12:01:17 +0200 Subject: [PATCH 46/65] Added missing file --- include/sqlpp11/no_data.h | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 include/sqlpp11/no_data.h diff --git a/include/sqlpp11/no_data.h b/include/sqlpp11/no_data.h new file mode 100644 index 00000000..e94a9289 --- /dev/null +++ b/include/sqlpp11/no_data.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2013-2014, 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. + */ + +#ifndef SQLPP_NO_DATA_H +#define SQLPP_NO_DATA_H + +#include +#include + +namespace sqlpp +{ + struct no_data_t {}; + + template + struct serializer_t + { + using T = no_data_t; + + static Context& _(const T& t, Context& context) + { + return context; + } + }; +} +#endif From d90b42f52be4ebd1c8fd539e9a8e1cd63bcc12f4 Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 22 Jun 2014 16:09:19 +0200 Subject: [PATCH 47/65] Added a minimalistic test for including sqlpp11.h --- include/sqlpp11/basic_expression_operators.h | 1 + tests/CMakeLists.txt | 1 + tests/Minimalistic.cpp | 5 +++++ 3 files changed, 7 insertions(+) create mode 100644 tests/Minimalistic.cpp diff --git a/include/sqlpp11/basic_expression_operators.h b/include/sqlpp11/basic_expression_operators.h index deeb5342..25702f6e 100644 --- a/include/sqlpp11/basic_expression_operators.h +++ b/include/sqlpp11/basic_expression_operators.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 350602ec..b7109ae7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -14,6 +14,7 @@ build_and_run(SelectTest) build_and_run(SelectTypeTest) build_and_run(FunctionTest) build_and_run(PreparedTest) +build_and_run(Minimalistic) find_package(PythonInterp REQUIRED) diff --git a/tests/Minimalistic.cpp b/tests/Minimalistic.cpp new file mode 100644 index 00000000..c30384c0 --- /dev/null +++ b/tests/Minimalistic.cpp @@ -0,0 +1,5 @@ +#include + +int main() +{ +} From 0b273733142cb7fb1ba76e12738f6d0f81a6c0c3 Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 22 Jun 2014 23:37:43 +0200 Subject: [PATCH 48/65] Adjusted code to work with g++-4.8 as well --- include/sqlpp11/extra_tables.h | 2 -- include/sqlpp11/insert.h | 2 +- include/sqlpp11/into.h | 2 +- include/sqlpp11/remove.h | 2 +- include/sqlpp11/select_column_list.h | 2 +- include/sqlpp11/statement.h | 2 +- include/sqlpp11/update.h | 2 +- 7 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/sqlpp11/extra_tables.h b/include/sqlpp11/extra_tables.h index 4b25a04f..82b54fd7 100644 --- a/include/sqlpp11/extra_tables.h +++ b/include/sqlpp11/extra_tables.h @@ -60,8 +60,6 @@ namespace sqlpp using _extra_tables = ::sqlpp::detail::type_set; }; - using _recursive_traits = make_recursive_traits; - // FIXME: extra_tables must not require tables! static_assert(sizeof...(Tables), "at least one table or join argument required in extra_tables()"); diff --git a/include/sqlpp11/insert.h b/include/sqlpp11/insert.h index d1f82eb2..b6ca7ff2 100644 --- a/include/sqlpp11/insert.h +++ b/include/sqlpp11/insert.h @@ -56,7 +56,7 @@ namespace sqlpp } template - auto _run(Db& db) const -> decltype(db.insert(_get_statement())) + auto _run(Db& db) const -> decltype(db.insert(this->_get_statement())) { _statement_t::_check_consistency(); diff --git a/include/sqlpp11/into.h b/include/sqlpp11/into.h index 2454528a..de2e2214 100644 --- a/include/sqlpp11/into.h +++ b/include/sqlpp11/into.h @@ -108,7 +108,7 @@ namespace sqlpp } template - auto _run(Db& db) const -> decltype(db.insert(_get_statement())) + auto _run(Db& db) const -> decltype(db.insert(this->_get_statement())) { _statement_t::_check_consistency(); diff --git a/include/sqlpp11/remove.h b/include/sqlpp11/remove.h index d3bc1142..1c067f09 100644 --- a/include/sqlpp11/remove.h +++ b/include/sqlpp11/remove.h @@ -57,7 +57,7 @@ namespace sqlpp } template - auto _run(Db& db) const -> decltype(db.remove(_get_statement())) + auto _run(Db& db) const -> decltype(db.remove(this->_get_statement())) { _statement_t::_check_consistency(); diff --git a/include/sqlpp11/select_column_list.h b/include/sqlpp11/select_column_list.h index 602bcf3f..41cb5f06 100644 --- a/include/sqlpp11/select_column_list.h +++ b/include/sqlpp11/select_column_list.h @@ -284,7 +284,7 @@ namespace sqlpp // Execute template auto _run(Db& db) const - -> result_t> + -> result_t_get_statement())), _result_row_t> { _statement_t::_check_consistency(); static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run select directly with parameters, use prepare instead"); diff --git a/include/sqlpp11/statement.h b/include/sqlpp11/statement.h index b5e1bc5a..ea40ee3b 100644 --- a/include/sqlpp11/statement.h +++ b/include/sqlpp11/statement.h @@ -110,7 +110,7 @@ namespace sqlpp struct _recursive_traits { - using _required_tables = _required_tables; + using _required_tables = statement_policies_t::_required_tables; using _provided_tables = detail::type_set<>; using _extra_tables = detail::type_set<>; using _parameters = detail::make_parameter_tuple_t...>; diff --git a/include/sqlpp11/update.h b/include/sqlpp11/update.h index 58bb2b74..f6ddd15b 100644 --- a/include/sqlpp11/update.h +++ b/include/sqlpp11/update.h @@ -57,7 +57,7 @@ namespace sqlpp } template - auto _run(Db& db) const -> decltype(db.update(_get_statement())) + auto _run(Db& db) const -> decltype(db.update(this->_get_statement())) { _statement_t::_check_consistency(); From 1267aa252f7ed9e7cc7c7cac279f03dd13dc459c Mon Sep 17 00:00:00 2001 From: rbock Date: Tue, 24 Jun 2014 21:53:25 +0200 Subject: [PATCH 49/65] Added _check_consistency call to all statement parts For instance, enforce where() to be called --- include/sqlpp11/extra_tables.h | 3 + include/sqlpp11/from.h | 3 + include/sqlpp11/group_by.h | 3 + include/sqlpp11/having.h | 3 + include/sqlpp11/insert_value_list.h | 10 ++- include/sqlpp11/into.h | 36 ++-------- include/sqlpp11/limit.h | 4 ++ include/sqlpp11/offset.h | 5 ++ include/sqlpp11/order_by.h | 3 + include/sqlpp11/remove.h | 3 +- include/sqlpp11/select.h | 2 +- include/sqlpp11/select_column_list.h | 3 + include/sqlpp11/select_flag_list.h | 3 + include/sqlpp11/single_table.h | 2 + include/sqlpp11/statement.h | 9 +-- include/sqlpp11/update.h | 3 +- include/sqlpp11/update_list.h | 3 + include/sqlpp11/using.h | 3 + include/sqlpp11/where.h | 104 ++++++++++++++------------- 19 files changed, 118 insertions(+), 87 deletions(-) diff --git a/include/sqlpp11/extra_tables.h b/include/sqlpp11/extra_tables.h index 82b54fd7..a00be84a 100644 --- a/include/sqlpp11/extra_tables.h +++ b/include/sqlpp11/extra_tables.h @@ -97,6 +97,7 @@ namespace sqlpp template struct _methods_t { + static void _check_consistency() {} }; }; @@ -139,6 +140,8 @@ namespace sqlpp template using _new_statement_t = typename Policies::template _new_statement_t; + static void _check_consistency() {} + template auto extra_tables(Args...) -> _new_statement_t> diff --git a/include/sqlpp11/from.h b/include/sqlpp11/from.h index 00a9a2e7..bf4af90a 100644 --- a/include/sqlpp11/from.h +++ b/include/sqlpp11/from.h @@ -126,6 +126,7 @@ namespace sqlpp template struct _methods_t { + static void _check_consistency() {} }; }; @@ -169,6 +170,8 @@ namespace sqlpp template using _new_statement_t = typename Policies::template _new_statement_t; + static void _check_consistency() {} + template auto from(Args... args) -> _new_statement_t> diff --git a/include/sqlpp11/group_by.h b/include/sqlpp11/group_by.h index f5c8bb56..6aa72724 100644 --- a/include/sqlpp11/group_by.h +++ b/include/sqlpp11/group_by.h @@ -128,6 +128,7 @@ namespace sqlpp template struct _methods_t { + static void _check_consistency() {} }; }; @@ -171,6 +172,8 @@ namespace sqlpp template using _new_statement_t = typename Policies::template _new_statement_t; + static void _check_consistency() {} + template auto group_by(Args... args) -> _new_statement_t> diff --git a/include/sqlpp11/having.h b/include/sqlpp11/having.h index 9fc1d410..7eceee0c 100644 --- a/include/sqlpp11/having.h +++ b/include/sqlpp11/having.h @@ -126,6 +126,7 @@ namespace sqlpp template struct _methods_t { + static void _check_consistency() {} }; }; @@ -169,6 +170,8 @@ namespace sqlpp template using _new_statement_t = typename Policies::template _new_statement_t; + static void _check_consistency() {} + template auto having(Args... args) -> _new_statement_t> diff --git a/include/sqlpp11/insert_value_list.h b/include/sqlpp11/insert_value_list.h index 75675f11..f4b86616 100644 --- a/include/sqlpp11/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -76,7 +76,9 @@ namespace sqlpp template struct _methods_t - {}; + { + static void _check_consistency() {} + }; }; template @@ -197,10 +199,9 @@ namespace sqlpp template struct _methods_t { + static void _check_consistency() {} }; - - }; template @@ -296,6 +297,7 @@ namespace sqlpp template struct _methods_t { + static void _check_consistency() {} }; /* @@ -347,6 +349,8 @@ namespace sqlpp template using _new_statement_t = typename Policies::template _new_statement_t; + static void _check_consistency() {} + auto default_values() -> _new_statement_t { diff --git a/include/sqlpp11/into.h b/include/sqlpp11/into.h index de2e2214..3e8ba6b4 100644 --- a/include/sqlpp11/into.h +++ b/include/sqlpp11/into.h @@ -57,7 +57,7 @@ namespace sqlpp template struct into_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits
; static_assert(is_table_t
::value, "argument has to be a table"); @@ -95,36 +95,9 @@ namespace sqlpp template struct _methods_t { + static void _check_consistency() {} }; - template - struct _result_methods_t - { - using _statement_t = typename Policies::_statement_t; - - const _statement_t& _get_statement() const - { - return static_cast(*this); - } - - template - auto _run(Db& db) const -> decltype(db.insert(this->_get_statement())) - { - _statement_t::_check_consistency(); - - static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run insert directly with parameters, use prepare instead"); - return db.insert(_get_statement()); - } - - template - auto _prepare(Db& db) const - -> prepared_insert_t - { - _statement_t::_check_consistency(); - - return {{}, db.prepare_insert(_get_statement())}; - } - }; }; // NO INTO YET @@ -167,6 +140,11 @@ namespace sqlpp template using _new_statement_t = typename Policies::template _new_statement_t; + static void _check_consistency() + { + static_assert(wrong_t::value, "into() required"); + } + template auto into(Args... args) -> _new_statement_t> diff --git a/include/sqlpp11/limit.h b/include/sqlpp11/limit.h index 99a31928..e38b3919 100644 --- a/include/sqlpp11/limit.h +++ b/include/sqlpp11/limit.h @@ -89,6 +89,7 @@ namespace sqlpp template struct _methods_t { + static void _check_consistency() {} }; }; @@ -165,6 +166,7 @@ namespace sqlpp template struct _methods_t { + static void _check_consistency() {} }; }; @@ -207,6 +209,8 @@ namespace sqlpp template using _new_statement_t = typename Policies::template _new_statement_t; + static void _check_consistency() {} + template auto limit(Arg arg) -> _new_statement_t::type>> diff --git a/include/sqlpp11/offset.h b/include/sqlpp11/offset.h index 9d89674c..7221f4e1 100644 --- a/include/sqlpp11/offset.h +++ b/include/sqlpp11/offset.h @@ -89,6 +89,7 @@ namespace sqlpp template struct _methods_t { + static void _check_consistency() {} }; }; @@ -164,6 +165,8 @@ namespace sqlpp template struct _methods_t { + static void _check_consistency() {} + template void set_offset(Offset value) { @@ -217,6 +220,8 @@ namespace sqlpp template using _new_statement_t = typename Policies::template _new_statement_t; + static void _check_consistency() {} + template auto offset(Arg arg) -> _new_statement_t::type>> diff --git a/include/sqlpp11/order_by.h b/include/sqlpp11/order_by.h index a82ac900..e23422d1 100644 --- a/include/sqlpp11/order_by.h +++ b/include/sqlpp11/order_by.h @@ -128,6 +128,7 @@ namespace sqlpp template struct _methods_t { + static void _check_consistency() {} }; }; @@ -171,6 +172,8 @@ namespace sqlpp template using _new_statement_t = typename Policies::template _new_statement_t; + static void _check_consistency() {} + template auto order_by(Args... args) -> _new_statement_t> diff --git a/include/sqlpp11/remove.h b/include/sqlpp11/remove.h index 1c067f09..061adf72 100644 --- a/include/sqlpp11/remove.h +++ b/include/sqlpp11/remove.h @@ -96,7 +96,8 @@ namespace sqlpp no_from_t, no_using_t, no_extra_tables_t, - no_where_t>; + no_where_t + >; auto remove() -> blank_remove_t diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 0c5b320f..d3dab3a7 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -71,7 +71,7 @@ namespace sqlpp no_select_column_list_t, no_from_t, no_extra_tables_t, - no_where_t, + no_where_t, no_group_by_t, no_having_t, no_order_by_t, diff --git a/include/sqlpp11/select_column_list.h b/include/sqlpp11/select_column_list.h index 41cb5f06..c24da000 100644 --- a/include/sqlpp11/select_column_list.h +++ b/include/sqlpp11/select_column_list.h @@ -231,6 +231,7 @@ namespace sqlpp template struct _methods_t { + static void _check_consistency() {} }; // Result methods @@ -355,6 +356,8 @@ namespace sqlpp template using _new_statement_t = typename Policies::template _new_statement_t; + static void _check_consistency() {} + template auto columns(Args... args) -> _new_statement_t<::sqlpp::detail::make_select_column_list_t> diff --git a/include/sqlpp11/select_flag_list.h b/include/sqlpp11/select_flag_list.h index 8932b896..5959a92a 100644 --- a/include/sqlpp11/select_flag_list.h +++ b/include/sqlpp11/select_flag_list.h @@ -127,6 +127,7 @@ namespace sqlpp template struct _methods_t { + static void _check_consistency() {} }; }; @@ -170,6 +171,8 @@ namespace sqlpp template using _new_statement_t = typename Policies::template _new_statement_t; + static void _check_consistency() {} + template auto flags(Args... args) -> _new_statement_t> diff --git a/include/sqlpp11/single_table.h b/include/sqlpp11/single_table.h index 00327fc4..12cf98b5 100644 --- a/include/sqlpp11/single_table.h +++ b/include/sqlpp11/single_table.h @@ -95,6 +95,7 @@ namespace sqlpp template struct _methods_t { + static void _check_consistency() {} }; }; @@ -139,6 +140,7 @@ namespace sqlpp template using _new_statement_t = typename Policies::template _new_statement_t; + static void _check_consistency() {} #warning: remove can operate on several tables at once, so it should not use single_table anyway template auto from(Args... args) diff --git a/include/sqlpp11/statement.h b/include/sqlpp11/statement.h index ea40ee3b..09497801 100644 --- a/include/sqlpp11/statement.h +++ b/include/sqlpp11/statement.h @@ -52,9 +52,6 @@ namespace sqlpp using _database_t = Db; using _statement_t = statement_t; - struct _methods_t: public Policies::template _methods_t... - {}; - template struct _policies_update_t { @@ -125,7 +122,7 @@ namespace sqlpp public Policies::template _member_t>..., public detail::statement_policies_t::_value_type::template expression_operators>, public detail::statement_policies_t::_result_methods_t, - public detail::statement_policies_t::_methods_t + public Policies::template _methods_t>... { using _policies_t = typename detail::statement_policies_t; @@ -172,6 +169,9 @@ namespace sqlpp // FIXME: Check each "methods" or each member... #warning check for missing terms here, and for missing tables static_assert(not required_tables_of<_policies_t>::size::value, "one sub expression requires tables which are otherwise not known in the statement"); + + using swallow = int[]; + (void) swallow{(Policies::template _methods_t>::_check_consistency(), 0)...}; } @@ -229,6 +229,7 @@ namespace sqlpp template struct _methods_t { + static void _check_consistency() {} }; }; diff --git a/include/sqlpp11/update.h b/include/sqlpp11/update.h index f6ddd15b..215200d6 100644 --- a/include/sqlpp11/update.h +++ b/include/sqlpp11/update.h @@ -95,7 +95,8 @@ namespace sqlpp update_t, no_single_table_t, no_update_list_t, - no_where_t>; + no_where_t + >; template constexpr auto update(Table table) diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index a5f9b7a4..882300be 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -140,6 +140,7 @@ namespace sqlpp template struct _methods_t { + static void _check_consistency() {} }; }; @@ -182,6 +183,8 @@ namespace sqlpp template using _new_statement_t = typename Policies::template _new_statement_t; + static void _check_consistency() {} + template auto set(Args... args) -> _new_statement_t> diff --git a/include/sqlpp11/using.h b/include/sqlpp11/using.h index b8423bc0..0214851b 100644 --- a/include/sqlpp11/using.h +++ b/include/sqlpp11/using.h @@ -121,6 +121,7 @@ namespace sqlpp template struct _methods_t { + static void _check_consistency() {} }; }; @@ -164,6 +165,8 @@ namespace sqlpp template using _new_statement_t = typename Policies::template _new_statement_t; + static void _check_consistency() {} + template auto using_(Args... args) -> _new_statement_t> diff --git a/include/sqlpp11/where.h b/include/sqlpp11/where.h index b19e7123..0a8d704d 100644 --- a/include/sqlpp11/where.h +++ b/include/sqlpp11/where.h @@ -127,6 +127,7 @@ namespace sqlpp template struct _methods_t { + static void _check_consistency() {} }; }; @@ -174,67 +175,74 @@ namespace sqlpp template struct _methods_t { + static void _check_consistency() {} }; }; // NO WHERE YET - struct no_where_t - { - using _traits = make_traits; - using _recursive_traits = make_recursive_traits<>; + template + struct no_where_t + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; - // Data - using _data_t = no_data_t; + // Data + using _data_t = no_data_t; - // Member implementation with data and methods - template - struct _impl_t - { - _data_t _data; - }; + // Member implementation with data and methods + template + struct _impl_t + { + _data_t _data; + }; - // Member template for adding the named member to a statement - template - struct _member_t - { - using _data_t = no_data_t; + // Member template for adding the named member to a statement + template + struct _member_t + { + using _data_t = no_data_t; - _impl_t no_where; - _impl_t& operator()() { return no_where; } - const _impl_t& operator()() const { return no_where; } + _impl_t no_where; + _impl_t& operator()() { return no_where; } + const _impl_t& operator()() const { return no_where; } - template - static auto _get_member(T t) -> decltype(t.no_where) + template + static auto _get_member(T t) -> decltype(t.no_where) + { + return t.no_where; + } + }; + + // Additional methods for the statement + template + struct _methods_t + { + using _database_t = typename Policies::_database_t; + template + using _new_statement_t = typename Policies::template _new_statement_t; + + static void _check_consistency() { - return t.no_where; - } - }; - - // Additional methods for the statement - template - struct _methods_t - { - using _database_t = typename Policies::_database_t; - template - using _new_statement_t = typename Policies::template _new_statement_t; - - template - auto where(Args... args) - -> _new_statement_t> - { - return { *static_cast(this), where_data_t{args...} }; + static_assert(Required ? wrong_t::value : true, "where expression required, e.g. where(true)"); } - template - auto dynamic_where(Args... args) - -> _new_statement_t> - { - static_assert(not std::is_same<_database_t, void>::value, "dynamic_where must not be called in a static statement"); - return { *static_cast(this), where_data_t<_database_t, Args...>{args...} }; - } - }; - }; + template + auto where(Args... args) + -> _new_statement_t> + { + return { *static_cast(this), where_data_t{args...} }; + } + + template + auto dynamic_where(Args... args) + -> _new_statement_t> + { + static_assert(not std::is_same<_database_t, void>::value, "dynamic_where must not be called in a static statement"); + return { *static_cast(this), where_data_t<_database_t, Args...>{args...} }; + } + }; + }; // Interpreters template From e03366202d876de4a478378d2aa3a3cfbdcb9af7 Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 26 Jun 2014 08:39:08 +0200 Subject: [PATCH 50/65] Fixed a bunch of warnings --- include/sqlpp11/basic_expression_operators.h | 1 - include/sqlpp11/integral.h | 1 + include/sqlpp11/simple_column.h | 1 - include/sqlpp11/single_table.h | 4 +- include/sqlpp11/statement.h | 3 - include/sqlpp11/update_list.h | 58 ++++++++++---------- tests/UpdateTest.cpp | 3 +- 7 files changed, 34 insertions(+), 37 deletions(-) diff --git a/include/sqlpp11/basic_expression_operators.h b/include/sqlpp11/basic_expression_operators.h index 25702f6e..deeb5342 100644 --- a/include/sqlpp11/basic_expression_operators.h +++ b/include/sqlpp11/basic_expression_operators.h @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include diff --git a/include/sqlpp11/integral.h b/include/sqlpp11/integral.h index 2b52fb6e..791df00c 100644 --- a/include/sqlpp11/integral.h +++ b/include/sqlpp11/integral.h @@ -33,6 +33,7 @@ #include #include #include +#include namespace sqlpp { diff --git a/include/sqlpp11/simple_column.h b/include/sqlpp11/simple_column.h index 0f05befe..e6b829a0 100644 --- a/include/sqlpp11/simple_column.h +++ b/include/sqlpp11/simple_column.h @@ -56,7 +56,6 @@ namespace sqlpp template simple_column_t simple_column(Column c) { -#warning: make sure that there are no parameters in Column return {c}; } } diff --git a/include/sqlpp11/single_table.h b/include/sqlpp11/single_table.h index 12cf98b5..8690be61 100644 --- a/include/sqlpp11/single_table.h +++ b/include/sqlpp11/single_table.h @@ -140,8 +140,8 @@ namespace sqlpp template using _new_statement_t = typename Policies::template _new_statement_t; - static void _check_consistency() {} -#warning: remove can operate on several tables at once, so it should not use single_table anyway + static void _check_consistency() {} + template auto from(Args... args) -> _new_statement_t> diff --git a/include/sqlpp11/statement.h b/include/sqlpp11/statement.h index 09497801..416f1654 100644 --- a/include/sqlpp11/statement.h +++ b/include/sqlpp11/statement.h @@ -48,7 +48,6 @@ namespace sqlpp template struct statement_policies_t { -#warning need to check policies' signature, e.g. a _data_t in _member_t template using _database_t = Db; using _statement_t = statement_t; @@ -166,8 +165,6 @@ namespace sqlpp static void _check_consistency() { - // FIXME: Check each "methods" or each member... -#warning check for missing terms here, and for missing tables static_assert(not required_tables_of<_policies_t>::size::value, "one sub expression requires tables which are otherwise not known in the statement"); using swallow = int[]; diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index 882300be..1f058a1a 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -60,23 +60,6 @@ namespace sqlpp using _recursive_traits = make_recursive_traits; using _is_dynamic = is_database; - static_assert(_is_dynamic::value or sizeof...(Assignments), "at least one assignment expression required in set()"); - - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in set()"); - - static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an assignment in set()"); - - static_assert(::sqlpp::detail::none_t::value...>::value, "at least one assignment is prohibited by its column definition in set()"); - -#warning reactivate tests - /* - using _column_table_set = typename ::sqlpp::detail::make_joined_set::type; - using _value_table_set = typename ::sqlpp::detail::make_joined_set::type; - using _table_set = typename ::sqlpp::detail::make_joined_set<_column_table_set, _value_table_set>::type; - static_assert(sizeof...(Assignments) ? (_column_table_set::size::value == 1) : true, "set() contains assignments for tables from several columns"); - static_assert(::sqlpp::detail::is_subset_of<_value_table_set, _column_table_set>::value, "set() contains values from foreign tables"); - */ - // Data using _data_t = update_list_data_t; @@ -95,13 +78,14 @@ namespace sqlpp { static_assert(_is_dynamic::value, "add must not be called for static from()"); static_assert(is_assignment_t::value, "invalid assignment argument in add()"); + using _assigned_columns = detail::make_type_set_t; + static_assert(not detail::is_element_of::value, "Must not assign value to column twice"); static_assert(sqlpp::detail::not_t::value, "add() argument must not be updated"); static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "assignment uses tables unknown to this statement in add()"); using ok = ::sqlpp::detail::all_t< _is_dynamic::value, - is_assignment_t::value, - not must_not_update_t::value>; + is_assignment_t::value>; _add_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert } @@ -185,19 +169,37 @@ namespace sqlpp static void _check_consistency() {} - template - auto set(Args... args) - -> _new_statement_t> + template + auto set(Assignments... assignments) + -> _new_statement_t> { - return { *static_cast(this), update_list_data_t{args...} }; + static_assert(sizeof...(Assignments), "at least one assignment expression required in set()"); + return _set_impl(assignments...); } - template - auto dynamic_set(Args... args) - -> _new_statement_t> + template + auto dynamic_set(Assignments... assignments) + -> _new_statement_t> { - static_assert(not std::is_same<_database_t, void>::value, "dynamic_set must not be called in a static statement"); - return { *static_cast(this), update_list_data_t<_database_t, Args...>{args...} }; + static_assert(not std::is_same<_database_t, void>::value, "dynamic_set() must not be called in a static statement"); + return _set_impl<_database_t>(assignments...); + } + + private: + template + auto _set_impl(Assignments... assignments) + -> _new_statement_t> + { + static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in set()"); + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an assignment in set()"); + static_assert(::sqlpp::detail::none_t::value...>::value, "at least one assignment is prohibited by its column definition in set()"); + + using _column_table_set = typename ::sqlpp::detail::make_joined_set...>::type; + using _value_table_set = typename ::sqlpp::detail::make_joined_set...>::type; + static_assert(sizeof...(Assignments) ? (_column_table_set::size::value == 1) : true, "set() contains assignments for columns from more than one table"); + static_assert(::sqlpp::detail::is_subset_of<_value_table_set, _column_table_set>::value, "set() contains values from foreign tables"); + + return { *static_cast(this), update_list_data_t{assignments...} }; } }; }; diff --git a/tests/UpdateTest.cpp b/tests/UpdateTest.cpp index 364d8a33..6f7a0c0b 100644 --- a/tests/UpdateTest.cpp +++ b/tests/UpdateTest.cpp @@ -61,8 +61,7 @@ int main() serialize(update(t).set(t.gamma = false).where(t.beta != "transparent"), printer).str(); serialize(update(t).set(t.beta = "opaque").where(t.beta != t.beta), printer).str(); auto u = dynamic_update(db, t).dynamic_set(t.gamma = false).dynamic_where(); -#warning: This should fail since gamma is set already - u.assignments.add(t.gamma = false); + u.assignments.add(t.beta = "cannot update gamma a second time"); u.where.add(t.gamma != false); printer.reset(); std::cerr << serialize(u, printer).str() << std::endl; From 2266787e94de83e7f11b9ad7b4911310a4b1f735 Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 26 Jun 2014 14:35:49 +0200 Subject: [PATCH 51/65] Fixed another few warnings --- include/sqlpp11/insert_value_list.h | 68 ++++++++++++----------------- include/sqlpp11/update_list.h | 6 +-- 2 files changed, 30 insertions(+), 44 deletions(-) diff --git a/include/sqlpp11/insert_value_list.h b/include/sqlpp11/insert_value_list.h index f4b86616..f02d7a47 100644 --- a/include/sqlpp11/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -116,24 +116,6 @@ namespace sqlpp template class Target, template class Wrap> using copy_wrapped_assignments_t = Target...>; - static_assert(_is_dynamic::value or sizeof...(Assignments), "at least one assignment required in set()"); - - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in set()"); - - static_assert(sqlpp::detail::all_t::value...>::value, "at least one argument is not an assignment in set()"); - - static_assert(sqlpp::detail::none_t::value...>::value, "at least one assignment is prohibited by its column definition in set()"); - -#warning: Need to reactivate these checks - /* - using _column_required_tables = typename ::sqlpp::detail::make_joined_set::type; - using _value_required_tables = typename ::sqlpp::detail::make_joined_set::type; - using _provided_tables = ::sqlpp::detail::type_set<>; - using _required_tables = typename ::sqlpp::detail::make_joined_set<_column_required_tables, _value_required_tables>::type; - static_assert(sizeof...(Assignments) ? (_column_required_tables::size::value == 1) : true, "set() contains assignments for tables from several columns"); - static_assert(::sqlpp::detail::is_subset_of<_value_required_tables, _column_required_tables>::value, "set() contains values from foreign tables"); - */ - // Data using _data_t = insert_list_data_t; @@ -152,14 +134,14 @@ namespace sqlpp { static_assert(_is_dynamic::value, "add must not be called for static from()"); static_assert(is_assignment_t::value, "add() arguments require to be assigments"); + using _assigned_columns = detail::make_type_set_t; + static_assert(not detail::is_element_of::value, "Must not assign value to column twice"); static_assert(not must_not_insert_t::value, "add() argument must not be used in insert"); static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables::value, "add() contains a column from a foreign table"); using ok = ::sqlpp::detail::all_t< _is_dynamic::value, - is_assignment_t::value, - not must_not_insert_t::value, - (not TableCheckRequired::value or Policies::template _no_unknown_tables::value)>; + is_assignment_t::value>; _add_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert } @@ -217,7 +199,6 @@ namespace sqlpp column_list_data_t& operator=(column_list_data_t&&) = default; ~column_list_data_t() = default; -#warning need to define just one version of value_tuple_t using _value_tuple_t = std::tuple...>; std::tuple...> _columns; std::vector<_value_tuple_t> _insert_values; @@ -237,7 +218,7 @@ namespace sqlpp static_assert(::sqlpp::detail::none_t::value...>::value, "at least one column argument has a must_not_insert flag in its definition"); - using _value_tuple_t = std::tuple...>; + using _value_tuple_t = typename column_list_data_t::_value_tuple_t; static_assert(required_tables_of::size::value == 1, "columns from multiple tables in columns()"); @@ -299,17 +280,9 @@ namespace sqlpp { static void _check_consistency() {} }; - - /* - bool empty() const - { - return _insert_values.empty(); - } - */ - }; - // NO HAVING YET + // NO INSERT COLUMNS/VALUES YET struct no_insert_value_list_t { using _traits = make_traits; @@ -364,19 +337,34 @@ namespace sqlpp return { *static_cast(this), column_list_data_t{args...} }; } - template - auto set(Args... args) - -> _new_statement_t> + template + auto set(Assignments... assignments) + -> _new_statement_t> { - return { *static_cast(this), insert_list_data_t{args...} }; + static_assert(sizeof...(Assignments), "at least one assignment expression required in set()"); + return _set_impl(assignments...); } - template - auto dynamic_set(Args... args) - -> _new_statement_t> + template + auto dynamic_set(Assignments... assignments) + -> _new_statement_t> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_set must not be called in a static statement"); - return { *static_cast(this), insert_list_data_t<_database_t, Args...>{args...} }; + return _set_impl<_database_t>(assignments...); + } + private: + template + auto _set_impl(Assignments... assignments) + -> _new_statement_t> + { + static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in set()"); + static_assert(sqlpp::detail::all_t::value...>::value, "at least one argument is not an assignment in set()"); + static_assert(sqlpp::detail::none_t::value...>::value, "at least one assignment is prohibited by its column definition in set()"); + + using _column_required_tables = typename ::sqlpp::detail::make_joined_set...>::type; + static_assert(sizeof...(Assignments) ? (_column_required_tables::size::value == 1) : true, "set() contains assignments for columns from several tables"); + + return { *static_cast(this), insert_list_data_t{assignments...} }; } }; }; diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index 1f058a1a..903bac66 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -194,10 +194,8 @@ namespace sqlpp static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an assignment in set()"); static_assert(::sqlpp::detail::none_t::value...>::value, "at least one assignment is prohibited by its column definition in set()"); - using _column_table_set = typename ::sqlpp::detail::make_joined_set...>::type; - using _value_table_set = typename ::sqlpp::detail::make_joined_set...>::type; - static_assert(sizeof...(Assignments) ? (_column_table_set::size::value == 1) : true, "set() contains assignments for columns from more than one table"); - static_assert(::sqlpp::detail::is_subset_of<_value_table_set, _column_table_set>::value, "set() contains values from foreign tables"); + using _column_required_tables = typename ::sqlpp::detail::make_joined_set...>::type; + static_assert(sizeof...(Assignments) ? (_column_required_tables::size::value == 1) : true, "set() contains assignments for columns from more than one table"); return { *static_cast(this), update_list_data_t{assignments...} }; } From 1f20d244c7c8357ea5af93da156523699758233b Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 26 Jun 2014 18:56:07 +0200 Subject: [PATCH 52/65] Added improved check for potential name duplicates in from() --- include/sqlpp11/detail/type_set.h | 18 +++++++++++ include/sqlpp11/from.h | 50 +++++++++++++++++++------------ include/sqlpp11/remove.h | 1 - include/sqlpp11/type_traits.h | 9 ++++++ include/sqlpp11/verbatim_table.h | 10 ++++--- 5 files changed, 64 insertions(+), 24 deletions(-) diff --git a/include/sqlpp11/detail/type_set.h b/include/sqlpp11/detail/type_set.h index 9f5f855f..a46ffb9b 100644 --- a/include/sqlpp11/detail/type_set.h +++ b/include/sqlpp11/detail/type_set.h @@ -211,6 +211,24 @@ namespace sqlpp template using make_difference_set_t = typename make_difference_set::type; + + template class Transformation, typename T> + struct transform_set + { + static_assert(::sqlpp::wrong_t::value, "invalid argument for transform_set"); + }; + + template class Transformation, typename... E> + struct transform_set> + { + using type = typename make_type_set...>::type; + }; + + template class Transformation, typename T> + using transform_set_t = typename transform_set::type; + + + } } diff --git a/include/sqlpp11/from.h b/include/sqlpp11/from.h index bf4af90a..1530391d 100644 --- a/include/sqlpp11/from.h +++ b/include/sqlpp11/from.h @@ -32,6 +32,7 @@ #include #include #include +#include #include namespace sqlpp @@ -60,18 +61,8 @@ namespace sqlpp { using _traits = make_traits; using _recursive_traits = make_recursive_traits; - using _is_dynamic = is_database; - static_assert(_is_dynamic::value or sizeof...(Tables), "at least one table or join argument required in from()"); - - // FIXME: Joins contain two tables. This is not being dealt with at the moment when looking at duplicates, for instance - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in from()"); - - static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a table or join in from()"); - - static_assert(required_tables_of::size::value == 0, "at least one table depends on another table"); - // Data using _data_t = from_data_t; @@ -84,7 +75,9 @@ namespace sqlpp { static_assert(_is_dynamic::value, "from::add() must not be called for static from()"); static_assert(is_table_t
::value, "invalid table argument in from::add()"); -#warning need to check if table is already known + using _known_tables = detail::make_joined_set_t...>; // Hint: Joins contain more than one table + using _known_table_names = detail::transform_set_t; + static_assert(not detail::is_element_of::value, "Must not use the same table name twice in from()"); using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_table_t
::value>; @@ -172,20 +165,39 @@ namespace sqlpp static void _check_consistency() {} - template - auto from(Args... args) - -> _new_statement_t> + template + auto from(Tables... tables) + -> _new_statement_t> { - return { *static_cast(this), from_data_t{args...} }; + static_assert(sizeof...(Tables), "at least one table or join argument required in from()"); + return _from_impl(tables...); } - template - auto dynamic_from(Args... args) - -> _new_statement_t> + template + auto dynamic_from(Tables... tables) + -> _new_statement_t> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_from must not be called in a static statement"); - return { *static_cast(this), from_data_t<_database_t, Args...>{args...} }; + return _from_impl<_database_t>(tables...); } + + private: + template + auto _from_impl(Tables... tables) + -> _new_statement_t> + { + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a table or join in from()"); + static_assert(required_tables_of>::size::value == 0, "at least one table depends on another table"); + + static constexpr std::size_t _number_of_tables = detail::sum(provided_tables_of::size::value...); + using _unique_tables = detail::make_joined_set_t...>; + using _unique_table_names = detail::transform_set_t; + static_assert(_number_of_tables == _unique_tables::size::value, "at least one duplicate table detected in from()"); + static_assert(_number_of_tables == _unique_table_names::size::value, "at least one duplicate table name detected in from()"); + + return { *static_cast(this), from_data_t{tables...} }; + } + }; }; diff --git a/include/sqlpp11/remove.h b/include/sqlpp11/remove.h index 061adf72..c2a60ae0 100644 --- a/include/sqlpp11/remove.h +++ b/include/sqlpp11/remove.h @@ -32,7 +32,6 @@ #include #include #include -#warning: need to use another table provider, since delete can be used with several tables #include #include #include diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index 4cd4fdf2..f74eea08 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -187,6 +187,12 @@ namespace sqlpp using type = typename T::_recursive_traits::_parameters; }; + template + struct name_of_impl + { + using type = typename T::_name_t; + }; + template struct make_parameter_tuple_impl { @@ -211,6 +217,9 @@ namespace sqlpp template using parameters_of = typename detail::parameters_of_impl::type; + template + using name_of = typename detail::name_of_impl::type; + template struct make_traits { diff --git a/include/sqlpp11/verbatim_table.h b/include/sqlpp11/verbatim_table.h index 7d6d15e4..dbacdb9d 100644 --- a/include/sqlpp11/verbatim_table.h +++ b/include/sqlpp11/verbatim_table.h @@ -49,8 +49,10 @@ namespace sqlpp struct verbatim_table_t: public sqlpp::table_t { - verbatim_table_t(std::string name): - _name(name) + struct _name_t {}; + + verbatim_table_t(std::string representation): + _representation(representation) { } @@ -60,7 +62,7 @@ namespace sqlpp verbatim_table_t& operator=(verbatim_table_t&& rhs) = default; ~verbatim_table_t() = default; - std::string _name; + std::string _representation; }; template @@ -70,7 +72,7 @@ namespace sqlpp static Context& _(const T& t, Context& context) { - context << t._name; + context << t._representation; return context; } }; From bc99c2b24055518b4aaa10fd72d8c8495c09acc3 Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 26 Jun 2014 22:06:54 +0200 Subject: [PATCH 53/65] Added missing file --- include/sqlpp11/detail/sum.h | 62 ++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 include/sqlpp11/detail/sum.h diff --git a/include/sqlpp11/detail/sum.h b/include/sqlpp11/detail/sum.h new file mode 100644 index 00000000..9296b498 --- /dev/null +++ b/include/sqlpp11/detail/sum.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2013-2014, 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. + */ + +#ifndef SQLPP_DETAIL_SUM_H +#define SQLPP_DETAIL_SUM_H + +namespace sqlpp +{ + namespace detail + { + + /** a non-recursive C++14 version + template + constexpr std::size_t sum(Args... args) + { + std::size_t result = 0; + + using swallow = int[]; + (void) swallow{(result += args, 0)...}; + + return result; + } + */ + + constexpr std::size_t sum() + { + return 0; + } + + template + constexpr std::size_t sum(Arg arg, Rest... rest) + { + return arg + sum(rest...); + } + } +} + +#endif + From ff4d93049cb913e971ce6bec59a0b48d5543f0f5 Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 27 Jun 2014 17:41:43 +0200 Subject: [PATCH 54/65] removed char_result_row --- include/sqlpp11/char_result_row.h | 44 ------------------------------- 1 file changed, 44 deletions(-) delete mode 100644 include/sqlpp11/char_result_row.h diff --git a/include/sqlpp11/char_result_row.h b/include/sqlpp11/char_result_row.h deleted file mode 100644 index 3cf09c12..00000000 --- a/include/sqlpp11/char_result_row.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2013-2014, 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. - */ - -#ifndef SQLPP_CHAR_RESULT_ROW_H -#define SQLPP_CHAR_RESULT_ROW_H - -namespace sqlpp -{ - struct char_result_row_t - { - const char** data; - size_t* len; - - bool operator==(const char_result_row_t& rhs) const - { - return data == rhs.data and len == rhs.len; - } - }; -} - -#endif From f14b6025d3e68a1035610589bea4576033699465 Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 27 Jun 2014 17:45:33 +0200 Subject: [PATCH 55/65] Fixed dynamic rows for bind_results --- include/sqlpp11/result_row.h | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/include/sqlpp11/result_row.h b/include/sqlpp11/result_row.h index ce4d4eb3..e06d1339 100644 --- a/include/sqlpp11/result_row.h +++ b/include/sqlpp11/result_row.h @@ -237,6 +237,10 @@ namespace sqlpp _is_valid(false), _dynamic_columns(dynamic_columns) { + for (auto name : _dynamic_columns) + { + _dynamic_fields.insert({name, _field_type{}}); + } } dynamic_result_row_t(const dynamic_result_row_t&) = delete; @@ -255,13 +259,24 @@ namespace sqlpp dynamic_row.len += _last_static_index; for (const auto& column : _dynamic_columns) { - _dynamic_fields[column].assign(dynamic_row.data[0], dynamic_row.len[0]); + _dynamic_fields.at(column).assign(dynamic_row.data[0], dynamic_row.len[0]); ++dynamic_row.data; ++dynamic_row.len; } return *this; } + void validate() + { + + _impl::validate(); + _is_valid = true; + for (auto& field : _dynamic_fields) + { + field.second.validate(); + } + } + void invalidate() { _impl::invalidate(); @@ -287,6 +302,17 @@ namespace sqlpp return _is_valid; } + template + void _bind(Target& target) + { + _impl::_bind(target); + + std::size_t index = _last_static_index; + for (const auto& name : _dynamic_columns) + { + _dynamic_fields.at(name)._bind(target, ++index); + } + } }; } From 620f9bef290737c3a0655120371329f1ced8285e Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 27 Jun 2014 17:45:33 +0200 Subject: [PATCH 56/65] Fixed dynamic rows for bind_results --- include/sqlpp11/result_row.h | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/include/sqlpp11/result_row.h b/include/sqlpp11/result_row.h index ce4d4eb3..e06d1339 100644 --- a/include/sqlpp11/result_row.h +++ b/include/sqlpp11/result_row.h @@ -237,6 +237,10 @@ namespace sqlpp _is_valid(false), _dynamic_columns(dynamic_columns) { + for (auto name : _dynamic_columns) + { + _dynamic_fields.insert({name, _field_type{}}); + } } dynamic_result_row_t(const dynamic_result_row_t&) = delete; @@ -255,13 +259,24 @@ namespace sqlpp dynamic_row.len += _last_static_index; for (const auto& column : _dynamic_columns) { - _dynamic_fields[column].assign(dynamic_row.data[0], dynamic_row.len[0]); + _dynamic_fields.at(column).assign(dynamic_row.data[0], dynamic_row.len[0]); ++dynamic_row.data; ++dynamic_row.len; } return *this; } + void validate() + { + + _impl::validate(); + _is_valid = true; + for (auto& field : _dynamic_fields) + { + field.second.validate(); + } + } + void invalidate() { _impl::invalidate(); @@ -287,6 +302,17 @@ namespace sqlpp return _is_valid; } + template + void _bind(Target& target) + { + _impl::_bind(target); + + std::size_t index = _last_static_index; + for (const auto& name : _dynamic_columns) + { + _dynamic_fields.at(name)._bind(target, ++index); + } + } }; } From c2d00b14ecdef48601f4cd60540e549e293a8d2c Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 27 Jun 2014 18:40:57 +0200 Subject: [PATCH 57/65] Removed char_result_row from result_row --- include/sqlpp11/result_row.h | 59 ++---------------------------------- 1 file changed, 2 insertions(+), 57 deletions(-) diff --git a/include/sqlpp11/result_row.h b/include/sqlpp11/result_row.h index e06d1339..18f4ada2 100644 --- a/include/sqlpp11/result_row.h +++ b/include/sqlpp11/result_row.h @@ -28,7 +28,6 @@ #define SQLPP_RESULT_ROW_H #include -#include #include #include #include @@ -47,16 +46,6 @@ namespace sqlpp using _field = typename NamedExpr::_name_t::template _member_t::template _result_entry_t>; result_field() = default; - result_field(const char_result_row_t& char_result_row_t): - _field({{char_result_row_t.data[index], char_result_row_t.len[index]}}) - { - } - - result_field& operator=(const char_result_row_t& char_result_row_t) - { - _field::operator()().assign(char_result_row_t.data[index], char_result_row_t.len[index]); - return *this; - } void validate() { @@ -82,15 +71,6 @@ namespace sqlpp using _multi_field = typename AliasProvider::_name_t::template _member_t, NamedExprs...>>; result_field() = default; - result_field(const char_result_row_t& char_result_row_t): - _multi_field({char_result_row_t}) - {} - - result_field& operator=(const char_result_row_t& char_result_row_t) - { - _multi_field::operator()() = char_result_row_t; - return *this; - } void validate() { @@ -114,18 +94,8 @@ namespace sqlpp public result_field... { static constexpr std::size_t _last_index = LastIndex; - result_row_impl() = default; - result_row_impl(const char_result_row_t& char_result_row): - result_field(char_result_row)... - { - } - result_row_impl& operator=(const char_result_row_t& char_result_row) - { - using swallow = int[]; - (void) swallow{(result_field::operator=(char_result_row), 0)...}; - return *this; - } + result_row_impl() = default; void validate() { @@ -174,13 +144,6 @@ namespace sqlpp result_row_t& operator=(const result_row_t&) = delete; result_row_t& operator=(result_row_t&&) = default; - result_row_t& operator=(const char_result_row_t& char_result_row_t) - { - _impl::operator=(char_result_row_t); - _is_valid = true; - return *this; - } - void validate() { _impl::validate(); @@ -209,7 +172,7 @@ namespace sqlpp } template - void bind_result(Target& target) + void _bind(Target& target) { _impl::_bind(target); } @@ -248,24 +211,6 @@ namespace sqlpp 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 char_result_row_t& char_result_row) - { - _impl::operator=(char_result_row); - _is_valid = true; - - char_result_row_t dynamic_row = char_result_row; - - dynamic_row.data += _last_static_index; - dynamic_row.len += _last_static_index; - for (const auto& column : _dynamic_columns) - { - _dynamic_fields.at(column).assign(dynamic_row.data[0], dynamic_row.len[0]); - ++dynamic_row.data; - ++dynamic_row.len; - } - return *this; - } - void validate() { From 08786c7cf936b93f9187ba3d462e5399415c880a Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 28 Jun 2014 14:39:04 +0200 Subject: [PATCH 58/65] Added -Wall, took care of a bunch of compiler warnings --- CMakeLists.txt | 4 ++-- include/sqlpp11/column_fwd.h | 2 +- include/sqlpp11/functions.h | 2 -- include/sqlpp11/insert_value_list.h | 2 +- include/sqlpp11/named_interpretable.h | 2 +- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a3d8eeaf..3dd3e7ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,9 +28,9 @@ enable_testing() message(STATUS "Using ${CMAKE_CXX_COMPILER} (compiler id: ${CMAKE_CXX_COMPILER_ID})") if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ ${CMAKE_CXX_FLAGS}") + set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ -Wall ${CMAKE_CXX_FLAGS}") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}") + set(CMAKE_CXX_FLAGS "-std=c++11 -Wall ${CMAKE_CXX_FLAGS}") endif () set(include_dir "${PROJECT_SOURCE_DIR}/include") diff --git a/include/sqlpp11/column_fwd.h b/include/sqlpp11/column_fwd.h index d378aa6a..634bbe0b 100644 --- a/include/sqlpp11/column_fwd.h +++ b/include/sqlpp11/column_fwd.h @@ -31,7 +31,7 @@ namespace sqlpp { template - class column_t; + struct column_t; } #endif diff --git a/include/sqlpp11/functions.h b/include/sqlpp11/functions.h index 058a3b48..65c05a2e 100644 --- a/include/sqlpp11/functions.h +++ b/include/sqlpp11/functions.h @@ -48,8 +48,6 @@ namespace sqlpp template auto value(T t) -> wrap_operand_t { - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; static_assert(is_wrapped_value_t>::value, "value() is to be called with non-sql-type like int, or string"); return { t }; } diff --git a/include/sqlpp11/insert_value_list.h b/include/sqlpp11/insert_value_list.h index f02d7a47..513085d5 100644 --- a/include/sqlpp11/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -96,9 +96,9 @@ namespace sqlpp insert_list_data_t& operator=(insert_list_data_t&&) = default; ~insert_list_data_t() = default; + std::tuple _assignments; // FIXME: Need to replace _columns and _values by _assignments (connector-container requires assignments) std::tuple...> _columns; std::tuple _values; - std::tuple _assignments; // FIXME: Need to replace _columns and _values by _assignments (connector-container requires assignments) interpretable_list_t _dynamic_columns; interpretable_list_t _dynamic_values; }; diff --git a/include/sqlpp11/named_interpretable.h b/include/sqlpp11/named_interpretable.h index 78af6e8c..dcbffbdb 100644 --- a/include/sqlpp11/named_interpretable.h +++ b/include/sqlpp11/named_interpretable.h @@ -71,7 +71,7 @@ namespace sqlpp std::string _get_name() const { - _impl->_get_name(); + return _impl->_get_name(); } private: From 778b0d8816e0b05a5cb18c755e77f74b5d1f107f Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 28 Jun 2014 14:39:04 +0200 Subject: [PATCH 59/65] Added -Wall, took care of a bunch of compiler warnings --- CMakeLists.txt | 4 ++-- include/sqlpp11/column_fwd.h | 2 +- include/sqlpp11/functions.h | 2 -- include/sqlpp11/insert_value_list.h | 2 +- include/sqlpp11/named_interpretable.h | 2 +- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a3d8eeaf..3dd3e7ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,9 +28,9 @@ enable_testing() message(STATUS "Using ${CMAKE_CXX_COMPILER} (compiler id: ${CMAKE_CXX_COMPILER_ID})") if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ ${CMAKE_CXX_FLAGS}") + set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ -Wall ${CMAKE_CXX_FLAGS}") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}") + set(CMAKE_CXX_FLAGS "-std=c++11 -Wall ${CMAKE_CXX_FLAGS}") endif () set(include_dir "${PROJECT_SOURCE_DIR}/include") diff --git a/include/sqlpp11/column_fwd.h b/include/sqlpp11/column_fwd.h index d378aa6a..634bbe0b 100644 --- a/include/sqlpp11/column_fwd.h +++ b/include/sqlpp11/column_fwd.h @@ -31,7 +31,7 @@ namespace sqlpp { template - class column_t; + struct column_t; } #endif diff --git a/include/sqlpp11/functions.h b/include/sqlpp11/functions.h index 058a3b48..65c05a2e 100644 --- a/include/sqlpp11/functions.h +++ b/include/sqlpp11/functions.h @@ -48,8 +48,6 @@ namespace sqlpp template auto value(T t) -> wrap_operand_t { - using _provided_tables = detail::type_set<>; - using _required_tables = ::sqlpp::detail::type_set<>; static_assert(is_wrapped_value_t>::value, "value() is to be called with non-sql-type like int, or string"); return { t }; } diff --git a/include/sqlpp11/insert_value_list.h b/include/sqlpp11/insert_value_list.h index f02d7a47..513085d5 100644 --- a/include/sqlpp11/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -96,9 +96,9 @@ namespace sqlpp insert_list_data_t& operator=(insert_list_data_t&&) = default; ~insert_list_data_t() = default; + std::tuple _assignments; // FIXME: Need to replace _columns and _values by _assignments (connector-container requires assignments) std::tuple...> _columns; std::tuple _values; - std::tuple _assignments; // FIXME: Need to replace _columns and _values by _assignments (connector-container requires assignments) interpretable_list_t _dynamic_columns; interpretable_list_t _dynamic_values; }; diff --git a/include/sqlpp11/named_interpretable.h b/include/sqlpp11/named_interpretable.h index 78af6e8c..dcbffbdb 100644 --- a/include/sqlpp11/named_interpretable.h +++ b/include/sqlpp11/named_interpretable.h @@ -71,7 +71,7 @@ namespace sqlpp std::string _get_name() const { - _impl->_get_name(); + return _impl->_get_name(); } private: From f113b837402e958fa624d896bef3ad7889684778 Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 28 Jun 2014 20:21:43 +0200 Subject: [PATCH 60/65] Fixed most of the compiler warnings about unused variables in test programs --- tests/InsertTest.cpp | 8 +------- tests/PreparedTest.cpp | 10 +++++----- tests/RemoveTest.cpp | 4 ---- tests/SelectTest.cpp | 9 +++++++-- tests/SelectTypeTest.cpp | 24 +++++------------------- tests/UpdateTest.cpp | 6 +----- 6 files changed, 19 insertions(+), 42 deletions(-) diff --git a/tests/InsertTest.cpp b/tests/InsertTest.cpp index 7a50f1c4..68b06d82 100644 --- a/tests/InsertTest.cpp +++ b/tests/InsertTest.cpp @@ -35,13 +35,7 @@ MockDb::_serializer_context_t printer; int main() { test::TabBar t; - test::TabFoo f; - - auto x = t.alpha = 7; - auto y = t.beta = "kaesekuchen"; - auto z = t.gamma = true; - auto a = t.alpha; - a = t.alpha; + //test::TabFoo f; { using T = decltype(insert_into(t)); diff --git a/tests/PreparedTest.cpp b/tests/PreparedTest.cpp index dcf339a5..ae4cc16e 100644 --- a/tests/PreparedTest.cpp +++ b/tests/PreparedTest.cpp @@ -35,7 +35,7 @@ MockDb db = {}; int main() { - test::TabFoo f; + //test::TabFoo f; test::TabBar t; // empty parameter lists @@ -65,20 +65,20 @@ int main() // single parameter in larger expression { - using T = sqlpp::parameters_of; + using T = sqlpp::parameters_of; static_assert(std::is_same>::value, "type requirement"); } // three parameters in expression { - using T = sqlpp::parameters_of; + using T = sqlpp::parameters_of; static_assert(std::tuple_size::value == 3, "type requirement"); static_assert(std::is_same>::value, "type requirement"); } // OK, fine, now create a named parameter list from an expression { - using Exp = decltype(t.beta.like(parameter(t.beta)) and t.alpha == parameter(t.alpha) or t.gamma != parameter(t.gamma)); + using Exp = decltype((t.beta.like(parameter(t.beta)) and t.alpha == parameter(t.alpha)) or t.gamma != parameter(t.gamma)); using T = sqlpp::make_parameter_list_t; T npl; static_assert(std::is_same::_parameter_t, decltype(npl.alpha)>::value, "type requirement"); @@ -88,7 +88,7 @@ int main() // Wonderful, now take a look at the parameter list of a select { - auto s = select(all_of(t)).from(t).where(t.beta.like(parameter(t.beta)) and t.alpha == parameter(t.alpha) or t.gamma != parameter(t.gamma)); + auto s = select(all_of(t)).from(t).where((t.beta.like(parameter(t.beta)) and t.alpha == parameter(t.alpha)) or t.gamma != parameter(t.gamma)); auto p = db.prepare(s); p.params.alpha = 7; using S = decltype(s); diff --git a/tests/RemoveTest.cpp b/tests/RemoveTest.cpp index 52636a57..0ea34df1 100644 --- a/tests/RemoveTest.cpp +++ b/tests/RemoveTest.cpp @@ -37,10 +37,6 @@ int main() { test::TabBar t; - auto x = t.alpha = 7; - auto y = t.beta = "kaesekuchen"; - auto z = t.gamma = true; - { using T = decltype(remove_from(t)); static_assert(sqlpp::is_regular::value, "type requirement"); diff --git a/tests/SelectTest.cpp b/tests/SelectTest.cpp index 14979a1d..9a94694b 100644 --- a/tests/SelectTest.cpp +++ b/tests/SelectTest.cpp @@ -54,12 +54,14 @@ int main() { int64_t a = row.alpha; const std::string b = row.beta; + std::cout << a << ", " << b << std::endl; } for (const auto& row : db(select(all_of(t).as(t)).from(t).where(true))) { int64_t a = row.tabBar.alpha; const std::string b = row.tabBar.beta; + std::cout << a << ", " << b << std::endl; } for (const auto& row : db(select(all_of(t).as(t), t.gamma).from(t).where(t.alpha > 7))) @@ -67,9 +69,11 @@ int main() int64_t a = row.tabBar.alpha; const std::string b = row.tabBar.beta; const bool g = row.gamma; + std::cout << a << ", " << b << ", " << g << std::endl; } auto stat = sqlpp::select().columns(all_of(t)).flags(sqlpp::all).from(t).extra_tables(f,t).where(t.alpha > 0).group_by(t.alpha).order_by(t.gamma.asc()).having(t.gamma).limit(7).offset(19); + auto s = dynamic_select(db).dynamic_columns(all_of(t)).dynamic_flags().dynamic_from(t).extra_tables(f,t).dynamic_where().dynamic_group_by(t.alpha).dynamic_order_by().dynamic_having(t.gamma).dynamic_limit().dynamic_offset(); s.select_flags.add(sqlpp::distinct); s.selected_columns.add(f.omega); @@ -83,12 +87,13 @@ int main() for (const auto& row : db(s)) { int64_t a = row.alpha; + std::cout << a << std::endl; } printer.reset(); std::cerr << serialize(s, printer).str() << std::endl; - - auto X = select(all_of(t)).from(t).as(t.alpha); + printer.reset(); + std::cerr << serialize(stat, printer).str() << std::endl; return 0; } diff --git a/tests/SelectTypeTest.cpp b/tests/SelectTypeTest.cpp index 8e19ec4e..2361a623 100644 --- a/tests/SelectTypeTest.cpp +++ b/tests/SelectTypeTest.cpp @@ -289,8 +289,11 @@ int main() // Test that a multicolumn is not a value { auto m = multi_column(t.alpha, t.beta).as(alias::a); + static_assert(not sqlpp::is_expression_t::value, "a multi_column is not a value"); + +#warning: A multicolumn cannot be used if the select is to be used like a table auto a = select(m).from(t).as(alias::b).a; - // FIXME: Do we really need that test? multi_column is a no_value static_assert(not sqlpp::is_expression_t::value, "a multi_column is not a value"); + //static_assert(not sqlpp::is_expression_t::value, "a multi_column is not a value"); } // Test that result sets with identical name/value combinations have identical types { @@ -307,6 +310,7 @@ int main() for (const auto& row : db(select(all_of(t)).from(t).where(true))) { int64_t a = row.alpha; + std::cout << a << std::endl; } { @@ -344,8 +348,6 @@ int main() static_assert(sqlpp::is_numeric_t::value, "TabBar.alpha has to be a numeric"); ((t.alpha + 7) + 4).asc(); static_assert(sqlpp::is_boolean_t::value, "Comparison expression have to be boolean"); - auto x = (t.gamma == true) and (t.alpha == 7); - auto y = t.gamma and true and t.gamma; !t.gamma; t.beta < "kaesekuchen"; serialize(t.beta + "hallenhalma", printer).str(); @@ -356,25 +358,9 @@ int main() static_assert(sqlpp::is_named_expression_t::value, "an alias of alpha should be a named expression"); static_assert(sqlpp::is_alias_t::value, "an alias of alpha should be an alias"); - auto z = select(t.alpha).from(t) == 7; auto l = t.as(alias::left); auto r = select(t.gamma.as(alias::a)).from(t).where(t.gamma == true).as(alias::right); - using R = decltype(r); static_assert(sqlpp::is_boolean_t::value, "select(bool) has to be a bool"); - auto s = select(r.a).from(r); - using RA = decltype(r.a); - using S = decltype(s); - /* - using SCL = typename S::_column_list_t; - using SF = typename S::_from_t; - static_assert(sqlpp::is_select_column_list_t::value, "no column list"); - static_assert(sqlpp::is_from_t::value, "no from list"); - using SCL_T = typename SCL::_table_set; - using SF_T = typename SF::_table_set; - static_assert(SCL_T::size::value == 1, "unexpected table_set in column_list"); - static_assert(SF_T::size::value == 1, "unexpected table_set in from"); - static_assert(std::is_same::value, "should be the same"); - */ static_assert(sqlpp::is_boolean_t::value, "select(bool) has to be a bool"); auto s1 = sqlpp::select().flags(sqlpp::distinct, sqlpp::straight_join).columns(l.alpha, l.beta, select(r.a).from(r)) .from(r,t,l) diff --git a/tests/UpdateTest.cpp b/tests/UpdateTest.cpp index 6f7a0c0b..e3f8de62 100644 --- a/tests/UpdateTest.cpp +++ b/tests/UpdateTest.cpp @@ -35,11 +35,7 @@ MockDb::_serializer_context_t printer; int main() { test::TabBar t; - test::TabFoo f; - - auto x = t.alpha = 7; - auto y = t.beta = "kaesekuchen"; - auto z = t.gamma = true; + //test::TabFoo f; { using T = decltype(update(t)); From 39413ee1bb9aebfe97deeec342f886cc0bfa90c7 Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 28 Jun 2014 21:02:49 +0200 Subject: [PATCH 61/65] Added check to prevent multicolumns in sub selects --- include/sqlpp11/multi_column.h | 2 +- include/sqlpp11/select_column_list.h | 1 + tests/SelectTypeTest.cpp | 5 +---- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/include/sqlpp11/multi_column.h b/include/sqlpp11/multi_column.h index 52de9d5f..ac09881c 100644 --- a/include/sqlpp11/multi_column.h +++ b/include/sqlpp11/multi_column.h @@ -76,7 +76,7 @@ namespace sqlpp template struct multi_column_alias_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; static_assert(detail::all_t::value...>::value, "multi_column parameters need to be named expressions"); diff --git a/include/sqlpp11/select_column_list.h b/include/sqlpp11/select_column_list.h index c24da000..0aab60ff 100644 --- a/include/sqlpp11/select_column_list.h +++ b/include/sqlpp11/select_column_list.h @@ -269,6 +269,7 @@ namespace sqlpp _alias_t as(const AliasProvider& aliasProvider) const { static_assert(Policies::_can_be_used_as_table::value, "statement cannot be used as table, e.g. due to missing tables"); + static_assert(::sqlpp::detail::none_t::value...>::value, "cannot use multi-columns in sub selects"); return _table_t(_get_statement()).as(aliasProvider); } diff --git a/tests/SelectTypeTest.cpp b/tests/SelectTypeTest.cpp index 2361a623..f709947a 100644 --- a/tests/SelectTypeTest.cpp +++ b/tests/SelectTypeTest.cpp @@ -290,11 +290,8 @@ int main() { auto m = multi_column(t.alpha, t.beta).as(alias::a); static_assert(not sqlpp::is_expression_t::value, "a multi_column is not a value"); - -#warning: A multicolumn cannot be used if the select is to be used like a table - auto a = select(m).from(t).as(alias::b).a; - //static_assert(not sqlpp::is_expression_t::value, "a multi_column is not a value"); } + // Test that result sets with identical name/value combinations have identical types { auto a = select(t.alpha); From 7900cba1ca58fedc9e42940307b7323df99c5afe Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 28 Jun 2014 20:21:43 +0200 Subject: [PATCH 62/65] Fixed most of the compiler warnings about unused variables in test programs --- tests/InsertTest.cpp | 8 +------- tests/PreparedTest.cpp | 10 +++++----- tests/RemoveTest.cpp | 4 ---- tests/SelectTest.cpp | 9 +++++++-- tests/SelectTypeTest.cpp | 24 +++++------------------- tests/UpdateTest.cpp | 6 +----- 6 files changed, 19 insertions(+), 42 deletions(-) diff --git a/tests/InsertTest.cpp b/tests/InsertTest.cpp index 7a50f1c4..68b06d82 100644 --- a/tests/InsertTest.cpp +++ b/tests/InsertTest.cpp @@ -35,13 +35,7 @@ MockDb::_serializer_context_t printer; int main() { test::TabBar t; - test::TabFoo f; - - auto x = t.alpha = 7; - auto y = t.beta = "kaesekuchen"; - auto z = t.gamma = true; - auto a = t.alpha; - a = t.alpha; + //test::TabFoo f; { using T = decltype(insert_into(t)); diff --git a/tests/PreparedTest.cpp b/tests/PreparedTest.cpp index dcf339a5..ae4cc16e 100644 --- a/tests/PreparedTest.cpp +++ b/tests/PreparedTest.cpp @@ -35,7 +35,7 @@ MockDb db = {}; int main() { - test::TabFoo f; + //test::TabFoo f; test::TabBar t; // empty parameter lists @@ -65,20 +65,20 @@ int main() // single parameter in larger expression { - using T = sqlpp::parameters_of; + using T = sqlpp::parameters_of; static_assert(std::is_same>::value, "type requirement"); } // three parameters in expression { - using T = sqlpp::parameters_of; + using T = sqlpp::parameters_of; static_assert(std::tuple_size::value == 3, "type requirement"); static_assert(std::is_same>::value, "type requirement"); } // OK, fine, now create a named parameter list from an expression { - using Exp = decltype(t.beta.like(parameter(t.beta)) and t.alpha == parameter(t.alpha) or t.gamma != parameter(t.gamma)); + using Exp = decltype((t.beta.like(parameter(t.beta)) and t.alpha == parameter(t.alpha)) or t.gamma != parameter(t.gamma)); using T = sqlpp::make_parameter_list_t; T npl; static_assert(std::is_same::_parameter_t, decltype(npl.alpha)>::value, "type requirement"); @@ -88,7 +88,7 @@ int main() // Wonderful, now take a look at the parameter list of a select { - auto s = select(all_of(t)).from(t).where(t.beta.like(parameter(t.beta)) and t.alpha == parameter(t.alpha) or t.gamma != parameter(t.gamma)); + auto s = select(all_of(t)).from(t).where((t.beta.like(parameter(t.beta)) and t.alpha == parameter(t.alpha)) or t.gamma != parameter(t.gamma)); auto p = db.prepare(s); p.params.alpha = 7; using S = decltype(s); diff --git a/tests/RemoveTest.cpp b/tests/RemoveTest.cpp index 52636a57..0ea34df1 100644 --- a/tests/RemoveTest.cpp +++ b/tests/RemoveTest.cpp @@ -37,10 +37,6 @@ int main() { test::TabBar t; - auto x = t.alpha = 7; - auto y = t.beta = "kaesekuchen"; - auto z = t.gamma = true; - { using T = decltype(remove_from(t)); static_assert(sqlpp::is_regular::value, "type requirement"); diff --git a/tests/SelectTest.cpp b/tests/SelectTest.cpp index 14979a1d..9a94694b 100644 --- a/tests/SelectTest.cpp +++ b/tests/SelectTest.cpp @@ -54,12 +54,14 @@ int main() { int64_t a = row.alpha; const std::string b = row.beta; + std::cout << a << ", " << b << std::endl; } for (const auto& row : db(select(all_of(t).as(t)).from(t).where(true))) { int64_t a = row.tabBar.alpha; const std::string b = row.tabBar.beta; + std::cout << a << ", " << b << std::endl; } for (const auto& row : db(select(all_of(t).as(t), t.gamma).from(t).where(t.alpha > 7))) @@ -67,9 +69,11 @@ int main() int64_t a = row.tabBar.alpha; const std::string b = row.tabBar.beta; const bool g = row.gamma; + std::cout << a << ", " << b << ", " << g << std::endl; } auto stat = sqlpp::select().columns(all_of(t)).flags(sqlpp::all).from(t).extra_tables(f,t).where(t.alpha > 0).group_by(t.alpha).order_by(t.gamma.asc()).having(t.gamma).limit(7).offset(19); + auto s = dynamic_select(db).dynamic_columns(all_of(t)).dynamic_flags().dynamic_from(t).extra_tables(f,t).dynamic_where().dynamic_group_by(t.alpha).dynamic_order_by().dynamic_having(t.gamma).dynamic_limit().dynamic_offset(); s.select_flags.add(sqlpp::distinct); s.selected_columns.add(f.omega); @@ -83,12 +87,13 @@ int main() for (const auto& row : db(s)) { int64_t a = row.alpha; + std::cout << a << std::endl; } printer.reset(); std::cerr << serialize(s, printer).str() << std::endl; - - auto X = select(all_of(t)).from(t).as(t.alpha); + printer.reset(); + std::cerr << serialize(stat, printer).str() << std::endl; return 0; } diff --git a/tests/SelectTypeTest.cpp b/tests/SelectTypeTest.cpp index 8e19ec4e..2361a623 100644 --- a/tests/SelectTypeTest.cpp +++ b/tests/SelectTypeTest.cpp @@ -289,8 +289,11 @@ int main() // Test that a multicolumn is not a value { auto m = multi_column(t.alpha, t.beta).as(alias::a); + static_assert(not sqlpp::is_expression_t::value, "a multi_column is not a value"); + +#warning: A multicolumn cannot be used if the select is to be used like a table auto a = select(m).from(t).as(alias::b).a; - // FIXME: Do we really need that test? multi_column is a no_value static_assert(not sqlpp::is_expression_t::value, "a multi_column is not a value"); + //static_assert(not sqlpp::is_expression_t::value, "a multi_column is not a value"); } // Test that result sets with identical name/value combinations have identical types { @@ -307,6 +310,7 @@ int main() for (const auto& row : db(select(all_of(t)).from(t).where(true))) { int64_t a = row.alpha; + std::cout << a << std::endl; } { @@ -344,8 +348,6 @@ int main() static_assert(sqlpp::is_numeric_t::value, "TabBar.alpha has to be a numeric"); ((t.alpha + 7) + 4).asc(); static_assert(sqlpp::is_boolean_t::value, "Comparison expression have to be boolean"); - auto x = (t.gamma == true) and (t.alpha == 7); - auto y = t.gamma and true and t.gamma; !t.gamma; t.beta < "kaesekuchen"; serialize(t.beta + "hallenhalma", printer).str(); @@ -356,25 +358,9 @@ int main() static_assert(sqlpp::is_named_expression_t::value, "an alias of alpha should be a named expression"); static_assert(sqlpp::is_alias_t::value, "an alias of alpha should be an alias"); - auto z = select(t.alpha).from(t) == 7; auto l = t.as(alias::left); auto r = select(t.gamma.as(alias::a)).from(t).where(t.gamma == true).as(alias::right); - using R = decltype(r); static_assert(sqlpp::is_boolean_t::value, "select(bool) has to be a bool"); - auto s = select(r.a).from(r); - using RA = decltype(r.a); - using S = decltype(s); - /* - using SCL = typename S::_column_list_t; - using SF = typename S::_from_t; - static_assert(sqlpp::is_select_column_list_t::value, "no column list"); - static_assert(sqlpp::is_from_t::value, "no from list"); - using SCL_T = typename SCL::_table_set; - using SF_T = typename SF::_table_set; - static_assert(SCL_T::size::value == 1, "unexpected table_set in column_list"); - static_assert(SF_T::size::value == 1, "unexpected table_set in from"); - static_assert(std::is_same::value, "should be the same"); - */ static_assert(sqlpp::is_boolean_t::value, "select(bool) has to be a bool"); auto s1 = sqlpp::select().flags(sqlpp::distinct, sqlpp::straight_join).columns(l.alpha, l.beta, select(r.a).from(r)) .from(r,t,l) diff --git a/tests/UpdateTest.cpp b/tests/UpdateTest.cpp index 6f7a0c0b..e3f8de62 100644 --- a/tests/UpdateTest.cpp +++ b/tests/UpdateTest.cpp @@ -35,11 +35,7 @@ MockDb::_serializer_context_t printer; int main() { test::TabBar t; - test::TabFoo f; - - auto x = t.alpha = 7; - auto y = t.beta = "kaesekuchen"; - auto z = t.gamma = true; + //test::TabFoo f; { using T = decltype(update(t)); From 0f9c1dbfb222d1132e9d889e8e17e1b8eea1fd2b Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 28 Jun 2014 21:02:49 +0200 Subject: [PATCH 63/65] Added check to prevent multicolumns in sub selects --- include/sqlpp11/multi_column.h | 2 +- include/sqlpp11/select_column_list.h | 1 + tests/SelectTypeTest.cpp | 5 +---- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/include/sqlpp11/multi_column.h b/include/sqlpp11/multi_column.h index 52de9d5f..ac09881c 100644 --- a/include/sqlpp11/multi_column.h +++ b/include/sqlpp11/multi_column.h @@ -76,7 +76,7 @@ namespace sqlpp template struct multi_column_alias_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; static_assert(detail::all_t::value...>::value, "multi_column parameters need to be named expressions"); diff --git a/include/sqlpp11/select_column_list.h b/include/sqlpp11/select_column_list.h index c24da000..0aab60ff 100644 --- a/include/sqlpp11/select_column_list.h +++ b/include/sqlpp11/select_column_list.h @@ -269,6 +269,7 @@ namespace sqlpp _alias_t as(const AliasProvider& aliasProvider) const { static_assert(Policies::_can_be_used_as_table::value, "statement cannot be used as table, e.g. due to missing tables"); + static_assert(::sqlpp::detail::none_t::value...>::value, "cannot use multi-columns in sub selects"); return _table_t(_get_statement()).as(aliasProvider); } diff --git a/tests/SelectTypeTest.cpp b/tests/SelectTypeTest.cpp index 2361a623..f709947a 100644 --- a/tests/SelectTypeTest.cpp +++ b/tests/SelectTypeTest.cpp @@ -290,11 +290,8 @@ int main() { auto m = multi_column(t.alpha, t.beta).as(alias::a); static_assert(not sqlpp::is_expression_t::value, "a multi_column is not a value"); - -#warning: A multicolumn cannot be used if the select is to be used like a table - auto a = select(m).from(t).as(alias::b).a; - //static_assert(not sqlpp::is_expression_t::value, "a multi_column is not a value"); } + // Test that result sets with identical name/value combinations have identical types { auto a = select(t.alpha); From 2f20f7ef823589260a49ad5386bae8afc683de48 Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 29 Jun 2014 11:35:51 +0200 Subject: [PATCH 64/65] Renamed bind and (in)validate to indicate their usage (vendor only) --- include/sqlpp11/boolean.h | 4 +-- include/sqlpp11/floating_point.h | 4 +-- include/sqlpp11/integral.h | 4 +-- include/sqlpp11/result_row.h | 44 ++++++++++++++++---------------- include/sqlpp11/text.h | 4 +-- tests/MockDb.h | 2 +- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/include/sqlpp11/boolean.h b/include/sqlpp11/boolean.h index ed8fe94c..e0a31821 100644 --- a/include/sqlpp11/boolean.h +++ b/include/sqlpp11/boolean.h @@ -118,12 +118,12 @@ namespace sqlpp _value = _is_null ? false : (data[0] == 't' or data[0] == '1'); } - void validate() + void _validate() { _is_valid = true; } - void invalidate() + void _invalidate() { _is_valid = false; _is_null = true; diff --git a/include/sqlpp11/floating_point.h b/include/sqlpp11/floating_point.h index 0b9b57b6..ccf7a43b 100644 --- a/include/sqlpp11/floating_point.h +++ b/include/sqlpp11/floating_point.h @@ -119,12 +119,12 @@ namespace sqlpp _value = _is_null ? 0 : std::strtoll(data, nullptr, 10); } - void validate() + void _validate() { _is_valid = true; } - void invalidate() + void _invalidate() { _is_valid = false; _is_null = true; diff --git a/include/sqlpp11/integral.h b/include/sqlpp11/integral.h index 791df00c..61a0bf3c 100644 --- a/include/sqlpp11/integral.h +++ b/include/sqlpp11/integral.h @@ -121,14 +121,14 @@ namespace sqlpp _value = _is_null ? 0 : std::strtoll(data, nullptr, 10); } - void invalidate() + void _invalidate() { _is_valid = false; _is_null = true; _value = 0; } - void validate() + void _validate() { _is_valid = true; } diff --git a/include/sqlpp11/result_row.h b/include/sqlpp11/result_row.h index 18f4ada2..1094692d 100644 --- a/include/sqlpp11/result_row.h +++ b/include/sqlpp11/result_row.h @@ -47,14 +47,14 @@ namespace sqlpp result_field() = default; - void validate() + void _validate() { - _field::operator()().validate(); + _field::operator()()._validate(); } - void invalidate() + void _invalidate() { - _field::operator()().invalidate(); + _field::operator()()._invalidate(); } template @@ -72,14 +72,14 @@ namespace sqlpp result_field() = default; - void validate() + void _validate() { - _multi_field::operator()().validate(); + _multi_field::operator()()._validate(); } - void invalidate() + void _invalidate() { - _multi_field::operator()().invalidate(); + _multi_field::operator()()._invalidate(); } template @@ -97,16 +97,16 @@ namespace sqlpp result_row_impl() = default; - void validate() + void _validate() { using swallow = int[]; - (void) swallow{(result_field::validate(), 0)...}; + (void) swallow{(result_field::_validate(), 0)...}; } - void invalidate() + void _invalidate() { using swallow = int[]; - (void) swallow{(result_field::invalidate(), 0)...}; + (void) swallow{(result_field::_invalidate(), 0)...}; } template @@ -144,15 +144,15 @@ namespace sqlpp result_row_t& operator=(const result_row_t&) = delete; result_row_t& operator=(result_row_t&&) = default; - void validate() + void _validate() { - _impl::validate(); + _impl::_validate(); _is_valid = true; } - void invalidate() + void _invalidate() { - _impl::invalidate(); + _impl::_invalidate(); _is_valid = false; } @@ -211,24 +211,24 @@ namespace sqlpp dynamic_result_row_t& operator=(const dynamic_result_row_t&) = delete; dynamic_result_row_t& operator=(dynamic_result_row_t&&) = default; - void validate() + void _validate() { - _impl::validate(); + _impl::_validate(); _is_valid = true; for (auto& field : _dynamic_fields) { - field.second.validate(); + field.second._validate(); } } - void invalidate() + void _invalidate() { - _impl::invalidate(); + _impl::_invalidate(); _is_valid = false; for (auto& field : _dynamic_fields) { - field.second.invalidate(); + field.second._invalidate(); } } diff --git a/include/sqlpp11/text.h b/include/sqlpp11/text.h index 0e0c6a53..1f50667a 100644 --- a/include/sqlpp11/text.h +++ b/include/sqlpp11/text.h @@ -117,12 +117,12 @@ namespace sqlpp _len = _value_ptr ? len: 0; } - void validate() + void _validate() { _is_valid = true; } - void invalidate() + void _invalidate() { _is_valid = false; _value_ptr = nullptr; diff --git a/tests/MockDb.h b/tests/MockDb.h index a80067de..9c4dafd9 100644 --- a/tests/MockDb.h +++ b/tests/MockDb.h @@ -85,7 +85,7 @@ struct MockDb: public sqlpp::connection template void next(ResultRow& result_row) { - result_row.invalidate(); + result_row._invalidate(); }; }; From abb97b623b942b25fcfba5293d7799569f94edd2 Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 29 Jun 2014 12:52:21 +0200 Subject: [PATCH 65/65] Removed remainder of char_result_row interface from fields --- include/sqlpp11/boolean.h | 13 ------------- include/sqlpp11/floating_point.h | 13 ------------- include/sqlpp11/integral.h | 13 ------------- include/sqlpp11/text.h | 13 ------------- 4 files changed, 52 deletions(-) diff --git a/include/sqlpp11/boolean.h b/include/sqlpp11/boolean.h index e0a31821..786b2200 100644 --- a/include/sqlpp11/boolean.h +++ b/include/sqlpp11/boolean.h @@ -105,19 +105,6 @@ namespace sqlpp _value(false) {} - _result_entry_t(const char* data, size_t): - _is_valid(true), - _is_null(data == nullptr), - _value(_is_null ? false : (data[0] == 't' or data[0] == '1')) - {} - - void assign(const char* data, size_t) - { - _is_valid = true; - _is_null = data == nullptr; - _value = _is_null ? false : (data[0] == 't' or data[0] == '1'); - } - void _validate() { _is_valid = true; diff --git a/include/sqlpp11/floating_point.h b/include/sqlpp11/floating_point.h index ccf7a43b..a39c85ae 100644 --- a/include/sqlpp11/floating_point.h +++ b/include/sqlpp11/floating_point.h @@ -106,19 +106,6 @@ namespace sqlpp _value(0) {} - _result_entry_t(const char* data, size_t): - _is_valid(true), - _is_null(data == nullptr), - _value(_is_null ? 0 : std::strtoll(data, nullptr, 10)) - {} - - void assign(const char* data, size_t) - { - _is_valid = true; - _is_null = data == nullptr; - _value = _is_null ? 0 : std::strtoll(data, nullptr, 10); - } - void _validate() { _is_valid = true; diff --git a/include/sqlpp11/integral.h b/include/sqlpp11/integral.h index 61a0bf3c..c1ab26bf 100644 --- a/include/sqlpp11/integral.h +++ b/include/sqlpp11/integral.h @@ -108,19 +108,6 @@ namespace sqlpp _value(0) {} - _result_entry_t(const char* data, size_t): - _is_valid(true), - _is_null(data == nullptr), - _value(_is_null ? 0 : std::strtoll(data, nullptr, 10)) - {} - - void assign(const char* data, size_t) - { - _is_valid = true; - _is_null = data == nullptr; - _value = _is_null ? 0 : std::strtoll(data, nullptr, 10); - } - void _invalidate() { _is_valid = false; diff --git a/include/sqlpp11/text.h b/include/sqlpp11/text.h index 1f50667a..6cce5aea 100644 --- a/include/sqlpp11/text.h +++ b/include/sqlpp11/text.h @@ -104,19 +104,6 @@ namespace sqlpp _len(0) {} - _result_entry_t(char* data, size_t len): - _is_valid(true), - _value_ptr(data), - _len(_value_ptr ? 0 : len) - {} - - void assign(const char* data, size_t len) - { - _is_valid = true; - _value_ptr = data; - _len = _value_ptr ? len: 0; - } - void _validate() { _is_valid = true;