From 23d0bc91a162e6243953fce35716bbb03a882db4 Mon Sep 17 00:00:00 2001 From: rbock Date: Mon, 27 Oct 2014 07:31:37 +0100 Subject: [PATCH] Make result methods templates of their statement, not their statement's policies --- include/sqlpp11/insert.h | 4 ++-- include/sqlpp11/noop.h | 2 +- include/sqlpp11/remove.h | 4 ++-- include/sqlpp11/select_column_list.h | 6 +++--- include/sqlpp11/statement.h | 18 ++++++++++++------ include/sqlpp11/update.h | 4 ++-- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/include/sqlpp11/insert.h b/include/sqlpp11/insert.h index d6e1bc3a..4a24dcb3 100644 --- a/include/sqlpp11/insert.h +++ b/include/sqlpp11/insert.h @@ -46,10 +46,10 @@ namespace sqlpp using _traits = make_traits; struct _name_t {}; - template + template struct _result_methods_t { - using _statement_t = derived_statement_t; + using _statement_t = Statement; const _statement_t& _get_statement() const { diff --git a/include/sqlpp11/noop.h b/include/sqlpp11/noop.h index 5d6afae2..a28fcc95 100644 --- a/include/sqlpp11/noop.h +++ b/include/sqlpp11/noop.h @@ -40,7 +40,7 @@ namespace sqlpp struct _name_t {}; - template + template struct _result_methods_t {}; }; diff --git a/include/sqlpp11/remove.h b/include/sqlpp11/remove.h index c607b847..f6ab9445 100644 --- a/include/sqlpp11/remove.h +++ b/include/sqlpp11/remove.h @@ -46,10 +46,10 @@ namespace sqlpp using _traits = make_traits; struct _name_t {}; - template + template struct _result_methods_t { - using _statement_t = derived_statement_t; + using _statement_t = Statement; const _statement_t& _get_statement() const { diff --git a/include/sqlpp11/select_column_list.h b/include/sqlpp11/select_column_list.h index 0b77b021..abfe6860 100644 --- a/include/sqlpp11/select_column_list.h +++ b/include/sqlpp11/select_column_list.h @@ -235,10 +235,10 @@ namespace sqlpp }; // Result methods - template + template struct _result_methods_t { - using _statement_t = derived_statement_t; + using _statement_t = Statement; const _statement_t& _get_statement() const { @@ -277,7 +277,7 @@ namespace sqlpp template _alias_t as(const AliasProvider& aliasProvider) const { - static_assert(Policies::_can_be_used_as_table::value, "statement cannot be used as table, e.g. due to missing tables"); + static_assert(_statement_t::_can_be_used_as_table(), "statement cannot be used as table, e.g. due to missing tables"); static_assert(detail::none_t::value...>::value, "cannot use multi-columns in sub selects"); return _table_t(_get_statement()).as(aliasProvider); } diff --git a/include/sqlpp11/statement.h b/include/sqlpp11/statement.h index 0ba602f6..4092638d 100644 --- a/include/sqlpp11/statement.h +++ b/include/sqlpp11/statement.h @@ -79,18 +79,19 @@ namespace sqlpp using _result_type_provider = detail::get_last_if; - struct _result_methods_t: public _result_type_provider::template _result_methods_t + struct _result_methods_t: public _result_type_provider::template _result_methods_t<_statement_t> {}; // A select can be used as a pseudo table if // - at least one column is selected // - the select is complete (leaks no tables) - using _can_be_used_as_table = typename std::conditional< - is_select_column_list_t<_result_type_provider>::value and _required_tables::size::value == 0, - std::true_type, - std::false_type - >::type; + static constexpr bool _can_be_used_as_table() + { + return is_select_column_list_t<_result_type_provider>::value and _required_tables::size::value == 0 + ? true + : false; + } using _value_type = typename std::conditional< detail::none_t::value...>::value, @@ -173,6 +174,11 @@ namespace sqlpp return _get_static_no_of_parameters(); } + static constexpr bool _can_be_used_as_table() + { + return _policies_t::_can_be_used_as_table(); + } + static void _check_consistency() { static_assert(not required_tables_of<_policies_t>::size::value, "one sub expression requires tables which are otherwise not known in the statement"); diff --git a/include/sqlpp11/update.h b/include/sqlpp11/update.h index 492f0791..2abf12f6 100644 --- a/include/sqlpp11/update.h +++ b/include/sqlpp11/update.h @@ -46,10 +46,10 @@ namespace sqlpp using _traits = make_traits; struct _name_t {}; - template + template struct _result_methods_t { - using _statement_t = derived_statement_t; + using _statement_t = Statement; const _statement_t& _get_statement() const {