/* * 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_REMOVE_H #define SQLPP_REMOVE_H #include #include #include #include #include namespace sqlpp { template< typename Table, typename Using = noop, typename Where = noop > struct remove_t; template< typename Table, typename Using, typename Where > struct remove_t { static_assert(is_noop::value or is_table_t
::value, "invalid 'Table' argument"); static_assert(is_noop::value or is_using_t::value, "invalid 'Using' argument"); static_assert(is_noop::value or is_where_t::value, "invalid 'Where' argument"); template using add_using_t = remove_t::type...>, Where>; template using add_where_t = remove_t::type>>; template add_using_t using_(Tab&&... tab) { static_assert(std::is_same::value, "cannot call using() twice"); static_assert(std::is_same::value, "cannot call using() after where()"); return { _table, {{std::forward(tab)...}}, _where }; } template add_where_t where(Expr&& where) { static_assert(std::is_same::value, "cannot call where() twice"); return { _table, _using, {std::forward(where)}, }; } template const remove_t& serialize(std::ostream& os, Db& db) const { os << "DELETE FROM "; _table.serialize(os, db); _using.serialize(os, db); _where.serialize(os, db); return *this; } template remove_t& serialize(std::ostream& os, Db& db) { static_cast(this)->serialize(os, db); return *this; } template std::size_t run(Db& db) const { std::ostringstream oss; serialize(oss, db); return db.remove(oss.str()); } Table _table; Using _using; Where _where; }; template constexpr remove_t::type> remove_from(Table&& table) { return {std::forward
(table)}; } } #endif