diff --git a/include/sqlpp11/cte.h b/include/sqlpp11/cte.h index 34b33506..86aea573 100644 --- a/include/sqlpp11/cte.h +++ b/include/sqlpp11/cte.h @@ -71,6 +71,19 @@ namespace sqlpp template struct cte_t: public member_t>... // FIXME { + using _traits = make_traits; + struct _recursive_traits + { + using _required_ctes = required_ctes_of; + using _provided_ctes = detail::make_type_set_t; + using _required_tables = required_tables_of; + using _provided_tables = detail::type_set; + using _provided_outer_tables = detail::type_set<>; + using _extra_tables = detail::type_set<>; + using _parameters = parameters_of; + using _tags = detail::type_set<>; + }; + using _alias_t = typename AliasProvider::_alias_t; cte_t(Statement statement): _statement(statement){} diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index 31f6a68e..e1f0239c 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -126,6 +126,8 @@ namespace sqlpp SQLPP_VALUE_TRAIT_GENERATOR(trivial_value_is_null); SQLPP_VALUE_TRAIT_GENERATOR(null_is_trivial_value); + SQLPP_VALUE_TRAIT_GENERATOR(is_with); + SQLPP_VALUE_TRAIT_GENERATOR(is_cte); SQLPP_VALUE_TRAIT_GENERATOR(is_statement); SQLPP_VALUE_TRAIT_GENERATOR(is_prepared_statement); SQLPP_VALUE_TRAIT_GENERATOR(is_noop); diff --git a/include/sqlpp11/with.h b/include/sqlpp11/with.h index 8700641c..63ecf249 100644 --- a/include/sqlpp11/with.h +++ b/include/sqlpp11/with.h @@ -56,13 +56,12 @@ namespace sqlpp ~with_data_t() = default; std::tuple _expressions; - interpretable_list_t _dynamic_expressions; }; template struct with_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; using _is_dynamic = is_database; @@ -84,14 +83,14 @@ namespace sqlpp { using _data_t = with_data_t; - _impl_t where; - _impl_t& operator()() { return where; } - const _impl_t& operator()() const { return where; } + _impl_t with; + _impl_t& operator()() { return with; } + const _impl_t& operator()() const { return with; } template - static auto _get_member(T t) -> decltype(t.where) + static auto _get_member(T t) -> decltype(t.with) { - return t.where; + return t.with; } #warning: Need real checks here @@ -102,7 +101,7 @@ namespace sqlpp struct no_with_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; // Data @@ -143,13 +142,28 @@ namespace sqlpp template auto operator()(Statement statement) - -> new_statement_t> + -> new_statement_t> { // FIXME need checks here, e.g. if there is recursion return { statement, _data }; } }; + // Interpreters + template + struct serializer_t> + { + using _serialize_check = serialize_check_of; + using T = with_data_t; + + static Context& _(const T& t, Context& context) + { + context << " WITH "; + interpret_tuple(t._expressions, ',', context); + return context; + } + }; + template auto with(Expressions... cte) -> blank_with_t diff --git a/tests/WithTest.cpp b/tests/WithTest.cpp index 6992458a..32b27ed4 100644 --- a/tests/WithTest.cpp +++ b/tests/WithTest.cpp @@ -37,7 +37,8 @@ int main() const auto t = test::TabBar{}; auto x = cte(sqlpp::x).as(select(all_of(t)).from(t)); - // to be done + + db(with(x)(select(x.alpha).from(x).where(true))); return 0; }