From 1046bde423ea94bde2665761247d0d142863b300 Mon Sep 17 00:00:00 2001 From: vaijns Date: Fri, 6 Dec 2024 20:32:35 +0100 Subject: [PATCH] Add SQL standard functions CURRENT_DATE, CURRENT_TIME and CURRENT_TIMESTAMP --- include/sqlpp11/current_date.h | 84 +++++++++++++++++++++++++++++ include/sqlpp11/current_time.h | 84 +++++++++++++++++++++++++++++ include/sqlpp11/current_timestamp.h | 84 +++++++++++++++++++++++++++++ include/sqlpp11/functions.h | 3 ++ 4 files changed, 255 insertions(+) create mode 100644 include/sqlpp11/current_date.h create mode 100644 include/sqlpp11/current_time.h create mode 100644 include/sqlpp11/current_timestamp.h diff --git a/include/sqlpp11/current_date.h b/include/sqlpp11/current_date.h new file mode 100644 index 00000000..3d478516 --- /dev/null +++ b/include/sqlpp11/current_date.h @@ -0,0 +1,84 @@ +#pragma once + +/* + * 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. + */ + +#include +#include + +namespace sqlpp +{ + struct current_date_alias_t + { + struct _alias_t + { + static constexpr const char _literal[] = "current_date_"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t + { + T current_date; + T& operator()() + { + return current_date; + } + const T& operator()() const + { + return current_date; + } + }; + }; + }; + + struct current_date_t : public expression_operators, public alias_operators + { + using _traits = make_traits; + + using _nodes = detail::type_vector<>; + using _can_be_null = std::false_type; + + using _auto_alias_t = current_date_alias_t; + + constexpr current_date_t() + { + } + + current_date_t(const current_date_t&) = default; + current_date_t(current_date_t&&) = default; + current_date_t& operator=(const current_date_t&) = default; + current_date_t& operator=(current_date_t&&) = default; + ~current_date_t() = default; + }; + + template + Context& serialize(const current_date_t& t, Context& context) + { + context << "CURRENT_DATE"; + return context; + } + + constexpr current_date_t current_date{}; +} // namespace sqlpp diff --git a/include/sqlpp11/current_time.h b/include/sqlpp11/current_time.h new file mode 100644 index 00000000..43154a8f --- /dev/null +++ b/include/sqlpp11/current_time.h @@ -0,0 +1,84 @@ +#pragma once + +/* + * 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. + */ + +#include +#include + +namespace sqlpp +{ + struct current_time_alias_t + { + struct _alias_t + { + static constexpr const char _literal[] = "current_time_"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t + { + T current_time; + T& operator()() + { + return current_time; + } + const T& operator()() const + { + return current_time; + } + }; + }; + }; + + struct current_time_t : public expression_operators, public alias_operators + { + using _traits = make_traits; + + using _nodes = detail::type_vector<>; + using _can_be_null = std::false_type; + + using _auto_alias_t = current_time_alias_t; + + constexpr current_time_t() + { + } + + current_time_t(const current_time_t&) = default; + current_time_t(current_time_t&&) = default; + current_time_t& operator=(const current_time_t&) = default; + current_time_t& operator=(current_time_t&&) = default; + ~current_time_t() = default; + }; + + template + Context& serialize(const current_time_t& t, Context& context) + { + context << "CURRENT_TIME"; + return context; + } + + constexpr current_time_t current_time{}; +} // namespace sqlpp diff --git a/include/sqlpp11/current_timestamp.h b/include/sqlpp11/current_timestamp.h new file mode 100644 index 00000000..98db4a12 --- /dev/null +++ b/include/sqlpp11/current_timestamp.h @@ -0,0 +1,84 @@ +#pragma once + +/* + * 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. + */ + +#include +#include + +namespace sqlpp +{ + struct current_timestamp_alias_t + { + struct _alias_t + { + static constexpr const char _literal[] = "current_timestamp_"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t + { + T current_timestamp; + T& operator()() + { + return current_timestamp; + } + const T& operator()() const + { + return current_timestamp; + } + }; + }; + }; + + struct current_timestamp_t : public expression_operators, public alias_operators + { + using _traits = make_traits; + + using _nodes = detail::type_vector<>; + using _can_be_null = std::false_type; + + using _auto_alias_t = current_timestamp_alias_t; + + constexpr current_timestamp_t() + { + } + + current_timestamp_t(const current_timestamp_t&) = default; + current_timestamp_t(current_timestamp_t&&) = default; + current_timestamp_t& operator=(const current_timestamp_t&) = default; + current_timestamp_t& operator=(current_timestamp_t&&) = default; + ~current_timestamp_t() = default; + }; + + template + Context& serialize(const current_timestamp_t& t, Context& context) + { + context << "CURRENT_TIMESTAMP"; + return context; + } + + constexpr current_timestamp_t current_timestamp{}; +} // namespace sqlpp diff --git a/include/sqlpp11/functions.h b/include/sqlpp11/functions.h index eadd33c6..0e84cabe 100644 --- a/include/sqlpp11/functions.h +++ b/include/sqlpp11/functions.h @@ -50,6 +50,9 @@ #include #include #include +#include +#include +#include namespace sqlpp {