diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 652c12cf..27408cff 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -69,6 +69,12 @@ namespace sqlpp { using _column_list_t = ColumnList; using _from_t = ColumnList; + + using _value_type = typename std::conditional< + sqlpp::is_from_t::value, + typename ColumnList::_value_type, + no_value_t // If there is no from, the select is not complete (this logic is a bit simple, but better than nothing) + >::type; template struct can_run_t { @@ -87,7 +93,7 @@ namespace sqlpp // SELECT template struct select_t: public vendor::policy_t..., public vendor::crtp_wrapper_t, Policies>..., - public detail::select_helper_t::_column_list_t::_value_type::template operators> + public detail::select_helper_t::_value_type::template operators> { template using _policy_update_t = select_t...>; @@ -103,8 +109,7 @@ namespace sqlpp using _is_select = std::true_type; using _requires_braces = std::true_type; - // FIXME: introduce checks whether this select could really be used as a value - using _value_type = typename _column_list_t::_value_type; + using _value_type = typename detail::select_helper_t::_value_type; using _name_t = typename _column_list_t::_name_t; select_t() diff --git a/include/sqlpp11/vendor/from.h b/include/sqlpp11/vendor/from.h index 8cdfa710..e94a8c5f 100644 --- a/include/sqlpp11/vendor/from.h +++ b/include/sqlpp11/vendor/from.h @@ -79,7 +79,6 @@ namespace sqlpp struct no_from_t { - using _is_from = std::true_type; const no_from_t& _from() const { return *this; } }; diff --git a/tests/SelectTest.cpp b/tests/SelectTest.cpp index 9172920c..4f030c75 100644 --- a/tests/SelectTest.cpp +++ b/tests/SelectTest.cpp @@ -159,8 +159,6 @@ 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 -#warning Need to reactivate these tests - /* 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"); @@ -172,7 +170,6 @@ int main() static_assert(not sqlpp::is_alias_t::value, "type requirement"); static_assert(not sqlpp::is_table_t::value, "type requirement"); static_assert(sqlpp::is_regular::value, "type requirement"); - */ } // Test a select of a single numeric table column @@ -360,7 +357,7 @@ int main() 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"); - auto z = select(t.alpha) == 7; + 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); static_assert(sqlpp::is_boolean_t::value, "select(bool) has to be a bool");