From 637e0ad4d97e07db5c76798128ba8707b517120c Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 1 Sep 2016 18:22:19 +0200 Subject: [PATCH] Better failure return types for update and remove --- include/sqlpp11/select_pseudo_table.h | 3 +- include/sqlpp11/single_table.h | 41 ++++++++++++--------- include/sqlpp11/update_list.h | 14 +++---- include/sqlpp11/using.h | 53 ++++++++++++++------------- tests/CMakeLists.txt | 4 +- 5 files changed, 59 insertions(+), 56 deletions(-) diff --git a/include/sqlpp11/select_pseudo_table.h b/include/sqlpp11/select_pseudo_table.h index 196c5e10..679019e2 100644 --- a/include/sqlpp11/select_pseudo_table.h +++ b/include/sqlpp11/select_pseudo_table.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -28,6 +28,7 @@ #define SQLPP_SELECT_PSEUDO_TABLE_H #include +#include namespace sqlpp { diff --git a/include/sqlpp11/single_table.h b/include/sqlpp11/single_table.h index 1823346d..ee16289e 100644 --- a/include/sqlpp11/single_table.h +++ b/include/sqlpp11/single_table.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -27,12 +27,12 @@ #ifndef SQLPP_SINGLE_TABLE_H #define SQLPP_SINGLE_TABLE_H -#include #include -#include -#include -#include #include +#include +#include +#include +#include namespace sqlpp { @@ -90,8 +90,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 template - _base_t(Args&&... args) - : from{std::forward(args)...} + _base_t(Args&&... args) : from{std::forward(args)...} { } @@ -115,7 +114,16 @@ namespace sqlpp }; }; - // NO INTO YET + SQLPP_PORTABLE_STATIC_ASSERT(assert_update_table_arg_is_table_t, "argument for update() must be a table"); + template + struct check_update_table + { + using type = static_combined_check_t::value, assert_update_table_arg_is_table_t>>; + }; + template + using check_update_table_t = typename check_update_table::type; + + // NO TABLE YET struct no_single_table_t { using _traits = make_traits; @@ -154,28 +162,25 @@ namespace sqlpp } using _database_t = typename Policies::_database_t; - template - using _check = logic::all_t::value>; template - using _new_statement_t = new_statement_t; + using _new_statement_t = new_statement_t; using _consistency_check = consistent_t; template - auto single_table(Table table) const -> _new_statement_t<_check
, single_table_t> + auto single_table(Table table) const -> _new_statement_t, single_table_t> { - static_assert(_check
::value, "argument is not a table in single_table()"); - return _single_table_impl(_check
{}, table); + return _single_table_impl(check_update_table_t
{}, table); } private: - template - auto _single_table_impl(const std::false_type&, Table table) const -> bad_statement; + template + auto _single_table_impl(Check, Table table) const -> Check; template - auto _single_table_impl(const std::true_type&, Table table) const - -> _new_statement_t> + auto _single_table_impl(consistent_t, Table table) const + -> _new_statement_t> { static_assert(required_tables_of>::size::value == 0, "argument depends on another table in single_table()"); diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index 40610f12..63e19af9 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -250,7 +250,7 @@ namespace sqlpp using _database_t = typename Policies::_database_t; template - using _new_statement_t = new_statement_t; + using _new_statement_t = new_statement_t; using _consistency_check = assert_update_assignments_t; @@ -259,8 +259,6 @@ namespace sqlpp -> _new_statement_t, update_list_t> { using Check = check_update_static_set_t; - Check{}._(); - return _set_impl(Check{}, assignments...); } @@ -270,18 +268,16 @@ namespace sqlpp update_list_t<_database_t, Assignments...>> { using Check = check_update_dynamic_set_t<_database_t, Assignments...>; - Check{}._(); - return _set_impl<_database_t>(Check{}, assignments...); } private: - template - auto _set_impl(const std::false_type&, Assignments... assignments) const -> bad_statement; + template + auto _set_impl(Check, Assignments... assignments) const -> Check; template - auto _set_impl(const std::true_type&, Assignments... assignments) const - -> _new_statement_t> + auto _set_impl(consistent_t, Assignments... assignments) const + -> _new_statement_t> { return {static_cast&>(*this), update_list_data_t{assignments...}}; diff --git a/include/sqlpp11/using.h b/include/sqlpp11/using.h index 23090f57..e09c5f4b 100644 --- a/include/sqlpp11/using.h +++ b/include/sqlpp11/using.h @@ -135,6 +135,16 @@ namespace sqlpp }; }; + SQLPP_PORTABLE_STATIC_ASSERT(assert_using_args_are_tables_t, "arguments for using() must be tables"); + template + struct check_using + { + using type = static_combined_check_t< + static_check_t::value...>::value, assert_using_args_are_tables_t>>; + }; + template + using check_using_t = typename check_using::type; + // NO USING YET struct no_using_t { @@ -187,52 +197,43 @@ namespace sqlpp using _database_t = typename Policies::_database_t; - // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 - // template - // using _check = logic::all_t::value...>; - template - struct _check : logic::all_t::value...> - { - }; - template - using _new_statement_t = new_statement_t; + using _new_statement_t = new_statement_t; using _consistency_check = consistent_t; - template - auto using_(Args... args) const -> _new_statement_t<_check, using_t> + template + auto using_(Tables... tables) const -> _new_statement_t, using_t> { - static_assert(not detail::has_duplicates::value, + static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected in using()"); - static_assert(sizeof...(Args), "at least one table required in using()"); - static_assert(_check::value, "at least one argument is not an table in using()"); + static_assert(sizeof...(Tables), "at least one table required in using()"); - return {_using_impl(_check{}, args...)}; + return {_using_impl(check_using_t{}, tables...)}; } - template - auto dynamic_using(Args... args) const -> _new_statement_t<_check, using_t<_database_t, Args...>> + template + auto dynamic_using(Tables... tables) const + -> _new_statement_t, using_t<_database_t, Tables...>> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_using must not be called in a static statement"); - static_assert(_check::value, "at least one argument is not an table in using()"); - return {_using_impl<_database_t>(_check{}, args...)}; + return {_using_impl<_database_t>(check_using_t{}, tables...)}; } private: - template - auto _using_impl(const std::false_type&, Args... args) const -> bad_statement; + template + auto _using_impl(Check, Tables... tables) const -> Check; - template - auto _using_impl(const std::true_type&, Args... args) const - -> _new_statement_t> + template + auto _using_impl(consistent_t, Tables... tables) const + -> _new_statement_t> { - static_assert(not detail::has_duplicates::value, + static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected in using()"); - return {static_cast&>(*this), using_data_t{args...}}; + return {static_cast&>(*this), using_data_t{tables...}}; } }; }; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 032bf09a..39fbad16 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -34,9 +34,9 @@ set(test_names #CustomQuery #DateTime #Interpret - Insert + #Insert #Remove - #Update + Update #Select #SelectType #Function