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...)); } }