From ee3d803c33d351ddc7bba4609616ab1308510d69 Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 8 Feb 2015 18:26:36 +0100 Subject: [PATCH] Added a few cte checks, fixed logic of requiring and providing ctes --- include/sqlpp11/cte.h | 42 +++++++++++++++++++++++++++++------ include/sqlpp11/type_traits.h | 2 +- include/sqlpp11/with.h | 13 ++++++++++- 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/include/sqlpp11/cte.h b/include/sqlpp11/cte.h index fd40f789..5fa9c177 100644 --- a/include/sqlpp11/cte.h +++ b/include/sqlpp11/cte.h @@ -71,12 +71,12 @@ namespace sqlpp template struct cte_t: public member_t>... { - using _traits = make_traits; + using _traits = make_traits; // FIXME: is table? really? struct _recursive_traits { - using _required_ctes = required_ctes_of; - using _provided_ctes = detail::make_type_set_t; - using _required_tables = required_tables_of; + using _required_ctes = detail::make_joined_set_t, detail::make_type_set_t>; + using _provided_ctes = detail::type_set<>; + using _required_tables = detail::type_set<>; using _provided_tables = detail::type_set; using _provided_outer_tables = detail::type_set<>; using _extra_tables = detail::type_set<>; @@ -122,17 +122,45 @@ namespace sqlpp template struct pre_cte_t { + using _traits = make_traits; // FIXME: is table? really? + struct _recursive_traits + { + using _required_ctes = detail::make_type_set_t; + using _provided_ctes = detail::type_set<>; + using _required_tables = detail::type_set<>; + using _provided_tables = detail::type_set; + using _provided_outer_tables = detail::type_set<>; + using _extra_tables = detail::type_set<>; + using _parameters = std::tuple<>; + using _tags = detail::type_set<>; + }; + + using _alias_t = typename AliasProvider::_alias_t; + template auto as(Statement statement) -> make_cte_t { - // FIXME: Need to check stuff here. - // e.g. make sure that the statement does not require this a cte of this name (other ctes are allowed) - // make sure that the statement does not depend on external tables + static_assert(required_tables_of::size::value == 0, "common table expression must not use unknown tables"); + static_assert(not detail::is_element_of>::value, "common table expression must not self-reference in the first part, use union_all/union_distinct for recursion"); + return { statement }; } }; + template + struct serializer_t> + { + using _serialize_check = consistent_t; + using T = pre_cte_t; + + static Context& _(const T& t, Context& context) + { + context << name_of::char_ptr(); + return context; + } + }; + template auto cte(const AliasProvider&) -> pre_cte_t diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index 8dee9b18..d11fa9f7 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -227,7 +227,7 @@ namespace sqlpp struct make_recursive_traits { using _required_ctes = detail::make_joined_set_t...>; - using _provided_ctes = detail::make_joined_set_t...>; + using _provided_ctes = detail::make_joined_set_t...>; using _required_tables = detail::make_joined_set_t...>; using _provided_tables = detail::make_joined_set_t...>; using _provided_outer_tables = detail::make_joined_set_t...>; diff --git a/include/sqlpp11/with.h b/include/sqlpp11/with.h index 48a2e5c3..399c94d8 100644 --- a/include/sqlpp11/with.h +++ b/include/sqlpp11/with.h @@ -62,7 +62,18 @@ namespace sqlpp struct with_t { using _traits = make_traits; - using _recursive_traits = make_recursive_traits; + struct _recursive_traits + { + using _required_ctes = detail::type_set<>; + using _provided_ctes = detail::make_joined_set_t...>; // with provides common table expressions + using _required_tables = detail::type_set<>; + using _provided_tables = detail::type_set<>; + using _provided_outer_tables = detail::type_set<>; + using _extra_tables = detail::type_set<>; + using _parameters = detail::make_parameter_tuple_t...>; + using _tags = detail::type_set<>; + }; + using _is_dynamic = is_database;