From 1ffa6e25baffae1a3becbe541c447dd3120cd627 Mon Sep 17 00:00:00 2001 From: rbock Date: Wed, 26 Mar 2014 21:02:22 +0100 Subject: [PATCH 1/4] Added an argument selector It returns the "correct" argument out of two. --- include/sqlpp11/detail/arg_selector.h | 47 +++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 include/sqlpp11/detail/arg_selector.h diff --git a/include/sqlpp11/detail/arg_selector.h b/include/sqlpp11/detail/arg_selector.h new file mode 100644 index 00000000..5332f33f --- /dev/null +++ b/include/sqlpp11/detail/arg_selector.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2013, Roland Bock + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SQLPP_DETAIL_ARG_SELECTOR_H +#define SQLPP_DETAIL_ARG_SELECTOR_H + +namespace sqlpp +{ + namespace detail + { + template + struct arg_selector + { + template + static Target _(X, Target t) { return t; } + + template + static Target _(Target t, X) { return t; } + }; + } +} + + +#endif From 6c4520a632a38bc4c0bb8baea7d38e6e50ff7e88 Mon Sep 17 00:00:00 2001 From: rbock Date: Wed, 26 Mar 2014 21:03:29 +0100 Subject: [PATCH 2/4] Using detail::arg_select to reduce number of constructors --- include/sqlpp11/insert.h | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/include/sqlpp11/insert.h b/include/sqlpp11/insert.h index 11bda07f..67649f3f 100644 --- a/include/sqlpp11/insert.h +++ b/include/sqlpp11/insert.h @@ -35,6 +35,7 @@ #include #include #include +#include namespace sqlpp { @@ -67,16 +68,10 @@ namespace sqlpp insert_t() {} - template - insert_t(X x, Table table): - _table(table), - _insert_value_list(x._insert_value_list) - {} - - template - insert_t(X x, InsertValueList insert_value_list): - _table(x._table), - _insert_value_list(insert_value_list) + template + insert_t(Select s, T t): + _table(detail::arg_selector::_(s._table, t)), + _insert_value_list(detail::arg_selector::_(s._insert_value_list, t)) {} insert_t(const insert_t&) = default; From 1a39d31b3e512a91828fb7514ff0836544dfdcd4 Mon Sep 17 00:00:00 2001 From: rbock Date: Wed, 26 Mar 2014 21:11:40 +0100 Subject: [PATCH 3/4] Using arg_selector for select --- include/sqlpp11/insert.h | 4 +- include/sqlpp11/select.h | 128 ++++----------------------------------- 2 files changed, 15 insertions(+), 117 deletions(-) diff --git a/include/sqlpp11/insert.h b/include/sqlpp11/insert.h index 67649f3f..18041895 100644 --- a/include/sqlpp11/insert.h +++ b/include/sqlpp11/insert.h @@ -68,8 +68,8 @@ namespace sqlpp insert_t() {} - template - insert_t(Select s, T t): + template + insert_t(Statement s, T t): _table(detail::arg_selector
::_(s._table, t)), _insert_value_list(detail::arg_selector::_(s._insert_value_list, t)) {} diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 009d5202..51c9932a 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -47,6 +47,7 @@ #include #include +#include namespace sqlpp { @@ -80,6 +81,7 @@ namespace sqlpp typename Limit = vendor::no_limit_t, typename Offset = vendor::no_offset_t > +#warning: idea: require from() for anything AFTER FROM, including dynamic columns. Then just check for from() in the run methods struct select_t: public detail::select_helper_t::_value_type::template expression_operators> { using _database_t = Database; @@ -113,121 +115,17 @@ namespace sqlpp select_t() {} - template - select_t(X x, FlagList flag_list): - _flag_list(flag_list), - _column_list(x._column_list), - _from(x._from), - _where(x._where), - _group_by(x._group_by), - _having(x._having), - _order_by(x._order_by), - _limit(x._limit), - _offset(x._offset) - {} - - template - select_t(X x, ColumnList column_list): - _flag_list(x._flag_list), - _column_list(column_list), - _from(x._from), - _where(x._where), - _group_by(x._group_by), - _having(x._having), - _order_by(x._order_by), - _limit(x._limit), - _offset(x._offset) - {} - - template - select_t(X x, From from): - _flag_list(x._flag_list), - _column_list(x._column_list), - _from(from), - _where(x._where), - _group_by(x._group_by), - _having(x._having), - _order_by(x._order_by), - _limit(x._limit), - _offset(x._offset) - {} - - template - select_t(X x, Where where): - _flag_list(x._flag_list), - _column_list(x._column_list), - _from(x._from), - _where(where), - _group_by(x._group_by), - _having(x._having), - _order_by(x._order_by), - _limit(x._limit), - _offset(x._offset) - {} - - template - select_t(X x, GroupBy group_by): - _flag_list(x._flag_list), - _column_list(x._column_list), - _from(x._from), - _where(x._where), - _group_by(group_by), - _having(x._having), - _order_by(x._order_by), - _limit(x._limit), - _offset(x._offset) - {} - - template - select_t(X x, Having having): - _flag_list(x._flag_list), - _column_list(x._column_list), - _from(x._from), - _where(x._where), - _group_by(x._group_by), - _having(having), - _order_by(x._order_by), - _limit(x._limit), - _offset(x._offset) - {} - - template - select_t(X x, OrderBy order_by): - _flag_list(x._flag_list), - _column_list(x._column_list), - _from(x._from), - _where(x._where), - _group_by(x._group_by), - _having(x._having), - _order_by(order_by), - _limit(x._limit), - _offset(x._offset) - {} - - template - select_t(X x, Limit limit): - _flag_list(x._flag_list), - _column_list(x._column_list), - _from(x._from), - _where(x._where), - _group_by(x._group_by), - _having(x._having), - _order_by(x._order_by), - _limit(limit), - _offset(x._offset) - {} - - template - select_t(X x, Offset offset): - _flag_list(x._flag_list), - _column_list(x._column_list), - _from(x._from), - _where(x._where), - _group_by(x._group_by), - _having(x._having), - _order_by(x._order_by), - _limit(x._limit), - _offset(offset) + template + select_t(Statement s, T t): + _flag_list(detail::arg_selector::_(s._flag_list, t)), + _column_list(detail::arg_selector::_(s._column_list, t)), + _from(detail::arg_selector::_(s._from, t)), + _where(detail::arg_selector::_(s._where, t)), + _group_by(detail::arg_selector::_(s._group_by, t)), + _having(detail::arg_selector::_(s._having, t)), + _order_by(detail::arg_selector::_(s._order_by, t)), + _limit(detail::arg_selector::_(s._limit, t)), + _offset(detail::arg_selector::_(s._offset, t)) {} select_t(const select_t& r) = default; From 1a347048df3ac7c4e012d70f0e60f384ce51aae1 Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 27 Mar 2014 08:37:05 +0100 Subject: [PATCH 4/4] Migrated remove and update to using arg_selector --- include/sqlpp11/detail/arg_selector.h | 2 ++ include/sqlpp11/remove.h | 25 ++++++------------------- include/sqlpp11/update.h | 27 +++++++-------------------- 3 files changed, 15 insertions(+), 39 deletions(-) diff --git a/include/sqlpp11/detail/arg_selector.h b/include/sqlpp11/detail/arg_selector.h index 5332f33f..0b54676a 100644 --- a/include/sqlpp11/detail/arg_selector.h +++ b/include/sqlpp11/detail/arg_selector.h @@ -34,6 +34,8 @@ namespace sqlpp template struct arg_selector { + static Target _(Target, Target t) { return t; } + template static Target _(X, Target t) { return t; } diff --git a/include/sqlpp11/remove.h b/include/sqlpp11/remove.h index 557b0f6d..5392885e 100644 --- a/include/sqlpp11/remove.h +++ b/include/sqlpp11/remove.h @@ -35,6 +35,7 @@ #include #include #include +#include namespace sqlpp { @@ -75,25 +76,11 @@ namespace sqlpp remove_t() {} - template - remove_t(X x, Table table): - _table(table), - _using(x._using), - _where(x._where) - {} - - template - remove_t(X x, Using using_): - _table(x._table), - _using(using_), - _where(x._where) - {} - - template - remove_t(X x, Where where): - _table(x._table), - _using(x._using), - _where(where) + template + remove_t(Statement s, T t): + _table(detail::arg_selector
::_(s._table, t)), + _using(detail::arg_selector::_(s._using, t)), + _where(detail::arg_selector::_(s._where, t)) {} remove_t(const remove_t&) = default; diff --git a/include/sqlpp11/update.h b/include/sqlpp11/update.h index 5c8be581..39733d9a 100644 --- a/include/sqlpp11/update.h +++ b/include/sqlpp11/update.h @@ -35,6 +35,7 @@ #include #include #include +#include namespace sqlpp { @@ -75,29 +76,15 @@ namespace sqlpp using _parameter_tuple_t = std::tuple; using _parameter_list_t = typename make_parameter_list_t::type; + // Constructors update_t() {} - // Constructors - template - update_t(X x, Table table): - _table(table), - _update_list(x._update_list), - _where(x._where) - {} - - template - update_t(X x, UpdateList update_list): - _table(x._table), - _update_list(update_list), - _where(x._where) - {} - - template - update_t(X x, Where where): - _table(x._table), - _update_list(x._update_list), - _where(where) + template + update_t(Statement s, T t): + _table(detail::arg_selector
::_(s._table, t)), + _update_list(detail::arg_selector::_(s._update_list, t)), + _where(detail::arg_selector::_(s._where, t)) {} update_t(const update_t&) = default;