/* * Copyright (c) 2013-2014, 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 #include #include #include #include #include namespace sqlpp { struct remove_name_t {}; struct remove_t: public statement_name_t { using _traits = make_traits; struct _name_t {}; template struct _result_methods_t { using _statement_t = Statement; const _statement_t& _get_statement() const { return static_cast(*this); } template auto _run(Db& db) const -> decltype(db.remove(this->_get_statement())) { _statement_t::_check_consistency(); static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run remove directly with parameters, use prepare instead"); return db.remove(_get_statement()); } template auto _prepare(Db& db) const -> prepared_remove_t { _statement_t::_check_consistency(); return {{}, db.prepare_remove(_get_statement())}; } }; }; template struct serializer_t { using T = remove_name_t; static Context& _(const T& t, Context& context) { context << "DELETE"; return context; } }; template using blank_remove_t = statement_t >; inline auto remove() -> blank_remove_t { return { blank_remove_t() }; } template auto remove_from(Table table) -> decltype(blank_remove_t().from(table)) { return { blank_remove_t().from(table) }; } template auto dynamic_remove(const Database&) -> decltype(blank_remove_t()) { static_assert(std::is_base_of::value, "Invalid database parameter"); return { blank_remove_t() }; } template auto dynamic_remove_from(const Database&, Table table) -> decltype(blank_remove_t().from(table)) { static_assert(std::is_base_of::value, "Invalid database parameter"); return { blank_remove_t().from(table) }; } } #endif