From 36afa04bcd9dbe17cf737fbd48314e36d4e94460 Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 1 Sep 2016 12:51:04 +0200 Subject: [PATCH] Adjusted insert to use wrapped asserts as failure return --- include/sqlpp11/insert_value_list.h | 49 ++++++++++++++--------------- include/sqlpp11/into.h | 37 ++++++++++++---------- tests/CMakeLists.txt | 4 +-- tests/Insert.cpp | 6 ++-- 4 files changed, 48 insertions(+), 48 deletions(-) diff --git a/include/sqlpp11/insert_value_list.h b/include/sqlpp11/insert_value_list.h index 18bfde95..5e16bfe5 100644 --- a/include/sqlpp11/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -426,6 +426,16 @@ namespace sqlpp SQLPP_PORTABLE_STATIC_ASSERT(assert_insert_values_t, "insert values required, e.g. set(...) or default_values()"); + SQLPP_PORTABLE_STATIC_ASSERT(assert_insert_columns_are_columns, "arguments for columns() must be table columns"); + template + struct check_insert_columns + { + using type = static_combined_check_t< + static_check_t::value...>::value, assert_insert_columns_are_columns>>; + }; + template + using check_insert_columns_t = typename check_insert_columns::type; + // NO INSERT COLUMNS/VALUES YET struct no_insert_value_list_t { @@ -478,32 +488,23 @@ namespace sqlpp using _database_t = typename Policies::_database_t; - // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 - // template - // using _column_check = logic::all_t::value...>; - template - struct _column_check : logic::all_t::value...> - { - }; - template - using _new_statement_t = new_statement_t; + using _new_statement_t = new_statement_t; using _consistency_check = assert_insert_values_t; - auto default_values() const -> _new_statement_t + auto default_values() const -> _new_statement_t { return {static_cast&>(*this), insert_default_values_data_t{}}; } template - auto columns(Columns... cols) const -> _new_statement_t<_column_check, column_list_t> + auto columns(Columns... cols) const + -> _new_statement_t, column_list_t> { - static_assert(logic::all_t::value...>::value, - "at least one argument is not a column in columns()"); static_assert(sizeof...(Columns), "at least one column required in columns()"); - return _columns_impl(_column_check{}, cols...); + return _columns_impl(check_insert_columns_t{}, cols...); } template @@ -511,8 +512,6 @@ namespace sqlpp -> _new_statement_t, insert_list_t> { using Check = check_insert_static_set_t; - Check{}._(); - return _set_impl(Check{}, assignments...); } @@ -522,18 +521,16 @@ namespace sqlpp insert_list_t<_database_t, Assignments...>> { using Check = check_insert_dynamic_set_t<_database_t, Assignments...>; - Check{}._(); - return _set_impl<_database_t>(Check{}, assignments...); } private: - template - auto _columns_impl(const std::false_type&, Columns... cols) const -> bad_statement; + template + auto _columns_impl(Check, Columns... cols) const -> Check; template - auto _columns_impl(const std::true_type&, Columns... cols) const - -> _new_statement_t> + auto _columns_impl(consistent_t, Columns... cols) const + -> _new_statement_t> { static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected in columns()"); @@ -548,12 +545,12 @@ namespace sqlpp return {static_cast&>(*this), column_list_data_t{cols...}}; } - template - auto _set_impl(std::false_type, Assignments... assignments) const -> bad_statement; + template + auto _set_impl(Check, Assignments... assignments) const -> Check; template - auto _set_impl(std::true_type, Assignments... assignments) const - -> _new_statement_t> + auto _set_impl(consistent_t, Assignments... assignments) const + -> _new_statement_t> { return {static_cast&>(*this), insert_list_data_t{assignments...}}; diff --git a/include/sqlpp11/into.h b/include/sqlpp11/into.h index 308dec6b..e0489443 100644 --- a/include/sqlpp11/into.h +++ b/include/sqlpp11/into.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,13 +27,13 @@ #ifndef SQLPP_INTO_H #define SQLPP_INTO_H -#include -#include #include +#include #include #include #include -#include +#include +#include namespace sqlpp { @@ -88,8 +88,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 template - _base_t(Args&&... args) - : into{std::forward(args)...} + _base_t(Args&&... args) : into{std::forward(args)...} { } @@ -115,6 +114,15 @@ namespace sqlpp SQLPP_PORTABLE_STATIC_ASSERT(assert_into_t, "into() required"); + SQLPP_PORTABLE_STATIC_ASSERT(assert_into_arg_is_table, "argument for into() must be a table"); + template + struct check_into + { + using type = static_combined_check_t::value, assert_into_arg_is_table>>; + }; + template + using check_into_t = typename check_into>::type; + // NO INTO YET struct no_into_t { @@ -155,28 +163,23 @@ 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 = assert_into_t; template - auto into(Table table) const -> _new_statement_t<_check, into_t> + auto into(Table table) const -> _new_statement_t, into_t> { - static_assert(_check
::value, "argument is not a raw table in into()"); - return _into_impl(_check
{}, table); + return _into_impl(check_into_t
{}, table); } private: - template - auto _into_impl(const std::false_type&, Table table) const -> bad_statement; + template + auto _into_impl(Check, Table table) const -> Check; template - auto _into_impl(const std::true_type&, Table table) const - -> _new_statement_t> + auto _into_impl(consistent_t, Table table) const -> _new_statement_t> { static_assert(required_tables_of>::size::value == 0, "argument depends on another table in into()"); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 57887c34..032bf09a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -34,10 +34,10 @@ set(test_names #CustomQuery #DateTime #Interpret - #Insert + Insert #Remove #Update - Select + #Select #SelectType #Function #Prepared diff --git a/tests/Insert.cpp b/tests/Insert.cpp index 0635f564..0c6e61b7 100644 --- a/tests/Insert.cpp +++ b/tests/Insert.cpp @@ -23,12 +23,12 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "Sample.h" #include "MockDb.h" +#include "Sample.h" #include "is_regular.h" -#include -#include #include +#include +#include int Insert(int, char* []) {