From 37a550a489ec3a8ee9d6f32f647ec275ce966447 Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 24 Jul 2014 09:29:50 +0200 Subject: [PATCH] Use potential outer table dependencies in pseudo tables The dependency indicates whether a column of a pseudo table can be null. --- include/sqlpp11/detail/type_set.h | 19 ++++++++++++++++++- include/sqlpp11/field.h | 1 + include/sqlpp11/select_pseudo_table.h | 10 ++++++---- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/include/sqlpp11/detail/type_set.h b/include/sqlpp11/detail/type_set.h index a46ffb9b..1e95cc6a 100644 --- a/include/sqlpp11/detail/type_set.h +++ b/include/sqlpp11/detail/type_set.h @@ -204,13 +204,30 @@ namespace sqlpp struct make_difference_set, type_set> { template - using is_subtrahend = is_element_of>; + using is_subtrahend = is_element_of>; using type = typename make_type_set_if_not::type; }; template using make_difference_set_t = typename make_difference_set::type; + template + struct make_intersect_set + { + static_assert(::sqlpp::wrong_t::value, "invalid argument for intersect set"); + }; + + template + struct make_intersect_set, type_set> + { + template + using is_in_both = is_element_of>; + using type = typename make_type_set_if::type; + }; + + template + using make_intersect_set_t = typename make_intersect_set::type; + template class Transformation, typename T> struct transform_set diff --git a/include/sqlpp11/field.h b/include/sqlpp11/field.h index 1a5db815..02e0a849 100644 --- a/include/sqlpp11/field.h +++ b/include/sqlpp11/field.h @@ -48,6 +48,7 @@ namespace sqlpp namespace detail { +#warning: Need to transport the "can be null" information via field_t to result_entry structs template struct make_field_t_impl { diff --git a/include/sqlpp11/select_pseudo_table.h b/include/sqlpp11/select_pseudo_table.h index 60bb9c9b..856845b5 100644 --- a/include/sqlpp11/select_pseudo_table.h +++ b/include/sqlpp11/select_pseudo_table.h @@ -32,16 +32,18 @@ namespace sqlpp { // provide type information for sub-selects that are used as named expressions or tables - template + template struct select_column_spec_t { -#warning use Select here to determine if a column relates to a outer join table using _name_t = typename NamedExpr::_name_t; + static constexpr bool _can_be_null = can_be_null_t::value; + static constexpr bool _depends_on_outer_table = detail::make_intersect_set_t, typename Select::_used_outer_tables>::size::value > 0; + using _traits = make_traits, tag::must_not_insert, tag::must_not_update, - typename std::conditional::value, tag::can_be_null, void>::type + typename std::conditional<_can_be_null or _depends_on_outer_table, tag::can_be_null, void>::type >; }; @@ -51,7 +53,7 @@ namespace sqlpp > struct select_pseudo_table_t: public sqlpp::table_t, select_column_spec_t...> + NamedExpr...>, select_column_spec_t...> { using _traits = make_traits; using _recursive_traits = make_recursive_traits<>;