From 38aba217d4e68dc232cdd528172e856ff20d7f1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthijs=20M=C3=B6hlmann?= Date: Sun, 2 Apr 2023 19:21:06 +0200 Subject: [PATCH] std::string_view should also be assignable in prepared statements --- .../sqlpp11/data_types/text/parameter_value.h | 20 +++++++++++++++++++ tests/core/usage/Insert.cpp | 12 +++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/sqlpp11/data_types/text/parameter_value.h b/include/sqlpp11/data_types/text/parameter_value.h index e1ac1bd0..087bdda8 100644 --- a/include/sqlpp11/data_types/text/parameter_value.h +++ b/include/sqlpp11/data_types/text/parameter_value.h @@ -33,6 +33,10 @@ #include #include +#if __cplusplus >= 201703L +#include +#endif + namespace sqlpp { template <> @@ -47,6 +51,22 @@ namespace sqlpp { target._bind_text_parameter(index, &_value, _is_null); } + +#if __cplusplus >= 201703L + parameter_value_base& operator=(const std::string_view& val) + { + _value = val; + _is_null = false; + return *this; + } + + parameter_value_base& operator=(const char* val) + { + _value = val; + _is_null = false; + return *this; + } +#endif }; } // namespace sqlpp #endif diff --git a/tests/core/usage/Insert.cpp b/tests/core/usage/Insert.cpp index f70ff1b3..ba84f9ed 100644 --- a/tests/core/usage/Insert.cpp +++ b/tests/core/usage/Insert.cpp @@ -27,6 +27,9 @@ #include "Sample.h" #include "is_regular.h" #include +#if __cplusplus >= 201703L +#include +#endif #include #include @@ -103,5 +106,14 @@ int Insert(int, char*[]) prepared_insert.params.delta = sqlpp::value_or_null(17); db(prepared_insert); +#if __cplusplus >= 201703L + auto prepared_insert_sv = db.prepare(insert_into(t).set(t.gamma = parameter(t.gamma), t.delta = parameter(t.delta), t.beta = parameter(t.beta))); + prepared_insert_sv.params.gamma = true; + prepared_insert_sv.params.delta = 17; + std::string_view sv = "string_view"; + prepared_insert_sv.params.beta = sv; + db(prepared_insert_sv); +#endif + return 0; }