diff --git a/include/sqlpp11/boolean.h b/include/sqlpp11/boolean.h index 00ffbc3a..8358da7f 100644 --- a/include/sqlpp11/boolean.h +++ b/include/sqlpp11/boolean.h @@ -63,6 +63,7 @@ namespace sqlpp using _is_boolean = std::true_type; using _is_value = std::true_type; using _is_expression = std::true_type; + using _cpp_value_type = bool; struct plus_ { diff --git a/include/sqlpp11/expression.h b/include/sqlpp11/expression.h index 9a5b2288..261fb2fa 100644 --- a/include/sqlpp11/expression.h +++ b/include/sqlpp11/expression.h @@ -40,6 +40,7 @@ namespace sqlpp using _is_assignment = std::true_type; using column_type = Lhs; using value_type = Rhs; + using _parameters = std::tuple; template void serialize(std::ostream& os, Db& db) const @@ -64,6 +65,7 @@ namespace sqlpp struct equal_t: public ValueType::template operators> { using _value_type = ValueType; + using _parameters = std::tuple; template equal_t(L&& l, R&& r): @@ -103,6 +105,7 @@ namespace sqlpp struct not_equal_t: public ValueType::template operators> { using _value_type = ValueType; + using _parameters = std::tuple; template not_equal_t(L&& l, R&& r): @@ -142,10 +145,10 @@ namespace sqlpp struct not_t: public ValueType::template operators> { using _value_type = ValueType; + using _parameters = std::tuple; - template - not_t(L&& l): - _lhs(std::forward(l)) + not_t(Lhs l): + _lhs(l) {} not_t(const not_t&) = default; @@ -179,6 +182,7 @@ namespace sqlpp struct binary_expression_t: public O::_value_type::template operators> { using _value_type = typename O::_value_type; + using _parameters = std::tuple; binary_expression_t(Lhs&& l, Rhs&& r): _lhs(std::move(l)), diff --git a/include/sqlpp11/floating_point.h b/include/sqlpp11/floating_point.h index 65215ac5..eb030ee9 100644 --- a/include/sqlpp11/floating_point.h +++ b/include/sqlpp11/floating_point.h @@ -46,6 +46,7 @@ namespace sqlpp using _is_floating_point = std::true_type; using _is_value = std::true_type; using _is_expression = std::true_type; + using _cpp_value_type = double; template struct _result_entry_t diff --git a/include/sqlpp11/functions.h b/include/sqlpp11/functions.h index 54d49b3a..bdd45294 100644 --- a/include/sqlpp11/functions.h +++ b/include/sqlpp11/functions.h @@ -28,6 +28,8 @@ #define SQLPP_FUNCTIONS_H #include +#include +#include #include #include #include diff --git a/include/sqlpp11/integral.h b/include/sqlpp11/integral.h index cbf0b298..fca44822 100644 --- a/include/sqlpp11/integral.h +++ b/include/sqlpp11/integral.h @@ -46,6 +46,7 @@ namespace sqlpp using _is_integral = std::true_type; using _is_value = std::true_type; using _is_expression = std::true_type; + using _cpp_value_type = int64_t; template struct _result_entry_t diff --git a/include/sqlpp11/like.h b/include/sqlpp11/like.h index 51e7698c..f2ea27cd 100644 --- a/include/sqlpp11/like.h +++ b/include/sqlpp11/like.h @@ -41,6 +41,7 @@ namespace sqlpp { static_assert(is_text_t::value, "Operand for like() has to be a text"); static_assert(is_text_t::value, "Pattern for like() has to be a text"); + using _parameters = std::tuple; struct _value_type: public ValueType::_base_value_type // we requite fully defined boolean here { diff --git a/include/sqlpp11/parameter.h b/include/sqlpp11/parameter.h index 355c82da..3de5e6d9 100644 --- a/include/sqlpp11/parameter.h +++ b/include/sqlpp11/parameter.h @@ -37,6 +37,8 @@ namespace sqlpp struct parameter_t { using _is_parameter = std::true_type; + using _value_type = ValueType; + using _is_expression_t = std::true_type; template void serialize(std::ostream& os, Db& db) const @@ -45,8 +47,15 @@ namespace sqlpp os << " ? "; } - using _member_t = NameType::_name_t::_member_t; + using _member_t = typename NameType::_name_t::template _member_t; }; + + template + auto parameter(NamedExpr&& namedExpr) + -> parameter_t::type::_value_type, typename std::decay::type> + { + return {}; + } } #endif diff --git a/include/sqlpp11/parameter_list.h b/include/sqlpp11/parameter_list.h index 39d297ed..071e849e 100644 --- a/include/sqlpp11/parameter_list.h +++ b/include/sqlpp11/parameter_list.h @@ -24,8 +24,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SQLPP_PARAMETER_H -#define SQLPP_PARAMETER_H +#ifndef SQLPP_PARAMETER_LIST_H +#define SQLPP_PARAMETER_LIST_H #include @@ -56,6 +56,35 @@ namespace sqlpp std::tuple _parameter_tuple; }; + namespace detail + { + template + struct get_parameter_tuple + { + using type = std::tuple<>; + }; + + template + struct get_parameter_tuple::value, void>::type> + { + using type = std::tuple; + }; + + template + struct get_parameter_tuple, void> + { + // cat together parameter tuples + using type = decltype(std::tuple_cat(std::declval::type>()...)); + }; + + template + struct get_parameter_tuple::value, void>::type> + { + using type = typename get_parameter_tuple::type; + }; + + } + } #endif diff --git a/include/sqlpp11/text.h b/include/sqlpp11/text.h index 8ba3d6b7..e2470242 100644 --- a/include/sqlpp11/text.h +++ b/include/sqlpp11/text.h @@ -46,6 +46,7 @@ namespace sqlpp using _is_text = std::true_type; using _is_value = std::true_type; using _is_expression = std::true_type; + using _cpp_value_type = std::string; template struct _result_entry_t diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index ef495acf..d4afca01 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -116,6 +116,7 @@ namespace sqlpp SQLPP_TYPE_TRAIT_GENERATOR(is_insert_list); SQLPP_TYPE_TRAIT_GENERATOR(is_sort_order); SQLPP_TYPE_TRAIT_GENERATOR(requires_braces); + SQLPP_TYPE_TRAIT_GENERATOR(is_parameter); SQLPP_CONNECTOR_TRAIT_GENERATOR(has_empty_list_insert); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index abc1625f..ebf4c6f1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,4 +8,5 @@ build_and_run(RemoveTest) build_and_run(UpdateTest) build_and_run(SelectTest) build_and_run(FunctionTest) +build_and_run(PreparedTest) diff --git a/tests/PreparedTest.cpp b/tests/PreparedTest.cpp new file mode 100644 index 00000000..eed5920d --- /dev/null +++ b/tests/PreparedTest.cpp @@ -0,0 +1,79 @@ +/* + * 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. + */ + +#include "TabSample.h" +#include "MockDb.h" +#include "is_regular.h" +#include + +#include + +DbMock db = {}; + +int main() +{ + TabSample t; + TabFoo f; + + // empty parameter lists + { + using T = typename sqlpp::detail::get_parameter_tuple::type; + static_assert(std::is_same>::value, "type requirement"); + } + + // single parameter + { + using T = typename sqlpp::detail::get_parameter_tuple::type; + static_assert(std::is_same>::value, "type requirement"); + } + + // single parameter + { + using T = typename sqlpp::detail::get_parameter_tuple::type; + static_assert(std::is_same>::value, "type requirement"); + } + + // single parameter in expression + { + using T = typename sqlpp::detail::get_parameter_tuple::type; + static_assert(std::is_same>::value, "type requirement"); + } + + // single parameter in larger expression + { + using T = typename sqlpp::detail::get_parameter_tuple::type; + static_assert(std::is_same>::value, "type requirement"); + } + + // three parameters in expression + { + using T = typename sqlpp::detail::get_parameter_tuple::type; + static_assert(std::tuple_size::value == 3, "type requirement"); + static_assert(std::is_same>::value, "type requirement"); + } + + + return 0; +}