From 69337fd7ca1faa322bc94e5deafc1240fee9755d Mon Sep 17 00:00:00 2001 From: rbock Date: Mon, 27 Oct 2014 17:36:33 +0100 Subject: [PATCH] Added first draft of custom query --- include/sqlpp11/custom_query.h | 78 ++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 include/sqlpp11/custom_query.h diff --git a/include/sqlpp11/custom_query.h b/include/sqlpp11/custom_query.h new file mode 100644 index 00000000..4af3cf71 --- /dev/null +++ b/include/sqlpp11/custom_query.h @@ -0,0 +1,78 @@ +/* + * 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_CUSTOM_QUERY_H +#define SQLPP_CUSTOM_QUERY_H + +#include + +namespace sqlpp +{ + template + struct custom_query_t: + public FirstPart::_result_type_provider::template _result_methods_t + { + custom_query_t(Expressions... expressions): + _expressions(expressions...) + {} + + custom_query_t(const custom_query_t&) = default; + custom_query_t(custom_query_t&&) = default; + custom_query_t& operator=(const custom_query_t&) = default; + custom_query_t& operator=(custom_query_t&&) = default; + ~custom_query_t() = default; + + std::tuple _parts; + }; + + template + struct serializer_t> + { + using T = custom_query_t; + + static Context& _(const T& t, Context& context) + { + interpret_tuple(t._parts, " ", context); + return context; + } + }; + + template + auto custom_query(Parts... parts) + -> statement_t + { + return statement_t(parts...); + } + + template + auto dynamic_custom_query(const Database&, Parts...) + -> statement_t + { + static_assert(std::is_base_of::value, "Invalid database parameter"); + return { }; + } +} +#endif