From 0471d732f9b4cfa688c6b5c21b21be28f8f467d4 Mon Sep 17 00:00:00 2001 From: rbock Date: Wed, 23 Dec 2015 11:50:40 +0100 Subject: [PATCH 1/3] Added CASE expression --- include/sqlpp11/case.h | 189 ++++++++++++++++++++++++++++++++++++ include/sqlpp11/functions.h | 1 + tests/Interpret.cpp | 4 + 3 files changed, 194 insertions(+) create mode 100644 include/sqlpp11/case.h diff --git a/include/sqlpp11/case.h b/include/sqlpp11/case.h new file mode 100644 index 00000000..c16151e1 --- /dev/null +++ b/include/sqlpp11/case.h @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2015-2015, 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_CASE_H +#define SQLPP_CASE_H + +#include +#include +#include +#include + +namespace sqlpp +{ + namespace detail + { + template + using valid_when_t = + logic::all_t>::value, is_expression_t>::value>; + + template + using valid_then_t = is_expression_t>; + + template + using valid_else_t = logic::all_t< + is_expression_t>::value, + logic::any_t::value, + is_sql_null_t>::value, + std::is_same, value_type_of>>::value>::value>; + } + + template + struct case_t + : public expression_operators< + case_t, + typename std::conditional::value, value_type_of, value_type_of>::type>, + public alias_operators> + { + using _traits = make_traits, tag::is_expression>; + using _nodes = detail::type_vector; + + case_t(When when, Then then, Else else_) : _when(when), _then(then), _else(else_) + { + } + + case_t(const case_t&) = default; + case_t(case_t&&) = default; + case_t& operator=(const case_t&) = default; + case_t& operator=(case_t&&) = default; + ~case_t() = default; + + When _when; + Then _then; + Else _else; + }; + + template + class case_then_t + { + template + auto _else_impl(const std::true_type&, Else else_) -> case_t + { + return {_when, _then, else_}; + }; + + template + auto _else_impl(const std::false_type&, Else else_) -> void; + + public: + case_then_t(When when, Then then) : _when(when), _then(then) + { + } + + case_then_t(const case_then_t&) = default; + case_then_t(case_then_t&&) = default; + case_then_t& operator=(const case_then_t&) = default; + case_then_t& operator=(case_then_t&&) = default; + ~case_then_t() = default; + + template + auto else_(Else else_) -> decltype(this->_else_impl(detail::valid_else_t{}, else_)) + { + static_assert(detail::valid_else_t::value, + "arguments of then and else must be expressions of the same type (or null)"); + return _else_impl(detail::valid_else_t{}, else_); + }; + + private: + When _when; + Then _then; + }; + + template + class case_when_t + { + template + auto _then_impl(const std::true_type&, Then t) -> case_then_t> + { + return {_when, t}; + }; + + template + auto _then_impl(const std::false_type&, Then t) -> void; + + public: + case_when_t(When when) : _when(when) + { + } + + case_when_t(const case_when_t&) = default; + case_when_t(case_when_t&&) = default; + case_when_t& operator=(const case_when_t&) = default; + case_when_t& operator=(case_when_t&&) = default; + ~case_when_t() = default; + + template + auto then(Then t) -> decltype(this->_then_impl(detail::valid_then_t{}, t)) + { + static_assert(detail::valid_then_t::value, "then argument must be a value expression"); + return _then_impl(detail::valid_then_t{}, t); + }; + + private: + When _when; + }; + + template + struct serializer_t> + { + using _serialize_check = serialize_check_of; + using T = case_t; + + static Context& _(const T& t, Context& context) + { + context << "(CASE WHEN "; + serialize(t._when, context); + context << " THEN "; + serialize(t._then, context); + context << " ELSE "; + serialize(t._else, context); + context << " END)"; + return context; + } + }; + + namespace detail + { + template + auto case_when_impl(const std::true_type&, When when) -> case_when_t> + { + return {when}; + } + + template + auto case_when_impl(const std::false_type&, When when) -> void; + } + + template + auto case_when(When when) -> decltype(detail::case_when_impl(detail::valid_when_t{}, when)) + { + static_assert(detail::valid_when_t::value, "case_when condition must be a boolean expression"); + + return detail::case_when_impl(detail::valid_when_t{}, when); + } +} + +#endif diff --git a/include/sqlpp11/functions.h b/include/sqlpp11/functions.h index 2f5925f4..1351c0d2 100644 --- a/include/sqlpp11/functions.h +++ b/include/sqlpp11/functions.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include diff --git a/tests/Interpret.cpp b/tests/Interpret.cpp index a9cfcd6a..c118bae8 100644 --- a/tests/Interpret.cpp +++ b/tests/Interpret.cpp @@ -216,5 +216,9 @@ int Interpret(int, char**) printer.reset(); std::cerr << serialize(select(all_of(s)).from(s).where(true), printer).str() << std::endl; + printer.reset(); + std::cerr << serialize(sqlpp::case_when(true).then(t.alpha).else_(t.alpha + 1).as(t.beta), printer).str() + << std::endl; + return 0; } From 3efae18e081d2e2634a54d5da573298c00e1a3c9 Mon Sep 17 00:00:00 2001 From: rbock Date: Wed, 23 Dec 2015 14:45:40 +0100 Subject: [PATCH 2/3] Friendlier error messages for some case-expressions --- include/sqlpp11/case.h | 2 +- include/sqlpp11/no_value.h | 3 ++- include/sqlpp11/type_traits.h | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/sqlpp11/case.h b/include/sqlpp11/case.h index c16151e1..11877fca 100644 --- a/include/sqlpp11/case.h +++ b/include/sqlpp11/case.h @@ -55,7 +55,7 @@ namespace sqlpp struct case_t : public expression_operators< case_t, - typename std::conditional::value, value_type_of, value_type_of>::type>, + typename std::conditional::value, value_type_of, value_type_of>::type>, public alias_operators> { using _traits = make_traits, tag::is_expression>; diff --git a/include/sqlpp11/no_value.h b/include/sqlpp11/no_value.h index 68c842dc..15703d0e 100644 --- a/include/sqlpp11/no_value.h +++ b/include/sqlpp11/no_value.h @@ -35,7 +35,8 @@ namespace sqlpp { struct no_value_t { - using _traits = make_traits; + using _traits = make_traits; + using _cpp_value_type = void; }; template diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index 83f49e16..8c978de6 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -38,12 +38,13 @@ namespace sqlpp { + struct no_value_t; namespace detail { template struct value_type_of_impl { - static_assert(wrong_t::value, "Attempting to obtain value type from type without value_type"); + using type = no_value_t; }; template From b41f1add8cb486fbe24ea52a5ba3146c387f2e69 Mon Sep 17 00:00:00 2001 From: rbock Date: Wed, 23 Dec 2015 16:01:45 +0100 Subject: [PATCH 3/3] Made no_value to a more complete value type This allows to select NULL via a case statement (seems to make more sense than disallowing it). --- include/sqlpp11/case.h | 8 +-- include/sqlpp11/data_types.h | 1 + include/sqlpp11/{ => data_types}/no_value.h | 28 ++------ .../data_types/no_value/column_operators.h | 41 +++++++++++ .../sqlpp11/data_types/no_value/data_type.h | 44 ++++++++++++ .../no_value/expression_operators.h | 42 +++++++++++ include/sqlpp11/data_types/no_value/operand.h | 35 +++++++++ .../data_types/no_value/parameter_value.h | 35 +++++++++ .../data_types/no_value/result_field.h | 72 +++++++++++++++++++ .../data_types/no_value/wrap_operand.h | 35 +++++++++ include/sqlpp11/default_value.h | 2 +- include/sqlpp11/into.h | 2 +- include/sqlpp11/multi_column.h | 3 +- include/sqlpp11/noop.h | 2 +- include/sqlpp11/null.h | 2 +- include/sqlpp11/prepared_execute.h | 2 +- include/sqlpp11/prepared_insert.h | 2 +- include/sqlpp11/prepared_remove.h | 2 +- include/sqlpp11/prepared_select.h | 2 +- include/sqlpp11/prepared_update.h | 2 +- include/sqlpp11/select_column_list.h | 2 +- include/sqlpp11/select_pseudo_table.h | 2 +- include/sqlpp11/single_table.h | 2 +- include/sqlpp11/table.h | 2 +- include/sqlpp11/verbatim.h | 2 +- include/sqlpp11/verbatim_table.h | 2 +- tests/MockDb.h | 2 +- tests/Select.cpp | 6 ++ 28 files changed, 340 insertions(+), 42 deletions(-) rename include/sqlpp11/{ => data_types}/no_value.h (77%) create mode 100644 include/sqlpp11/data_types/no_value/column_operators.h create mode 100644 include/sqlpp11/data_types/no_value/data_type.h create mode 100644 include/sqlpp11/data_types/no_value/expression_operators.h create mode 100644 include/sqlpp11/data_types/no_value/operand.h create mode 100644 include/sqlpp11/data_types/no_value/parameter_value.h create mode 100644 include/sqlpp11/data_types/no_value/result_field.h create mode 100644 include/sqlpp11/data_types/no_value/wrap_operand.h diff --git a/include/sqlpp11/case.h b/include/sqlpp11/case.h index 11877fca..5183fd8b 100644 --- a/include/sqlpp11/case.h +++ b/include/sqlpp11/case.h @@ -83,7 +83,7 @@ namespace sqlpp auto _else_impl(const std::true_type&, Else else_) -> case_t { return {_when, _then, else_}; - }; + } template auto _else_impl(const std::false_type&, Else else_) -> void; @@ -105,7 +105,7 @@ namespace sqlpp static_assert(detail::valid_else_t::value, "arguments of then and else must be expressions of the same type (or null)"); return _else_impl(detail::valid_else_t{}, else_); - }; + } private: When _when; @@ -119,7 +119,7 @@ namespace sqlpp auto _then_impl(const std::true_type&, Then t) -> case_then_t> { return {_when, t}; - }; + } template auto _then_impl(const std::false_type&, Then t) -> void; @@ -140,7 +140,7 @@ namespace sqlpp { static_assert(detail::valid_then_t::value, "then argument must be a value expression"); return _then_impl(detail::valid_then_t{}, t); - }; + } private: When _when; diff --git a/include/sqlpp11/data_types.h b/include/sqlpp11/data_types.h index 9e50cf9d..0c54cc61 100644 --- a/include/sqlpp11/data_types.h +++ b/include/sqlpp11/data_types.h @@ -33,5 +33,6 @@ #include #include #include +#include #endif diff --git a/include/sqlpp11/no_value.h b/include/sqlpp11/data_types/no_value.h similarity index 77% rename from include/sqlpp11/no_value.h rename to include/sqlpp11/data_types/no_value.h index 15703d0e..312cab93 100644 --- a/include/sqlpp11/no_value.h +++ b/include/sqlpp11/data_types/no_value.h @@ -27,26 +27,12 @@ #ifndef SQLPP_NO_VALUE_H #define SQLPP_NO_VALUE_H -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include -namespace sqlpp -{ - struct no_value_t - { - using _traits = make_traits; - using _cpp_value_type = void; - }; - - template - struct expression_operators - { - }; - - template - struct column_operators - { - }; -} #endif diff --git a/include/sqlpp11/data_types/no_value/column_operators.h b/include/sqlpp11/data_types/no_value/column_operators.h new file mode 100644 index 00000000..3417f2ae --- /dev/null +++ b/include/sqlpp11/data_types/no_value/column_operators.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2013-2015, 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_NO_VALUE_COLUMN_OPERATORS_H +#define SQLPP_NO_VALUE_COLUMN_OPERATORS_H + +#include + +namespace sqlpp +{ + struct no_value_t; + + template + struct column_operators + { + }; +} +#endif diff --git a/include/sqlpp11/data_types/no_value/data_type.h b/include/sqlpp11/data_types/no_value/data_type.h new file mode 100644 index 00000000..df98a11f --- /dev/null +++ b/include/sqlpp11/data_types/no_value/data_type.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2013-2015, 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_NO_VALUE_DATA_TYPE_H +#define SQLPP_NO_VALUE_DATA_TYPE_H + +#include + +namespace sqlpp +{ + struct no_value_t + { + using _traits = make_traits; + using _cpp_value_type = void; + + template + using _is_valid_operand = wrong_t; + }; +} + +#endif diff --git a/include/sqlpp11/data_types/no_value/expression_operators.h b/include/sqlpp11/data_types/no_value/expression_operators.h new file mode 100644 index 00000000..baac3856 --- /dev/null +++ b/include/sqlpp11/data_types/no_value/expression_operators.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2013-2015, 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_NO_VALUE_EXPRESSION_OPERATORS_H +#define SQLPP_NO_VALUE_EXPRESSION_OPERATORS_H + +#include +#include +#include + +namespace sqlpp +{ + template + struct expression_operators : public basic_expression_operators + { + }; +} + +#endif diff --git a/include/sqlpp11/data_types/no_value/operand.h b/include/sqlpp11/data_types/no_value/operand.h new file mode 100644 index 00000000..cbda37f3 --- /dev/null +++ b/include/sqlpp11/data_types/no_value/operand.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2013-2015, 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_NO_VALUE_OPERAND_H +#define SQLPP_NO_VALUE_OPERAND_H + +namespace sqlpp +{ + // There is no no_value operand +} + +#endif diff --git a/include/sqlpp11/data_types/no_value/parameter_value.h b/include/sqlpp11/data_types/no_value/parameter_value.h new file mode 100644 index 00000000..0a822237 --- /dev/null +++ b/include/sqlpp11/data_types/no_value/parameter_value.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2013-2015, 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_NO_VALUE_PARAMETER_VALUE_H +#define SQLPP_NO_VALUE_PARAMETER_VALUE_H + +namespace sqlpp +{ + // There is no no_value parameter +} + +#endif diff --git a/include/sqlpp11/data_types/no_value/result_field.h b/include/sqlpp11/data_types/no_value/result_field.h new file mode 100644 index 00000000..647b6c0a --- /dev/null +++ b/include/sqlpp11/data_types/no_value/result_field.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2013-2015, 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_NO_VALUE_RESULT_FIELD_H +#define SQLPP_NO_VALUE_RESULT_FIELD_H + +#include +#include +#include + +namespace sqlpp +{ + template + struct result_field_t> + { + template + void _bind(Target&, size_t) + { + } + + template + void _post_bind(Target&, size_t) + { + } + + void _validate() const + { + } + + void _invalidate() const + { + } + + constexpr bool is_null() const + { + return true; + } + }; + + template + inline std::ostream& operator<<( + std::ostream& os, const result_field_t>&) + { + os << "NULL"; + return os; + } +} + +#endif diff --git a/include/sqlpp11/data_types/no_value/wrap_operand.h b/include/sqlpp11/data_types/no_value/wrap_operand.h new file mode 100644 index 00000000..545eb09c --- /dev/null +++ b/include/sqlpp11/data_types/no_value/wrap_operand.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2013-2015, 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_NO_VALUE_WRAP_OPERAND_H +#define SQLPP_NO_VALUE_WRAP_OPERAND_H + +namespace sqlpp +{ + // There is no no_value operand +} + +#endif diff --git a/include/sqlpp11/default_value.h b/include/sqlpp11/default_value.h index bee70bb2..83d9dc00 100644 --- a/include/sqlpp11/default_value.h +++ b/include/sqlpp11/default_value.h @@ -27,7 +27,7 @@ #ifndef SQLPP_DEFAULT_VALUE_H #define SQLPP_DEFAULT_VALUE_H -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/into.h b/include/sqlpp11/into.h index 8751cfd1..f420ab57 100644 --- a/include/sqlpp11/into.h +++ b/include/sqlpp11/into.h @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include #include diff --git a/include/sqlpp11/multi_column.h b/include/sqlpp11/multi_column.h index a805a4e2..a8bd1377 100644 --- a/include/sqlpp11/multi_column.h +++ b/include/sqlpp11/multi_column.h @@ -27,7 +27,6 @@ #ifndef SQLPP_MULTI_COLUMN_H #define SQLPP_MULTI_COLUMN_H -#include #include #include @@ -35,6 +34,8 @@ namespace sqlpp { + struct no_value_t; + template struct multi_column_alias_t; diff --git a/include/sqlpp11/noop.h b/include/sqlpp11/noop.h index 0adc03e7..3236e226 100644 --- a/include/sqlpp11/noop.h +++ b/include/sqlpp11/noop.h @@ -28,7 +28,7 @@ #define SQLPP_NOOP_H #include -#include +#include #include #include diff --git a/include/sqlpp11/null.h b/include/sqlpp11/null.h index 6bd4c4f9..cde00e65 100644 --- a/include/sqlpp11/null.h +++ b/include/sqlpp11/null.h @@ -27,7 +27,7 @@ #ifndef SQLPP_NULL_H #define SQLPP_NULL_H -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/prepared_execute.h b/include/sqlpp11/prepared_execute.h index 5304449b..0080b6ee 100644 --- a/include/sqlpp11/prepared_execute.h +++ b/include/sqlpp11/prepared_execute.h @@ -29,7 +29,7 @@ #include #include -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/prepared_insert.h b/include/sqlpp11/prepared_insert.h index 467aebe0..5e7ec2cf 100644 --- a/include/sqlpp11/prepared_insert.h +++ b/include/sqlpp11/prepared_insert.h @@ -29,7 +29,7 @@ #include #include -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/prepared_remove.h b/include/sqlpp11/prepared_remove.h index d1ed093c..b3b4e416 100644 --- a/include/sqlpp11/prepared_remove.h +++ b/include/sqlpp11/prepared_remove.h @@ -29,7 +29,7 @@ #include #include -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/prepared_select.h b/include/sqlpp11/prepared_select.h index 9444bc1c..57454a37 100644 --- a/include/sqlpp11/prepared_select.h +++ b/include/sqlpp11/prepared_select.h @@ -29,7 +29,7 @@ #include #include -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/prepared_update.h b/include/sqlpp11/prepared_update.h index 9b40a397..a5855d1b 100644 --- a/include/sqlpp11/prepared_update.h +++ b/include/sqlpp11/prepared_update.h @@ -29,7 +29,7 @@ #include #include -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/select_column_list.h b/include/sqlpp11/select_column_list.h index 7a90bdef..40a94d4b 100644 --- a/include/sqlpp11/select_column_list.h +++ b/include/sqlpp11/select_column_list.h @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/sqlpp11/select_pseudo_table.h b/include/sqlpp11/select_pseudo_table.h index 6127629c..196c5e10 100644 --- a/include/sqlpp11/select_pseudo_table.h +++ b/include/sqlpp11/select_pseudo_table.h @@ -27,7 +27,7 @@ #ifndef SQLPP_SELECT_PSEUDO_TABLE_H #define SQLPP_SELECT_PSEUDO_TABLE_H -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/single_table.h b/include/sqlpp11/single_table.h index ed900cdf..9a9037c9 100644 --- a/include/sqlpp11/single_table.h +++ b/include/sqlpp11/single_table.h @@ -28,7 +28,7 @@ #define SQLPP_SINGLE_TABLE_H #include -#include +#include #include #include #include diff --git a/include/sqlpp11/table.h b/include/sqlpp11/table.h index e9eb833b..b80b8ae8 100644 --- a/include/sqlpp11/table.h +++ b/include/sqlpp11/table.h @@ -33,7 +33,7 @@ #include #include #include -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/verbatim.h b/include/sqlpp11/verbatim.h index 55d5d651..4a25f102 100644 --- a/include/sqlpp11/verbatim.h +++ b/include/sqlpp11/verbatim.h @@ -27,7 +27,7 @@ #ifndef SQLPP_VERBATIM_H #define SQLPP_VERBATIM_H -#include +#include #include #include diff --git a/include/sqlpp11/verbatim_table.h b/include/sqlpp11/verbatim_table.h index 72d3e4ce..1618bd07 100644 --- a/include/sqlpp11/verbatim_table.h +++ b/include/sqlpp11/verbatim_table.h @@ -27,7 +27,7 @@ #ifndef SQLPP_VERBATIM_TABLE_H #define SQLPP_VERBATIM_TABLE_H -#include +#include namespace sqlpp { diff --git a/tests/MockDb.h b/tests/MockDb.h index 2611add7..a90d4eae 100644 --- a/tests/MockDb.h +++ b/tests/MockDb.h @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/Select.cpp b/tests/Select.cpp index 5d276eef..2d5a9a4c 100644 --- a/tests/Select.cpp +++ b/tests/Select.cpp @@ -164,5 +164,11 @@ int Select(int, char**) select(sqlpp::value(7).as(t.alpha)); + for (const auto& row : + db(select(sqlpp::case_when(true).then(sqlpp::null).else_(sqlpp::null).as(t.beta)).from(t).where(true))) + { + std::cerr << row.beta << std::endl; + } + return 0; }