diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 55077409..4cdef8de 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -129,6 +129,12 @@ namespace sqlpp using _extra_tables = detail::type_set<>; }; + static void _check_consistency() + { +#warning check for missing terms here, and for missing tables + static_assert(not required_tables_of::size::value, "one sub expression requires tables which are otherwise not known in the statement"); + } + }; } @@ -147,18 +153,8 @@ namespace sqlpp using _traits = make_traits, ::sqlpp::tag::select, tag::expression_if, tag::named_expression_if>; using _recursive_traits = typename _policies_t::_recursive_traits; - using _database_t = Db; - using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; - using _result_type_provider = typename _policies_t::_result_type_provider; - using _parameter_tuple_t = std::tuple; - using _parameter_list_t = typename make_parameter_list_t::type; - - template - using _result_row_t = typename _result_type_provider::template _result_row_t; - using _dynamic_names_t = typename _result_type_provider::_dynamic_names_t; - using _requires_braces = std::true_type; using _name_t = typename _result_type_provider::_name_t; @@ -178,53 +174,6 @@ namespace sqlpp select_t& operator=(select_t&& r) = default; ~select_t() = default; - // PseudoTable - const _dynamic_names_t& get_dynamic_names() const - { - return static_cast(*this)._dynamic_columns._dynamic_expression_names; - } - - static constexpr size_t _get_static_no_of_parameters() - { - return _parameter_list_t::size::value; - } - - size_t _get_no_of_parameters() const - { - return _parameter_list_t::size::value; - } - - size_t get_no_of_result_columns() const - { - return _result_type_provider::static_size() + get_dynamic_names().size(); - } - - void _check_consistency() const - { -#warning check for missing terms here, and for missing tables - static_assert(not required_tables_of<_policies_t>::size::value, "one sub expression contains tables which are not in the from()"); - } - - // Execute - template - auto _run(Database& db) const - -> result_t> - { - _check_consistency(); - static_assert(_get_static_no_of_parameters() == 0, "cannot run select directly with parameters, use prepare instead"); - - return {db.select(*this), get_dynamic_names()}; - } - - // Prepare - template - auto _prepare(Database& db) const - -> prepared_select_t - { - _check_consistency(); - - return {{}, get_dynamic_names(), db.prepare_select(*this)}; - } }; namespace vendor diff --git a/include/sqlpp11/vendor/select_column_list.h b/include/sqlpp11/vendor/select_column_list.h index 89c25263..f5be996f 100644 --- a/include/sqlpp11/vendor/select_column_list.h +++ b/include/sqlpp11/vendor/select_column_list.h @@ -165,6 +165,7 @@ namespace sqlpp using _dynamic_t = select_column_list_t>; select_column_list_t& _select_column_list() { return *this; } + const select_column_list_t& _select_column_list() const { return *this; } select_column_list_t(std::tuple columns): _columns(columns) @@ -246,6 +247,50 @@ namespace sqlpp static_assert(Policies::_can_be_used_as_table::value, "statement cannot be used as table, e.g. due to missing tables"); return _table_t(static_cast(*this)).as(aliasProvider); } + const _dynamic_names_t& get_dynamic_names() const + { + return static_cast(this)->_select_column_list()._dynamic_columns._dynamic_expression_names; + } + + static constexpr size_t _get_static_no_of_parameters() + { +#warning need to fix this + return 0; + } + + size_t _get_no_of_parameters() const + { +#warning need to fix this + return 0; + } + + size_t get_no_of_result_columns() const + { + return static_size() + get_dynamic_names().size(); + } + + // Execute + template + auto _run(Db& db) const + -> result_t())), _result_row_t> + { + Policies::_check_consistency(); + static_assert(_get_static_no_of_parameters() == 0, "cannot run select directly with parameters, use prepare instead"); + + return {db.select(static_cast(*this)), get_dynamic_names()}; + } +#if 0 + + // Prepare + template + auto _prepare(Db& db) const + -> prepared_select_t + { + Policies::_check_consistency(); + + return {{}, get_dynamic_names(), db.prepare_select(*this)}; + } +#endif };