From 1d98fb01989c6cd35becc275a17f44e64b09eb66 Mon Sep 17 00:00:00 2001 From: rbock Date: Tue, 12 Aug 2014 22:00:59 +0200 Subject: [PATCH] Added tvin arguments for parameters --- include/sqlpp11/boolean.h | 18 +++++++++++++++++- include/sqlpp11/floating_point.h | 15 +++++++++++++++ include/sqlpp11/text.h | 15 +++++++++++++++ include/sqlpp11/tvin.h | 4 ++-- tests/PreparedTest.cpp | 1 + 5 files changed, 50 insertions(+), 3 deletions(-) diff --git a/include/sqlpp11/boolean.h b/include/sqlpp11/boolean.h index 2c65f798..20a663ac 100644 --- a/include/sqlpp11/boolean.h +++ b/include/sqlpp11/boolean.h @@ -32,6 +32,7 @@ #include #include #include +#include #include namespace sqlpp @@ -60,7 +61,22 @@ namespace sqlpp _parameter_t& operator=(const _cpp_value_type& value) { _value = value; - _is_null = (false); + _is_null = false; + return *this; + } + + _parameter_t& operator=(const tvin_t>& t) + { + if (t._is_trivial()) + { + _value = false; + _is_null = true; + } + else + { + _value = t._value._t; + _is_null = false; + } return *this; } diff --git a/include/sqlpp11/floating_point.h b/include/sqlpp11/floating_point.h index 424ac555..9f61c251 100644 --- a/include/sqlpp11/floating_point.h +++ b/include/sqlpp11/floating_point.h @@ -63,6 +63,21 @@ namespace sqlpp return *this; } + _parameter_t& operator=(const tvin_t>& t) + { + if (t._is_trivial()) + { + _value = 0; + _is_null = true; + } + else + { + _value = t._value._t; + _is_null = false; + } + return *this; + } + _parameter_t& operator=(const std::nullptr_t&) { _value = 0; diff --git a/include/sqlpp11/text.h b/include/sqlpp11/text.h index 58affcfc..d707d5a1 100644 --- a/include/sqlpp11/text.h +++ b/include/sqlpp11/text.h @@ -64,6 +64,21 @@ namespace sqlpp return *this; } + _parameter_t& operator=(const tvin_t>& t) + { + if (t._is_trivial()) + { + _value = ""; + _is_null = true; + } + else + { + _value = t._value._t; + _is_null = false; + } + return *this; + } + _parameter_t& operator=(const std::nullptr_t&) { _value = ""; diff --git a/include/sqlpp11/tvin.h b/include/sqlpp11/tvin.h index ad65ed38..fe289149 100644 --- a/include/sqlpp11/tvin.h +++ b/include/sqlpp11/tvin.h @@ -152,9 +152,9 @@ namespace sqlpp }; template - auto tvin(Operand operand) -> tvin_arg_t::type> + auto tvin(Operand operand) -> tvin_arg_t> { - using _operand_t = typename wrap_operand::type; + using _operand_t = wrap_operand_t; static_assert(not std::is_same<_operand_t, Operand>::value or is_result_field_t::value, "tvin() used with invalid type (only string and primitive types allowed)"); return {{operand}}; } diff --git a/tests/PreparedTest.cpp b/tests/PreparedTest.cpp index 2607cd39..cacac316 100644 --- a/tests/PreparedTest.cpp +++ b/tests/PreparedTest.cpp @@ -91,6 +91,7 @@ int main() auto s = select(all_of(t)).from(t).where((t.beta.like(parameter(t.beta)) and t.alpha == parameter(t.alpha)) or t.gamma != parameter(t.gamma)); auto p = db.prepare(s); p.params.alpha = 7; + p.params.alpha = sqlpp::tvin(0); using S = decltype(s); using T = sqlpp::make_parameter_list_t; T npl;