diff --git a/include/sqlpp11/detail/arg_selector.h b/include/sqlpp11/detail/arg_selector.h new file mode 100644 index 00000000..0b54676a --- /dev/null +++ b/include/sqlpp11/detail/arg_selector.h @@ -0,0 +1,49 @@ +/* + * 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 + { + static Target _(Target, Target t) { return t; } + + template + static Target _(X, Target t) { return t; } + + template + static Target _(Target t, X) { return t; } + }; + } +} + + +#endif diff --git a/include/sqlpp11/insert.h b/include/sqlpp11/insert.h index 11bda07f..18041895 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(Statement 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; 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/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; 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;