From 18d244dd9f26e8306f9e6563fd9a92c468758de3 Mon Sep 17 00:00:00 2001 From: rbock Date: Wed, 9 Apr 2014 07:25:24 +0200 Subject: [PATCH] Moved from-methods to from-classes --- include/sqlpp11/select.h | 24 +------------------- include/sqlpp11/vendor/from.h | 40 +++++++++++++++++++++++++++++----- include/sqlpp11/vendor/where.h | 1 + 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index e950e84f..1523bf7c 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -131,6 +131,7 @@ namespace sqlpp > struct select_t: public detail::select_helper_t::_value_type::template expression_operators>, FlagList::template _methods_t>, + From::template _methods_t>, Where::template _methods_t>, GroupBy::template _methods_t>, Having::template _methods_t>, @@ -206,21 +207,6 @@ namespace sqlpp return { *this, vendor::select_column_list_t<_database_t, Args...>{args...} }; } - template - auto from(Args... args) - -> _policies_update_t> - { - return { *this, vendor::from_t{args...} }; - } - - template - auto dynamic_from(Args... args) - -> _policies_update_t> - { - static_assert(not std::is_same<_database_t, void>::value, "dynamic_from must not be called in a static statement"); - return { *this, vendor::from_t<_database_t, Args...>{args...} }; - } - // value adding methods template void add_column(Args... args) @@ -230,14 +216,6 @@ namespace sqlpp return _column_list.add_column(*this, args...); } - template - void add_from(Args... args) - { - static_assert(is_from_t::value, "cannot call add_from() before dynamic_from()"); - static_assert(is_dynamic_t::value, "cannot call add_using() before dynamic_from()"); - return _from.add_from(*this, args...); - } - // PseudoTable template struct _pseudo_table_t diff --git a/include/sqlpp11/vendor/from.h b/include/sqlpp11/vendor/from.h index e703b2b3..72a66980 100644 --- a/include/sqlpp11/vendor/from.h +++ b/include/sqlpp11/vendor/from.h @@ -64,13 +64,17 @@ namespace sqlpp from_t& operator=(from_t&&) = default; ~from_t() = default; - template - void add_from(const Select&, Table table) + template + struct _methods_t { - static_assert(_is_dynamic::value, "add_from can only be called for dynamic_from"); - static_assert(is_table_t::value, "from arguments require to be tables or joins"); - _dynamic_tables.emplace_back(table); - } + template + void add_from(Table table) + { + static_assert(is_table_t
::value, "invalid expression argument in add_from()"); +#warning: Need to dispatch to actual add method to prevent error messages from being generated + return static_cast(this)->_from._dynamic_tables.emplace_back(table); + } + }; std::tuple _tables; vendor::interpretable_list_t _dynamic_tables; @@ -79,6 +83,30 @@ namespace sqlpp struct no_from_t { using _is_noop = std::true_type; + using _table_set = ::sqlpp::detail::type_set<>; + + template + struct _methods_t + { + using _database_t = typename Policies::_database_t; + template + using _new_select_t = typename Policies::template _policies_update_t; + + template + auto from(Args... args) + -> _new_select_t> + { + return { *static_cast(this), from_t{args...} }; + } + + template + auto dynamic_from(Args... args) + -> _new_select_t> + { + static_assert(not std::is_same<_database_t, void>::value, "dynamic_from must not be called in a static statement"); + return { *static_cast(this), vendor::from_t<_database_t, Args...>{args...} }; + } + }; }; // Interpreters diff --git a/include/sqlpp11/vendor/where.h b/include/sqlpp11/vendor/where.h index 55f7a150..d7ddabeb 100644 --- a/include/sqlpp11/vendor/where.h +++ b/include/sqlpp11/vendor/where.h @@ -70,6 +70,7 @@ namespace sqlpp template void add_where(Expression expression) { + static_assert(_is_dynamic::value, "add_where can only be called for dynamic_where"); static_assert(is_expression_t::value, "invalid expression argument in add_where()"); #warning: Need to dispatch to actual add method to prevent error messages from being generated return static_cast(this)->_where._dynamic_expressions.emplace_back(expression);