From e03366202d876de4a478378d2aa3a3cfbdcb9af7 Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 26 Jun 2014 08:39:08 +0200 Subject: [PATCH] Fixed a bunch of warnings --- include/sqlpp11/basic_expression_operators.h | 1 - include/sqlpp11/integral.h | 1 + include/sqlpp11/simple_column.h | 1 - include/sqlpp11/single_table.h | 4 +- include/sqlpp11/statement.h | 3 - include/sqlpp11/update_list.h | 58 ++++++++++---------- tests/UpdateTest.cpp | 3 +- 7 files changed, 34 insertions(+), 37 deletions(-) diff --git a/include/sqlpp11/basic_expression_operators.h b/include/sqlpp11/basic_expression_operators.h index 25702f6e..deeb5342 100644 --- a/include/sqlpp11/basic_expression_operators.h +++ b/include/sqlpp11/basic_expression_operators.h @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include diff --git a/include/sqlpp11/integral.h b/include/sqlpp11/integral.h index 2b52fb6e..791df00c 100644 --- a/include/sqlpp11/integral.h +++ b/include/sqlpp11/integral.h @@ -33,6 +33,7 @@ #include #include #include +#include namespace sqlpp { diff --git a/include/sqlpp11/simple_column.h b/include/sqlpp11/simple_column.h index 0f05befe..e6b829a0 100644 --- a/include/sqlpp11/simple_column.h +++ b/include/sqlpp11/simple_column.h @@ -56,7 +56,6 @@ namespace sqlpp template simple_column_t simple_column(Column c) { -#warning: make sure that there are no parameters in Column return {c}; } } diff --git a/include/sqlpp11/single_table.h b/include/sqlpp11/single_table.h index 12cf98b5..8690be61 100644 --- a/include/sqlpp11/single_table.h +++ b/include/sqlpp11/single_table.h @@ -140,8 +140,8 @@ namespace sqlpp template using _new_statement_t = typename Policies::template _new_statement_t; - static void _check_consistency() {} -#warning: remove can operate on several tables at once, so it should not use single_table anyway + static void _check_consistency() {} + template auto from(Args... args) -> _new_statement_t> diff --git a/include/sqlpp11/statement.h b/include/sqlpp11/statement.h index 09497801..416f1654 100644 --- a/include/sqlpp11/statement.h +++ b/include/sqlpp11/statement.h @@ -48,7 +48,6 @@ namespace sqlpp template struct statement_policies_t { -#warning need to check policies' signature, e.g. a _data_t in _member_t template using _database_t = Db; using _statement_t = statement_t; @@ -166,8 +165,6 @@ namespace sqlpp static void _check_consistency() { - // FIXME: Check each "methods" or each member... -#warning check for missing terms here, and for missing tables static_assert(not required_tables_of<_policies_t>::size::value, "one sub expression requires tables which are otherwise not known in the statement"); using swallow = int[]; diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index 882300be..1f058a1a 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -60,23 +60,6 @@ namespace sqlpp using _recursive_traits = make_recursive_traits; using _is_dynamic = is_database; - static_assert(_is_dynamic::value or sizeof...(Assignments), "at least one assignment expression required in set()"); - - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in set()"); - - static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an assignment in set()"); - - static_assert(::sqlpp::detail::none_t::value...>::value, "at least one assignment is prohibited by its column definition in set()"); - -#warning reactivate tests - /* - using _column_table_set = typename ::sqlpp::detail::make_joined_set::type; - using _value_table_set = typename ::sqlpp::detail::make_joined_set::type; - using _table_set = typename ::sqlpp::detail::make_joined_set<_column_table_set, _value_table_set>::type; - static_assert(sizeof...(Assignments) ? (_column_table_set::size::value == 1) : true, "set() contains assignments for tables from several columns"); - static_assert(::sqlpp::detail::is_subset_of<_value_table_set, _column_table_set>::value, "set() contains values from foreign tables"); - */ - // Data using _data_t = update_list_data_t; @@ -95,13 +78,14 @@ namespace sqlpp { static_assert(_is_dynamic::value, "add must not be called for static from()"); static_assert(is_assignment_t::value, "invalid assignment argument in add()"); + using _assigned_columns = detail::make_type_set_t; + static_assert(not detail::is_element_of::value, "Must not assign value to column twice"); static_assert(sqlpp::detail::not_t::value, "add() argument must not be updated"); static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "assignment uses tables unknown to this statement in add()"); using ok = ::sqlpp::detail::all_t< _is_dynamic::value, - is_assignment_t::value, - not must_not_update_t::value>; + is_assignment_t::value>; _add_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert } @@ -185,19 +169,37 @@ namespace sqlpp static void _check_consistency() {} - template - auto set(Args... args) - -> _new_statement_t> + template + auto set(Assignments... assignments) + -> _new_statement_t> { - return { *static_cast(this), update_list_data_t{args...} }; + static_assert(sizeof...(Assignments), "at least one assignment expression required in set()"); + return _set_impl(assignments...); } - template - auto dynamic_set(Args... args) - -> _new_statement_t> + template + auto dynamic_set(Assignments... assignments) + -> _new_statement_t> { - static_assert(not std::is_same<_database_t, void>::value, "dynamic_set must not be called in a static statement"); - return { *static_cast(this), update_list_data_t<_database_t, Args...>{args...} }; + static_assert(not std::is_same<_database_t, void>::value, "dynamic_set() must not be called in a static statement"); + return _set_impl<_database_t>(assignments...); + } + + private: + template + auto _set_impl(Assignments... assignments) + -> _new_statement_t> + { + static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in set()"); + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an assignment in set()"); + static_assert(::sqlpp::detail::none_t::value...>::value, "at least one assignment is prohibited by its column definition in set()"); + + using _column_table_set = typename ::sqlpp::detail::make_joined_set...>::type; + using _value_table_set = typename ::sqlpp::detail::make_joined_set...>::type; + static_assert(sizeof...(Assignments) ? (_column_table_set::size::value == 1) : true, "set() contains assignments for columns from more than one table"); + static_assert(::sqlpp::detail::is_subset_of<_value_table_set, _column_table_set>::value, "set() contains values from foreign tables"); + + return { *static_cast(this), update_list_data_t{assignments...} }; } }; }; diff --git a/tests/UpdateTest.cpp b/tests/UpdateTest.cpp index 364d8a33..6f7a0c0b 100644 --- a/tests/UpdateTest.cpp +++ b/tests/UpdateTest.cpp @@ -61,8 +61,7 @@ int main() serialize(update(t).set(t.gamma = false).where(t.beta != "transparent"), printer).str(); serialize(update(t).set(t.beta = "opaque").where(t.beta != t.beta), printer).str(); auto u = dynamic_update(db, t).dynamic_set(t.gamma = false).dynamic_where(); -#warning: This should fail since gamma is set already - u.assignments.add(t.gamma = false); + u.assignments.add(t.beta = "cannot update gamma a second time"); u.where.add(t.gamma != false); printer.reset(); std::cerr << serialize(u, printer).str() << std::endl;