From dfcd372611cf2ee853b8bd1f28334e96a13e9536 Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 26 Jan 2014 15:44:44 +0100 Subject: [PATCH] tvin works with const char*, too --- include/sqlpp11/tvin.h | 28 ++++++++++++++------------- include/sqlpp11/vendor/insert_value.h | 2 +- include/sqlpp11/vendor/wrap_operand.h | 1 - tests/InterpretTest.cpp | 2 +- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/include/sqlpp11/tvin.h b/include/sqlpp11/tvin.h index 9e47969c..363192c0 100644 --- a/include/sqlpp11/tvin.h +++ b/include/sqlpp11/tvin.h @@ -34,15 +34,14 @@ namespace sqlpp { - template + template struct tvin_t { - using _operand_t = typename vendor::wrap_operand::type; - static_assert(std::is_same<_operand_t, vendor::text_operand>::value or not std::is_same<_operand_t, T>::value, "tvin() used with invalid type (only string and primitive types allowed)"); + using _operand_t = Operand; using _value_type = typename _operand_t::_value_type; - tvin_t(T t): - _value({t}) + tvin_t(Operand operand): + _value(operand) {} tvin_t(const tvin_t&) = default; tvin_t(tvin_t&&) = default; @@ -60,10 +59,10 @@ namespace sqlpp namespace vendor { - template - struct interpreter_t> + template + struct interpreter_t> { - using T = tvin_t; + using T = tvin_t; static void _(const T& t, Context& context) { @@ -114,10 +113,10 @@ namespace sqlpp namespace vendor { - template - struct interpreter_t> + template + struct interpreter_t> { - using T = tvin_wrap_t; + using T = tvin_wrap_t; static Context& _(const T& t, Context& context) { @@ -135,9 +134,12 @@ namespace sqlpp } template - auto tvin(T t) -> tvin_t::type> + auto tvin(T t) -> tvin_t::type> { - return {t}; + using _operand_t = typename vendor::wrap_operand::type; + static_assert(std::is_same<_operand_t, vendor::text_operand>::value + or not std::is_same<_operand_t, T>::value, "tvin() used with invalid type (only string and primitive types allowed)"); + return {{t}}; } } diff --git a/include/sqlpp11/vendor/insert_value.h b/include/sqlpp11/vendor/insert_value.h index 13835709..88559474 100644 --- a/include/sqlpp11/vendor/insert_value.h +++ b/include/sqlpp11/vendor/insert_value.h @@ -60,7 +60,7 @@ namespace sqlpp using _is_insert_value = std::true_type; using _pure_value_t = typename Column::_value_type::_cpp_value_type; using _wrapped_value_t = typename wrap_operand<_pure_value_t>::type; - using _tvin_t = typename detail::type_if, can_be_null_t::value>::type; // static asserts and SFINAE do not work together + using _tvin_t = typename detail::type_if, can_be_null_t::value>::type; // static asserts and SFINAE do not work together using _null_t = typename detail::type_if::value>::type; // static asserts and SFINAE do not work together insert_value_t(assignment_t assignment): diff --git a/include/sqlpp11/vendor/wrap_operand.h b/include/sqlpp11/vendor/wrap_operand.h index 184fe5cb..b3873009 100644 --- a/include/sqlpp11/vendor/wrap_operand.h +++ b/include/sqlpp11/vendor/wrap_operand.h @@ -164,7 +164,6 @@ namespace sqlpp }; // FIXME: Need to allow std::ref arguments - // FIXME: insert requires to work with value_list } } diff --git a/tests/InterpretTest.cpp b/tests/InterpretTest.cpp index 77670dd8..1a81b9ba 100644 --- a/tests/InterpretTest.cpp +++ b/tests/InterpretTest.cpp @@ -47,7 +47,7 @@ int main() interpret(insert_into(t).columns(t.gamma, t.beta).add_values(t.gamma = true, t.beta = "cheesecake"), printer).flush(); interpret(insert_into(t).columns(t.gamma, t.beta) .add_values(t.gamma = true, t.beta = "cheesecake") - .add_values(t.gamma = false, t.beta = sqlpp::tvin(std::string("coffee"))) // FIXME: Want to use const char* const here, too + .add_values(t.gamma = false, t.beta = sqlpp::tvin("coffee")) .add_values(t.gamma = false, t.beta = sqlpp::tvin(std::string())) , printer).flush(); interpret(insert_into(t).columns(t.gamma, t.beta)