/* * 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_SELECT_EXPRESSION_LIST_H #define SQLPP_SELECT_EXPRESSION_LIST_H #include #include #include #include #include #include #include #include namespace sqlpp { namespace detail { template void serialize_select(std::ostream& os, Db& db, const Select& select) { os << "SELECT "; select._flags.serialize(os, db); select._expression_list.serialize(os, db); select._from.serialize(os, db); select._where.serialize(os, db); select._group_by.serialize(os, db); select._having.serialize(os, db); select._order_by.serialize(os, db); select._limit.serialize(os, db); select._offset.serialize(os, db); }; template struct get_first_argument { using type = T; }; } template struct select_expression_list_t> { // check for at least one select expression static_assert(sizeof...(NamedExpr), "at least one select expression required"); // check for duplicate select expressions static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected"); // check for invalid select expressions template struct is_valid_expression_t: public std::integral_constant::value or is_multi_column_t::value> {}; using _valid_expressions = typename detail::make_set_if::type; static_assert(_valid_expressions::size::value == sizeof...(NamedExpr), "at least one argument is not a named expression"); // check for duplicate select expression names static_assert(not detail::has_duplicates...>::value, "at least one duplicate name detected"); // declare this to be a select expression using _is_select_expression_list = tag_yes; // provide type information for sub-selects that are used as expressions struct _column_type {}; struct _value_type: std::conditional::type::_value_type, no_value_t>::type { using _is_expression = typename std::conditional::type; using _is_named_expression = typename std::conditional::type; using _is_alias = tag_no; }; struct _no_name_t {}; using _name_t = typename std::conditional::type::_name_t, _no_name_t>::type; template struct _no_member_t {}; template using _member_t = typename std::conditional::type::template _member_t, _no_member_t>::type; template void serialize(std::ostream& os, Db& db) const { detail::serialize_tuple(os, db, _expressions, ','); } std::tuple _expressions; }; } #endif