From 24ca3b2217e4c4ee937ec44ea7ec18741d3b4d31 Mon Sep 17 00:00:00 2001 From: Aaron Bishop Date: Mon, 2 May 2016 08:08:34 -0400 Subject: [PATCH 01/15] added common SQL data types like binary and bit --- include/sqlpp11/data_types/boolean/data_type.h | 2 ++ include/sqlpp11/data_types/day_point/data_type.h | 2 ++ include/sqlpp11/data_types/text/data_type.h | 2 ++ include/sqlpp11/data_types/time_point/data_type.h | 4 ++++ 4 files changed, 10 insertions(+) diff --git a/include/sqlpp11/data_types/boolean/data_type.h b/include/sqlpp11/data_types/boolean/data_type.h index 66528c63..7589d829 100644 --- a/include/sqlpp11/data_types/boolean/data_type.h +++ b/include/sqlpp11/data_types/boolean/data_type.h @@ -39,6 +39,8 @@ namespace sqlpp template using _is_valid_operand = is_boolean_t; }; + + using bit = sqlpp::boolean; } #endif diff --git a/include/sqlpp11/data_types/day_point/data_type.h b/include/sqlpp11/data_types/day_point/data_type.h index a589e752..9be108a0 100644 --- a/include/sqlpp11/data_types/day_point/data_type.h +++ b/include/sqlpp11/data_types/day_point/data_type.h @@ -42,5 +42,7 @@ namespace sqlpp template using _is_valid_assignment_operand = is_day_point_t; }; + + using date = day_point; } #endif diff --git a/include/sqlpp11/data_types/text/data_type.h b/include/sqlpp11/data_types/text/data_type.h index 7b90b5e0..6215dacb 100644 --- a/include/sqlpp11/data_types/text/data_type.h +++ b/include/sqlpp11/data_types/text/data_type.h @@ -43,5 +43,7 @@ namespace sqlpp using blob = text; using varchar = text; using char_ = text; + using binary = text; + using varbinary = text; } #endif diff --git a/include/sqlpp11/data_types/time_point/data_type.h b/include/sqlpp11/data_types/time_point/data_type.h index ad3f727e..41bc7eca 100644 --- a/include/sqlpp11/data_types/time_point/data_type.h +++ b/include/sqlpp11/data_types/time_point/data_type.h @@ -40,5 +40,9 @@ namespace sqlpp template using _is_valid_operand = is_day_or_time_point_t; }; + + using datetime = time_point; + using timestamp = time_point; + using time = time_point; } #endif From ce7b949e1bb1446fd5b086c14670e415b6fc0775 Mon Sep 17 00:00:00 2001 From: Aaron Bishop Date: Thu, 19 May 2016 08:53:56 -0400 Subject: [PATCH 02/15] Added time_of_day data_type --- include/sqlpp11/chrono.h | 7 ++ include/sqlpp11/data_types.h | 1 + include/sqlpp11/data_types/time_of_day.h | 38 +++++++++ .../data_types/time_of_day/column_operators.h | 44 ++++++++++ .../data_types/time_of_day/data_type.h | 44 ++++++++++ .../time_of_day/expression_operators.h | 43 ++++++++++ .../sqlpp11/data_types/time_of_day/operand.h | 83 +++++++++++++++++++ .../data_types/time_of_day/parameter_value.h | 53 ++++++++++++ .../data_types/time_of_day/result_field.h | 73 ++++++++++++++++ .../data_types/time_of_day/wrap_operand.h | 41 +++++++++ include/sqlpp11/type_traits.h | 4 + tests/DateTime.cpp | 6 +- tests/Sample.h | 25 +++++- 13 files changed, 459 insertions(+), 3 deletions(-) create mode 100644 include/sqlpp11/data_types/time_of_day.h create mode 100644 include/sqlpp11/data_types/time_of_day/column_operators.h create mode 100644 include/sqlpp11/data_types/time_of_day/data_type.h create mode 100644 include/sqlpp11/data_types/time_of_day/expression_operators.h create mode 100644 include/sqlpp11/data_types/time_of_day/operand.h create mode 100644 include/sqlpp11/data_types/time_of_day/parameter_value.h create mode 100644 include/sqlpp11/data_types/time_of_day/result_field.h create mode 100644 include/sqlpp11/data_types/time_of_day/wrap_operand.h diff --git a/include/sqlpp11/chrono.h b/include/sqlpp11/chrono.h index 1ab77523..572245ca 100644 --- a/include/sqlpp11/chrono.h +++ b/include/sqlpp11/chrono.h @@ -44,6 +44,13 @@ namespace sqlpp #else using ::date::floor; #endif + + template + std::chrono::microseconds time_of_day(T t) + { + const auto dp = floor(t); + return std::chrono::duration_cast(::date::make_time(t - dp).to_duration()); + } } } diff --git a/include/sqlpp11/data_types.h b/include/sqlpp11/data_types.h index 0c54cc61..c9df51fa 100644 --- a/include/sqlpp11/data_types.h +++ b/include/sqlpp11/data_types.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include diff --git a/include/sqlpp11/data_types/time_of_day.h b/include/sqlpp11/data_types/time_of_day.h new file mode 100644 index 00000000..5eb1a630 --- /dev/null +++ b/include/sqlpp11/data_types/time_of_day.h @@ -0,0 +1,38 @@ +/* + * 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_TIME_OF_DAY_H +#define SQLPP_TIME_OF_DAY_H + +#include +#include +#include +#include +#include +#include +#include + +#endif diff --git a/include/sqlpp11/data_types/time_of_day/column_operators.h b/include/sqlpp11/data_types/time_of_day/column_operators.h new file mode 100644 index 00000000..cbe989a8 --- /dev/null +++ b/include/sqlpp11/data_types/time_of_day/column_operators.h @@ -0,0 +1,44 @@ +/* + * 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_TIME_OF_DAY_COLUMN_OPERATOR_H +#define SQLPP_TIME_OF_DAY_COLUMN_OPERATOR_H + +#include +#include +#include +#include + +namespace sqlpp +{ + template + struct column_operators + { + template + using _is_valid_operand = is_valid_operand; + }; +} +#endif diff --git a/include/sqlpp11/data_types/time_of_day/data_type.h b/include/sqlpp11/data_types/time_of_day/data_type.h new file mode 100644 index 00000000..d58dcc10 --- /dev/null +++ b/include/sqlpp11/data_types/time_of_day/data_type.h @@ -0,0 +1,44 @@ +/* + * 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_TIME_OF_DAY_DATA_TYPE_H +#define SQLPP_TIME_OF_DAY_DATA_TYPE_H + +#include +#include + +namespace sqlpp +{ + struct time_of_day + { + using _traits = make_traits; + using _cpp_value_type = std::chrono::microseconds; + + template + using _is_valid_operand = is_time_of_day_t; + }; +} +#endif diff --git a/include/sqlpp11/data_types/time_of_day/expression_operators.h b/include/sqlpp11/data_types/time_of_day/expression_operators.h new file mode 100644 index 00000000..1c75de8f --- /dev/null +++ b/include/sqlpp11/data_types/time_of_day/expression_operators.h @@ -0,0 +1,43 @@ +/* + * 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_TIME_OF_DAY_EXPRESSION_OPERATORS_H +#define SQLPP_TIME_OF_DAY_EXPRESSION_OPERATORS_H + +#include +#include +#include +#include + +namespace sqlpp +{ + // time_of_day expression operators + template + struct expression_operators : public basic_expression_operators + { + }; +} +#endif diff --git a/include/sqlpp11/data_types/time_of_day/operand.h b/include/sqlpp11/data_types/time_of_day/operand.h new file mode 100644 index 00000000..bcac1e49 --- /dev/null +++ b/include/sqlpp11/data_types/time_of_day/operand.h @@ -0,0 +1,83 @@ +/* + * 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_TIME_OF_DAY_OPERAND_H +#define SQLPP_TIME_OF_DAY_OPERAND_H + +#include +#include +#include +#include + +namespace sqlpp +{ + struct time_of_day; + + template + struct time_of_day_operand : public alias_operators> + { + using _traits = make_traits; + using _nodes = detail::type_vector<>; + using _is_aggregate_expression = std::true_type; + + using _value_t = std::chrono::microseconds; + + time_of_day_operand() : _t{} + { + } + + time_of_day_operand(_value_t t) : _t(t) + { + } + + time_of_day_operand(const time_of_day_operand&) = default; + time_of_day_operand(time_of_day_operand&&) = default; + time_of_day_operand& operator=(const time_of_day_operand&) = default; + time_of_day_operand& operator=(time_of_day_operand&&) = default; + ~time_of_day_operand() = default; + + bool _is_trivial() const + { + return std::chrono::operator==(_t, _value_t{}); + } + + _value_t _t; + }; + + template + struct serializer_t> + { + using _serialize_check = consistent_t; + using Operand = time_of_day_operand; + + static Context& _(const Operand& t, Context& context) + { + context << '\'' << ::date::make_time(t._t) << '\''; + return context; + } + }; +} +#endif diff --git a/include/sqlpp11/data_types/time_of_day/parameter_value.h b/include/sqlpp11/data_types/time_of_day/parameter_value.h new file mode 100644 index 00000000..79075b34 --- /dev/null +++ b/include/sqlpp11/data_types/time_of_day/parameter_value.h @@ -0,0 +1,53 @@ +/* + * 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_TIME_OF_DAY_PARAMETER_VALUE_H +#define SQLPP_TIME_OF_DAY_PARAMETER_VALUE_H + +#include +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template <> + struct parameter_value_t : public parameter_value_base + { + using base = parameter_value_base; + using base::base; + using base::operator=; + + template + void _bind(Target& target, size_t index) const + { + target._bind_time_of_day_parameter(index, &_value, _is_null); + } + }; +} +#endif diff --git a/include/sqlpp11/data_types/time_of_day/result_field.h b/include/sqlpp11/data_types/time_of_day/result_field.h new file mode 100644 index 00000000..a0753db1 --- /dev/null +++ b/include/sqlpp11/data_types/time_of_day/result_field.h @@ -0,0 +1,73 @@ +/* + * 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_TIME_OF_DAY_RESULT_FIELD_H +#define SQLPP_TIME_OF_DAY_RESULT_FIELD_H + +#include +#include +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template + struct result_field_t> + : public result_field_base> + { + template + void _bind(Target& target, size_t i) + { + target._bind_time_of_day_result(i, &this->_value, &this->_is_null); + } + + template + void _post_bind(Target& target, size_t i) + { + target._post_bind_time_of_day_result(i, &this->_value, &this->_is_null); + } + }; + + template + inline std::ostream& operator<<( + std::ostream& os, const result_field_t>& e) + { + if (e.is_null() and not NullIsTrivialValue) + { + os << "NULL"; + } + else + { + const auto time = ::date::make_time(::sqlpp::chrono::floor<::date::days>(e.value() % std::chrono::duration(24))); + os << time; + } + return os; + } +} +#endif diff --git a/include/sqlpp11/data_types/time_of_day/wrap_operand.h b/include/sqlpp11/data_types/time_of_day/wrap_operand.h new file mode 100644 index 00000000..ba53fe5c --- /dev/null +++ b/include/sqlpp11/data_types/time_of_day/wrap_operand.h @@ -0,0 +1,41 @@ +/* + * 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_TIME_OF_DAY_WRAP_OPERAND_H +#define SQLPP_TIME_OF_DAY_WRAP_OPERAND_H + +#include +#include + +namespace sqlpp +{ + template + struct wrap_operand, void> + { + using type = time_of_day_operand>; + }; +} +#endif diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index 1b2d33ea..25e4fcda 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -83,6 +83,10 @@ namespace sqlpp template using is_text_t = std::is_same, text>; + struct time_of_day; + template + using is_time_of_day_t = std::is_same, time_of_day>; + struct time_point; template using is_time_point_t = std::is_same, time_point>; diff --git a/tests/DateTime.cpp b/tests/DateTime.cpp index 669b69a7..4f042a9c 100644 --- a/tests/DateTime.cpp +++ b/tests/DateTime.cpp @@ -58,21 +58,23 @@ int DateTime(int, char* []) db(insert_into(t).set(t.colDayPoint = floor<::sqlpp::chrono::days>(std::chrono::system_clock::now()))); db(insert_into(t).set(t.colTimePoint = floor<::sqlpp::chrono::days>(std::chrono::system_clock::now()))); db(insert_into(t).set(t.colTimePoint = std::chrono::system_clock::now())); + db(insert_into(t).set(t.colTimeOfDay = ::sqlpp::chrono::time_of_day(std::chrono::system_clock::now()))); db(update(t) .set(t.colDayPoint = floor<::sqlpp::chrono::days>(std::chrono::system_clock::now())) .where(t.colDayPoint < std::chrono::system_clock::now())); db(update(t) - .set(t.colTimePoint = floor<::sqlpp::chrono::days>(std::chrono::system_clock::now())) + .set(t.colTimePoint = floor<::sqlpp::chrono::days>(std::chrono::system_clock::now()), t.colTimeOfDay = ::sqlpp::chrono::time_of_day(std::chrono::system_clock::now())) .where(t.colDayPoint < std::chrono::system_clock::now())); db(update(t) - .set(t.colTimePoint = std::chrono::system_clock::now()) + .set(t.colTimePoint = std::chrono::system_clock::now(), t.colTimeOfDay = ::sqlpp::chrono::time_of_day(std::chrono::system_clock::now())) .where(t.colDayPoint < std::chrono::system_clock::now())); db(remove_from(t).where(t.colDayPoint == floor<::sqlpp::chrono::days>(std::chrono::system_clock::now()))); db(remove_from(t).where(t.colDayPoint == std::chrono::system_clock::now())); db(remove_from(t).where(t.colTimePoint == floor<::sqlpp::chrono::days>(std::chrono::system_clock::now()))); db(remove_from(t).where(t.colTimePoint == std::chrono::system_clock::now())); + db(remove_from(t).where(t.colTimeOfDay == ::sqlpp::chrono::time_of_day(std::chrono::system_clock::now()))); return 0; } diff --git a/tests/Sample.h b/tests/Sample.h index 0bb6dc51..f6f903dd 100644 --- a/tests/Sample.h +++ b/tests/Sample.h @@ -259,9 +259,32 @@ namespace test }; using _traits = sqlpp::make_traits; }; + + struct ColTimeOfDay + { + struct _alias_t + { + static constexpr const char _literal[] = "col_time_of_day"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t + { + T colTimeOfDay; + T& operator()() + { + return colTimeOfDay; + } + const T& operator()() const + { + return colTimeOfDay; + } + }; + }; + using _traits = sqlpp::make_traits; + }; } - struct TabDateTime : sqlpp::table_t + struct TabDateTime : sqlpp::table_t { struct _alias_t { From c0494bd98b40f030db080285e85c25630a7de7db Mon Sep 17 00:00:00 2001 From: Aaron Bishop Date: Thu, 19 May 2016 21:03:49 -0400 Subject: [PATCH 03/15] fixed ctest issues --- include/sqlpp11/data_types/time_of_day/result_field.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/sqlpp11/data_types/time_of_day/result_field.h b/include/sqlpp11/data_types/time_of_day/result_field.h index a0753db1..511fe8d6 100644 --- a/include/sqlpp11/data_types/time_of_day/result_field.h +++ b/include/sqlpp11/data_types/time_of_day/result_field.h @@ -64,8 +64,7 @@ namespace sqlpp } else { - const auto time = ::date::make_time(::sqlpp::chrono::floor<::date::days>(e.value() % std::chrono::duration(24))); - os << time; + os << ::date::make_time(e.value()); } return os; } From a8fa0ddba00ee08d9aaa485084c303f9b7ad40dc Mon Sep 17 00:00:00 2001 From: Aaron Bishop Date: Fri, 20 May 2016 07:09:48 -0400 Subject: [PATCH 04/15] reset to master, added unsigned_integral, removed time_of_day --- include/sqlpp11/chrono.h | 8 ++ include/sqlpp11/data_types.h | 1 + .../data_types/integral/wrap_operand.h | 2 +- .../sqlpp11/data_types/unsigned_integral.h | 38 ++++++ .../unsigned_integral/column_operators.h | 82 +++++++++++++ .../data_types/unsigned_integral/data_type.h | 48 ++++++++ .../unsigned_integral/expression_operators.h | 108 ++++++++++++++++++ .../data_types/unsigned_integral/operand.h | 82 +++++++++++++ .../unsigned_integral/parameter_value.h | 51 +++++++++ .../unsigned_integral/result_field.h | 55 +++++++++ .../unsigned_integral/wrap_operand.h | 43 +++++++ include/sqlpp11/type_traits.h | 6 +- tests/Sample.h | 24 +++- tests/SelectType.cpp | 18 +++ tests/sample.sql | 3 +- 15 files changed, 565 insertions(+), 4 deletions(-) create mode 100644 include/sqlpp11/data_types/unsigned_integral.h create mode 100644 include/sqlpp11/data_types/unsigned_integral/column_operators.h create mode 100644 include/sqlpp11/data_types/unsigned_integral/data_type.h create mode 100644 include/sqlpp11/data_types/unsigned_integral/expression_operators.h create mode 100644 include/sqlpp11/data_types/unsigned_integral/operand.h create mode 100644 include/sqlpp11/data_types/unsigned_integral/parameter_value.h create mode 100644 include/sqlpp11/data_types/unsigned_integral/result_field.h create mode 100644 include/sqlpp11/data_types/unsigned_integral/wrap_operand.h diff --git a/include/sqlpp11/chrono.h b/include/sqlpp11/chrono.h index 1ab77523..ab91d746 100644 --- a/include/sqlpp11/chrono.h +++ b/include/sqlpp11/chrono.h @@ -44,6 +44,14 @@ namespace sqlpp #else using ::date::floor; #endif + + + template + std::chrono::microseconds time_of_day(T t) + { + const auto dp = floor(t); + return std::chrono::duration_cast(::date::make_time(t - dp).to_duration()); + } } } diff --git a/include/sqlpp11/data_types.h b/include/sqlpp11/data_types.h index 0c54cc61..eee711bc 100644 --- a/include/sqlpp11/data_types.h +++ b/include/sqlpp11/data_types.h @@ -29,6 +29,7 @@ #include #include +#include #include #include #include diff --git a/include/sqlpp11/data_types/integral/wrap_operand.h b/include/sqlpp11/data_types/integral/wrap_operand.h index a395b864..1a07838a 100644 --- a/include/sqlpp11/data_types/integral/wrap_operand.h +++ b/include/sqlpp11/data_types/integral/wrap_operand.h @@ -35,7 +35,7 @@ namespace sqlpp struct integral_operand; template - struct wrap_operand::value and not std::is_same::value>::type> + struct wrap_operand::value and not std::is_same::value and not std::is_unsigned::value>::type> { using type = integral_operand; }; diff --git a/include/sqlpp11/data_types/unsigned_integral.h b/include/sqlpp11/data_types/unsigned_integral.h new file mode 100644 index 00000000..ba0a98ff --- /dev/null +++ b/include/sqlpp11/data_types/unsigned_integral.h @@ -0,0 +1,38 @@ +/* + * 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_UNSIGNED_INTEGRAL_H +#define SQLPP_UNSIGNED_INTEGRAL_H + +#include +#include +#include +#include +#include +#include +#include + +#endif diff --git a/include/sqlpp11/data_types/unsigned_integral/column_operators.h b/include/sqlpp11/data_types/unsigned_integral/column_operators.h new file mode 100644 index 00000000..ea98038b --- /dev/null +++ b/include/sqlpp11/data_types/unsigned_integral/column_operators.h @@ -0,0 +1,82 @@ +/* + * 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_UNSIGNED_INTEGRAL_COLUMN_OPERATORS_H +#define SQLPP_UNSIGNED_INTEGRAL_COLUMN_OPERATORS_H + +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template + struct column_operators + { + template + using _is_valid_operand = is_valid_operand; + + template + auto operator+=(T t) const -> assignment_t, wrap_operand_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return {*static_cast(this), {{*static_cast(this), rhs{t}}}}; + } + + template + auto operator-=(T t) const -> assignment_t, wrap_operand_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return {*static_cast(this), {{*static_cast(this), rhs{t}}}}; + } + + template + auto operator/=(T t) const -> assignment_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return {*static_cast(this), {{*static_cast(this), rhs{t}}}}; + } + + template + auto operator*=(T t) const -> assignment_t, wrap_operand_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return {*static_cast(this), {{*static_cast(this), rhs{t}}}}; + } + }; +} + +#endif diff --git a/include/sqlpp11/data_types/unsigned_integral/data_type.h b/include/sqlpp11/data_types/unsigned_integral/data_type.h new file mode 100644 index 00000000..68e061aa --- /dev/null +++ b/include/sqlpp11/data_types/unsigned_integral/data_type.h @@ -0,0 +1,48 @@ +/* + * 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_UNSIGNED_INTEGRAL_DATA_TYPE_H +#define SQLPP_UNSIGNED_INTEGRAL_DATA_TYPE_H + +#include + +namespace sqlpp +{ + struct unsigned_integral + { + using _traits = make_traits; + using _cpp_value_type = uint64_t; + + template + using _is_valid_operand = is_numeric_t; + }; + + using tinyint_unsigned = unsigned_integral; + using smallint_unsigned = unsigned_integral; + using integer_unsigned = unsigned_integral; + using bigint_unsigned = unsigned_integral; +} +#endif diff --git a/include/sqlpp11/data_types/unsigned_integral/expression_operators.h b/include/sqlpp11/data_types/unsigned_integral/expression_operators.h new file mode 100644 index 00000000..0ce3b0e1 --- /dev/null +++ b/include/sqlpp11/data_types/unsigned_integral/expression_operators.h @@ -0,0 +1,108 @@ +/* + * 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_UNSIGNED_INTEGRAL_EXPRESSION_OPERATORS_H +#define SQLPP_UNSIGNED_INTEGRAL_EXPRESSION_OPERATORS_H + +#include +#include +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template + struct expression_operators : public basic_expression_operators + { + }; + + template + struct return_type_plus> + { + using check = consistent_t; + using type = plus_t, value_type_of>, wrap_operand_t>; + }; + + template + struct return_type_minus> + { + using check = consistent_t; + using type = minus_t, value_type_of>, wrap_operand_t>; + }; + + template + struct return_type_multiplies> + { + using check = consistent_t; + using type = multiplies_t, value_type_of>, wrap_operand_t>; + }; + + template + struct return_type_divides> + { + using check = consistent_t; + using type = divides_t, wrap_operand_t>; + }; + + template + struct return_type_modulus> + { + using check = consistent_t; + using type = modulus_t, wrap_operand_t>; + }; + + template + struct return_type_unary_plus> + { + using check = consistent_t; + using type = unary_plus_t>; + }; + + template + struct return_type_unary_minus> + { + using check = consistent_t; + using type = unary_minus_t>; + }; + + template + struct return_type_bitwise_and> + { + using check = consistent_t; + using type = bitwise_and_t, unsigned_integral, wrap_operand_t>; + }; + + template + struct return_type_bitwise_or> + { + using check = consistent_t; + using type = bitwise_or_t, unsigned_integral, wrap_operand_t>; + }; +} +#endif diff --git a/include/sqlpp11/data_types/unsigned_integral/operand.h b/include/sqlpp11/data_types/unsigned_integral/operand.h new file mode 100644 index 00000000..d117b6fa --- /dev/null +++ b/include/sqlpp11/data_types/unsigned_integral/operand.h @@ -0,0 +1,82 @@ +/* + * 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_UNSIGNED_INTEGRAL_OPERAND_H +#define SQLPP_UNSIGNED_INTEGRAL_OPERAND_H + +#include +#include +#include + +namespace sqlpp +{ + struct unsigned_integral; + + struct unsigned_integral_operand : public alias_operators + { + using _traits = make_traits; + using _nodes = detail::type_vector<>; + using _is_aggregate_expression = std::true_type; + + using _value_t = uint64_t; + + unsigned_integral_operand() : _t{} + { + } + + unsigned_integral_operand(_value_t t) : _t(t) + { + } + + unsigned_integral_operand(const unsigned_integral_operand&) = default; + unsigned_integral_operand(unsigned_integral_operand&&) = default; + unsigned_integral_operand& operator=(const unsigned_integral_operand&) = default; + unsigned_integral_operand& operator=(unsigned_integral_operand&&) = default; + ~unsigned_integral_operand() = default; + + bool _is_trivial() const + { + return _t == 0; + } + + _value_t _t; + }; + + template + struct serializer_t + { + using _serialize_check = consistent_t; + using Operand = unsigned_integral_operand; + + static Context& _(const Operand& t, Context& context) + { + context << t._t; + return context; + } + }; +} + +#endif diff --git a/include/sqlpp11/data_types/unsigned_integral/parameter_value.h b/include/sqlpp11/data_types/unsigned_integral/parameter_value.h new file mode 100644 index 00000000..9b596d33 --- /dev/null +++ b/include/sqlpp11/data_types/unsigned_integral/parameter_value.h @@ -0,0 +1,51 @@ +/* + * 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_UNSIGNED_INTEGRAL_PARAMETER_VALUE_H +#define SQLPP_UNSIGNED_INTEGRAL_PARAMETER_VALUE_H + +#include +#include +#include +#include + +namespace sqlpp +{ + template <> + struct parameter_value_t : public parameter_value_base + { + using base = parameter_value_base; + using base::base; + using base::operator=; + + template + void _bind(Target& target, size_t index) const + { + target._bind_unsigned_integral_parameter(index, &_value, _is_null); + } + }; +} +#endif diff --git a/include/sqlpp11/data_types/unsigned_integral/result_field.h b/include/sqlpp11/data_types/unsigned_integral/result_field.h new file mode 100644 index 00000000..960ccc1a --- /dev/null +++ b/include/sqlpp11/data_types/unsigned_integral/result_field.h @@ -0,0 +1,55 @@ +/* + * 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_UNSIGNED_INTEGRAL_RESULT_FIELD_H +#define SQLPP_UNSIGNED_INTEGRAL_RESULT_FIELD_H + +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template + struct result_field_t> + : public result_field_base> + { + template + void _bind(Target& target, size_t index) + { + target._bind_unsigned_integral_result(index, &this->_value, &this->_is_null); + } + + template + void _post_bind(Target& target, size_t index) + { + target._post_bind_unsigned_integral_result(index, &this->_value, &this->_is_null); + } + }; +} +#endif diff --git a/include/sqlpp11/data_types/unsigned_integral/wrap_operand.h b/include/sqlpp11/data_types/unsigned_integral/wrap_operand.h new file mode 100644 index 00000000..d12a5af6 --- /dev/null +++ b/include/sqlpp11/data_types/unsigned_integral/wrap_operand.h @@ -0,0 +1,43 @@ +/* + * 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_UNSIGNED_INTEGRAL_WRAP_OPERAND_H +#define SQLPP_UNSIGNED_INTEGRAL_WRAP_OPERAND_H + +#include +#include + +namespace sqlpp +{ + struct unsigned_integral_operand; + + template + struct wrap_operand::value and not std::is_same::value and std::is_unsigned::value>::type> + { + using type = unsigned_integral_operand; + }; +} +#endif diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index 1b2d33ea..08a3f9fe 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -79,6 +79,10 @@ namespace sqlpp template using is_integral_t = std::is_same, integral>; + struct unsigned_integral; + template + using is_unsigned_integral_t = std::is_same, unsigned_integral>; + struct text; template using is_text_t = std::is_same, text>; @@ -89,7 +93,7 @@ namespace sqlpp // joined data type template - using is_numeric_t = logic::any_t::value, is_floating_point_t::value>; + using is_numeric_t = logic::any_t::value, is_unsigned_integral_t::value, is_floating_point_t::value>; template using is_day_or_time_point_t = logic::any_t::value, is_time_point_t::value>; diff --git a/tests/Sample.h b/tests/Sample.h index 0bb6dc51..bd9b30ea 100644 --- a/tests/Sample.h +++ b/tests/Sample.h @@ -75,9 +75,31 @@ namespace test }; using _traits = sqlpp::make_traits; }; + struct Psi + { + struct _alias_t + { + static constexpr const char _literal[] = "psi"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t + { + T psi; + T& operator()() + { + return psi; + } + const T& operator()() const + { + return psi; + } + }; + }; + using _traits = sqlpp::make_traits; + }; } - struct TabFoo : sqlpp::table_t + struct TabFoo : sqlpp::table_t { struct _alias_t { diff --git a/tests/SelectType.cpp b/tests/SelectType.cpp index 712491e0..ce5bd2d8 100644 --- a/tests/SelectType.cpp +++ b/tests/SelectType.cpp @@ -108,6 +108,7 @@ int SelectType(int, char* []) using T = decltype(t.alpha); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(sqlpp::is_integral_t::value, "type requirement"); + static_assert(not sqlpp::is_unsigned_integral_t::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t::value, "type requirement"); static_assert(sqlpp::is_expression_t::value, "type requirement"); static_assert(sqlpp::is_selectable_t::value, "type requirement"); @@ -121,6 +122,23 @@ int SelectType(int, char* []) static_assert(sqlpp::is_regular::value, "type requirement"); } + // Test an unsigned integral table column + { + using T = decltype(f.psi); + static_assert(sqlpp::is_numeric_t::value, "type requirement"); + static_assert(not sqlpp::is_integral_t::value, "type requirement"); + static_assert(sqlpp::is_unsigned_integral_t::value, "type requirement"); + static_assert(not sqlpp::is_floating_point_t::value, "type requirement"); + static_assert(sqlpp::is_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); + static_assert(not sqlpp::require_insert_t::value, "type requirement"); + static_assert(not sqlpp::is_boolean_t::value, "type requirement"); + static_assert(not sqlpp::is_text_t::value, "type requirement"); + static_assert(not sqlpp::is_alias_t::value, "type requirement"); + static_assert(not sqlpp::is_table_t::value, "type requirement"); + static_assert(sqlpp::is_regular::value, "type requirement"); + } + // Test a floating point table column { using T = decltype(f.omega); diff --git a/tests/sample.sql b/tests/sample.sql index fc420fd0..5ebabf00 100644 --- a/tests/sample.sql +++ b/tests/sample.sql @@ -28,7 +28,8 @@ CREATE TABLE tab_foo ( delta varchar(255), epsilon bigint, - omega double + omega double, + psi bigint UNSIGNED ); CREATE TABLE tab_bar From 58256e2b797f08c35b6fa323b384c1fe652e6cbf Mon Sep 17 00:00:00 2001 From: Aaron Bishop Date: Fri, 20 May 2016 07:28:08 -0400 Subject: [PATCH 05/15] removed time in favor of feature/time_of_day --- include/sqlpp11/data_types/time_point/data_type.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/sqlpp11/data_types/time_point/data_type.h b/include/sqlpp11/data_types/time_point/data_type.h index 41bc7eca..374520dc 100644 --- a/include/sqlpp11/data_types/time_point/data_type.h +++ b/include/sqlpp11/data_types/time_point/data_type.h @@ -43,6 +43,5 @@ namespace sqlpp using datetime = time_point; using timestamp = time_point; - using time = time_point; } #endif From 6bdf5ef1ee03b8ec784fd396a98723e4d136c016 Mon Sep 17 00:00:00 2001 From: Aaron Bishop Date: Mon, 23 May 2016 08:16:27 -0400 Subject: [PATCH 06/15] updated copyright --- include/sqlpp11/chrono.h | 2 +- include/sqlpp11/data_types.h | 2 +- include/sqlpp11/data_types/integral/expression_operators.h | 2 +- include/sqlpp11/data_types/integral/wrap_operand.h | 2 +- include/sqlpp11/data_types/unsigned_integral.h | 2 +- include/sqlpp11/data_types/unsigned_integral/data_type.h | 2 +- .../sqlpp11/data_types/unsigned_integral/expression_operators.h | 2 +- include/sqlpp11/data_types/unsigned_integral/operand.h | 2 +- include/sqlpp11/data_types/unsigned_integral/parameter_value.h | 2 +- include/sqlpp11/data_types/unsigned_integral/result_field.h | 2 +- include/sqlpp11/data_types/unsigned_integral/wrap_operand.h | 2 +- include/sqlpp11/type_traits.h | 2 +- tests/SelectType.cpp | 2 +- tests/sample.sql | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/sqlpp11/chrono.h b/include/sqlpp11/chrono.h index ab91d746..3625bc6b 100644 --- a/include/sqlpp11/chrono.h +++ b/include/sqlpp11/chrono.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2015, Roland Bock + * Copyright (c) 2015-2016, Roland Bock, Aaron Bishop * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, diff --git a/include/sqlpp11/data_types.h b/include/sqlpp11/data_types.h index eee711bc..fbe76392 100644 --- a/include/sqlpp11/data_types.h +++ b/include/sqlpp11/data_types.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, diff --git a/include/sqlpp11/data_types/integral/expression_operators.h b/include/sqlpp11/data_types/integral/expression_operators.h index e42637f1..0633e533 100644 --- a/include/sqlpp11/data_types/integral/expression_operators.h +++ b/include/sqlpp11/data_types/integral/expression_operators.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, diff --git a/include/sqlpp11/data_types/integral/wrap_operand.h b/include/sqlpp11/data_types/integral/wrap_operand.h index 1a07838a..d6381b67 100644 --- a/include/sqlpp11/data_types/integral/wrap_operand.h +++ b/include/sqlpp11/data_types/integral/wrap_operand.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, diff --git a/include/sqlpp11/data_types/unsigned_integral.h b/include/sqlpp11/data_types/unsigned_integral.h index ba0a98ff..b37cdbaa 100644 --- a/include/sqlpp11/data_types/unsigned_integral.h +++ b/include/sqlpp11/data_types/unsigned_integral.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, diff --git a/include/sqlpp11/data_types/unsigned_integral/data_type.h b/include/sqlpp11/data_types/unsigned_integral/data_type.h index 68e061aa..9a4d4269 100644 --- a/include/sqlpp11/data_types/unsigned_integral/data_type.h +++ b/include/sqlpp11/data_types/unsigned_integral/data_type.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, diff --git a/include/sqlpp11/data_types/unsigned_integral/expression_operators.h b/include/sqlpp11/data_types/unsigned_integral/expression_operators.h index 0ce3b0e1..62eaf03d 100644 --- a/include/sqlpp11/data_types/unsigned_integral/expression_operators.h +++ b/include/sqlpp11/data_types/unsigned_integral/expression_operators.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, diff --git a/include/sqlpp11/data_types/unsigned_integral/operand.h b/include/sqlpp11/data_types/unsigned_integral/operand.h index d117b6fa..2fa70619 100644 --- a/include/sqlpp11/data_types/unsigned_integral/operand.h +++ b/include/sqlpp11/data_types/unsigned_integral/operand.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, diff --git a/include/sqlpp11/data_types/unsigned_integral/parameter_value.h b/include/sqlpp11/data_types/unsigned_integral/parameter_value.h index 9b596d33..c7ed7548 100644 --- a/include/sqlpp11/data_types/unsigned_integral/parameter_value.h +++ b/include/sqlpp11/data_types/unsigned_integral/parameter_value.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, diff --git a/include/sqlpp11/data_types/unsigned_integral/result_field.h b/include/sqlpp11/data_types/unsigned_integral/result_field.h index 960ccc1a..1a54eaa9 100644 --- a/include/sqlpp11/data_types/unsigned_integral/result_field.h +++ b/include/sqlpp11/data_types/unsigned_integral/result_field.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, diff --git a/include/sqlpp11/data_types/unsigned_integral/wrap_operand.h b/include/sqlpp11/data_types/unsigned_integral/wrap_operand.h index d12a5af6..501d4a55 100644 --- a/include/sqlpp11/data_types/unsigned_integral/wrap_operand.h +++ b/include/sqlpp11/data_types/unsigned_integral/wrap_operand.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index 08a3f9fe..3ebe00ef 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, diff --git a/tests/SelectType.cpp b/tests/SelectType.cpp index ce5bd2d8..2c72f32f 100644 --- a/tests/SelectType.cpp +++ b/tests/SelectType.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2016, Roland Bock + * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, diff --git a/tests/sample.sql b/tests/sample.sql index 5ebabf00..e6ff21bd 100644 --- a/tests/sample.sql +++ b/tests/sample.sql @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, From 2f1f34d0b1a84011de837be21f541eb2ec6394b8 Mon Sep 17 00:00:00 2001 From: Aaron Bishop Date: Mon, 23 May 2016 08:24:35 -0400 Subject: [PATCH 07/15] fixed some expressions, added tests --- .../integral/expression_operators.h | 36 ++++++++++++++++--- .../unsigned_integral/expression_operators.h | 21 +++++++---- include/sqlpp11/type_traits.h | 3 ++ tests/SelectType.cpp | 23 ++++++++++++ 4 files changed, 73 insertions(+), 10 deletions(-) diff --git a/include/sqlpp11/data_types/integral/expression_operators.h b/include/sqlpp11/data_types/integral/expression_operators.h index 0633e533..445703b5 100644 --- a/include/sqlpp11/data_types/integral/expression_operators.h +++ b/include/sqlpp11/data_types/integral/expression_operators.h @@ -43,33 +43,61 @@ namespace sqlpp }; template - struct return_type_plus> + struct return_type_plus> { using check = consistent_t; using type = plus_t, value_type_of>, wrap_operand_t>; }; template - struct return_type_minus> + struct return_type_plus> + { + using check = consistent_t; + using type = integral; + }; + + template + struct return_type_minus> { using check = consistent_t; using type = minus_t, value_type_of>, wrap_operand_t>; }; template - struct return_type_multiplies> + struct return_type_minus> + { + using check = consistent_t; + using type = integral; + }; + + template + struct return_type_multiplies> { using check = consistent_t; using type = multiplies_t, value_type_of>, wrap_operand_t>; }; template - struct return_type_divides> + struct return_type_multiplies> + { + using check = consistent_t; + using type = integral; + }; + + template + struct return_type_divides> { using check = consistent_t; using type = divides_t, wrap_operand_t>; }; + template + struct return_type_divides> + { + using check = consistent_t; + using type = integral; + }; + template struct return_type_modulus> { diff --git a/include/sqlpp11/data_types/unsigned_integral/expression_operators.h b/include/sqlpp11/data_types/unsigned_integral/expression_operators.h index 62eaf03d..1c016102 100644 --- a/include/sqlpp11/data_types/unsigned_integral/expression_operators.h +++ b/include/sqlpp11/data_types/unsigned_integral/expression_operators.h @@ -37,6 +37,8 @@ namespace sqlpp { + struct integral; + template struct expression_operators : public basic_expression_operators { @@ -46,28 +48,35 @@ namespace sqlpp struct return_type_plus> { using check = consistent_t; - using type = plus_t, value_type_of>, wrap_operand_t>; + using type = value_type_of>; }; template - struct return_type_minus> + struct return_type_minus> { using check = consistent_t; - using type = minus_t, value_type_of>, wrap_operand_t>; + using type = value_type_of>; + }; + + template + struct return_type_minus> + { + using check = consistent_t; + using type = minus_t, integral, wrap_operand_t>; }; template struct return_type_multiplies> { using check = consistent_t; - using type = multiplies_t, value_type_of>, wrap_operand_t>; + using type = value_type_of>; }; template struct return_type_divides> { using check = consistent_t; - using type = divides_t, wrap_operand_t>; + using type = value_type_of>; }; template @@ -88,7 +97,7 @@ namespace sqlpp struct return_type_unary_minus> { using check = consistent_t; - using type = unary_minus_t>; + using type = unary_minus_t>; }; template diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index 3ebe00ef..d7d3adaa 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -95,6 +95,9 @@ namespace sqlpp template using is_numeric_t = logic::any_t::value, is_unsigned_integral_t::value, is_floating_point_t::value>; + template + using is_numeric_not_unsigned_t = logic::any_t::value, not is_unsigned_integral_t::value, is_floating_point_t::value>; + template using is_day_or_time_point_t = logic::any_t::value, is_time_point_t::value>; diff --git a/tests/SelectType.cpp b/tests/SelectType.cpp index 2c72f32f..26b7857b 100644 --- a/tests/SelectType.cpp +++ b/tests/SelectType.cpp @@ -137,6 +137,29 @@ int SelectType(int, char* []) static_assert(not sqlpp::is_alias_t::value, "type requirement"); static_assert(not sqlpp::is_table_t::value, "type requirement"); static_assert(sqlpp::is_regular::value, "type requirement"); + //subtraction on unsigned makes it signed + static_assert(sqlpp::is_integral_t>::value, "type requirement"); + static_assert(sqlpp::is_integral_t>::value, "type requirement"); + //any operation on float makes it float + static_assert(sqlpp::is_floating_point_t>::value, "type requirement"); + static_assert(sqlpp::is_floating_point_t>::value, "type requirement"); + static_assert(sqlpp::is_floating_point_t>::value, "type requirement"); + static_assert(sqlpp::is_floating_point_t>::value, "type requirement"); + static_assert(sqlpp::is_floating_point_t>::value, "type requirement"); + static_assert(sqlpp::is_floating_point_t>::value, "type requirement"); + static_assert(sqlpp::is_floating_point_t>::value, "type requirement"); + static_assert(sqlpp::is_floating_point_t>::value, "type requirement"); + static_assert(sqlpp::is_floating_point_t>::value, "type requirement"); + //signed operation on unsigned makes it signed + static_assert(sqlpp::is_integral_t>::value, "type requirement"); + static_assert(sqlpp::is_integral_t>::value, "type requirement"); + static_assert(sqlpp::is_integral_t>::value, "type requirement"); + static_assert(sqlpp::is_integral_t>::value, "type requirement"); + static_assert(sqlpp::is_integral_t>::value, "type requirement"); + static_assert(sqlpp::is_integral_t>::value, "type requirement"); + static_assert(sqlpp::is_integral_t>::value, "type requirement"); + static_assert(sqlpp::is_integral_t>::value, "type requirement"); + static_assert(sqlpp::is_integral_t>::value, "type requirement"); } // Test a floating point table column From efeefa817950e9555c36546f19f1772316510280 Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 4 Jun 2016 09:58:12 +0200 Subject: [PATCH 08/15] Some more portable static_asserts. --- include/sqlpp11/insert_value_list.h | 12 ++--- include/sqlpp11/select_column_list.h | 2 +- include/sqlpp11/update_list.h | 75 ++++++++++++++++++---------- test_static_asserts/insert.cpp | 12 ++--- 4 files changed, 62 insertions(+), 39 deletions(-) diff --git a/include/sqlpp11/insert_value_list.h b/include/sqlpp11/insert_value_list.h index 391af7a9..2cae2a63 100644 --- a/include/sqlpp11/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -145,9 +145,9 @@ namespace sqlpp SQLPP_PORTABLE_STATIC_ASSERT(assert_insert_set_assignments_t, "at least one argument is not an assignment in set()"); SQLPP_PORTABLE_STATIC_ASSERT(assert_insert_set_no_duplicates_t, "at least one duplicate column detected in set()"); - SQLPP_PORTABLE_STATIC_ASSERT(assert_insert_set_prohibited_t, + SQLPP_PORTABLE_STATIC_ASSERT(assert_insert_set_allowed_t, "at least one assignment is prohibited by its column definition in set()"); - SQLPP_PORTABLE_STATIC_ASSERT(assert_insert_set_one_table_t, + SQLPP_PORTABLE_STATIC_ASSERT(assert_insert_set_single_table_t, "set() arguments contain assignments from more than one table"); SQLPP_PORTABLE_STATIC_ASSERT(assert_insert_static_set_count_args_t, "at least one assignment expression required in set()"); @@ -163,10 +163,10 @@ namespace sqlpp // static_check_t::value...>::value, assert_insert_set_assignments_t>, // static_check_t...>::value, assert_insert_set_no_duplicates_t>, // static_check_t>::value...>::value, - // assert_insert_set_prohibited_t>, + // assert_insert_set_allowed_t>, // static_check_t>...>::size::value == 1, - // assert_insert_set_one_table_t>>; + // assert_insert_set_single_table_t>>; template struct must_not_insert @@ -180,11 +180,11 @@ namespace sqlpp assert_insert_set_assignments_t>, static_check_t::type...>::value, assert_insert_set_no_duplicates_t>, - static_check_t::value...>::value, assert_insert_set_prohibited_t>, + static_check_t::value...>::value, assert_insert_set_allowed_t>, static_check_t< sizeof...(Assignments) == 0 or detail::make_joined_set_t::type>...>::size::value == 1, - assert_insert_set_one_table_t>>; + assert_insert_set_single_table_t>>; // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 // template diff --git a/include/sqlpp11/select_column_list.h b/include/sqlpp11/select_column_list.h index d96cf2e3..19f79eac 100644 --- a/include/sqlpp11/select_column_list.h +++ b/include/sqlpp11/select_column_list.h @@ -92,7 +92,7 @@ namespace sqlpp assert_no_unknown_tables_in_selected_columns_t, "at least one selected column requires a table which is otherwise not known in the statement"); SQLPP_PORTABLE_STATIC_ASSERT(assert_no_unknown_aggregates_t, - "not all columns are made of aggregates, despite group_by or similar"); + "not all selected columns are made of aggregates, despite group_by or similar"); // SELECTED COLUMNS template diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index ab4af1b0..a3c1b625 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -147,6 +147,47 @@ namespace sqlpp SQLPP_PORTABLE_STATIC_ASSERT(assert_update_assignments_t, "update assignments required, i.e. set(...)"); + SQLPP_PORTABLE_STATIC_ASSERT(assert_update_set_assignments_t, "at least one argument is not an assignment in set()"); + SQLPP_PORTABLE_STATIC_ASSERT(assert_update_set_no_duplicates_t, "at least one duplicate column detected in set()"); + SQLPP_PORTABLE_STATIC_ASSERT(assert_update_set_allowed_t, + "at least one assignment is prohibited by its column definition in set()"); + SQLPP_PORTABLE_STATIC_ASSERT(assert_update_set_single_table_t, + "set() contains assignments for columns from more than one table"); + SQLPP_PORTABLE_STATIC_ASSERT(assert_update_set_count_args_t, "at least one assignment expression required in set()"); + SQLPP_PORTABLE_STATIC_ASSERT(assert_update_dynamic_set_statement_dynamic_t, + "dynamic_set() must not be called in a static statement"); + template + using check_update_set_t = static_combined_check_t< + static_check_t::value...>::value, assert_update_set_assignments_t>, + static_check_t::type...>::value, + assert_update_set_no_duplicates_t>, + static_check_t::value...>::value, assert_update_set_allowed_t>, + static_check_t< + sizeof...(Assignments) == 0 or + detail::make_joined_set_t::type>...>::size::value == 1, + assert_update_set_single_table_t>>; + + template + struct check_update_static_set + { + using type = static_combined_check_t, + static_check_t>; + }; + + template + using check_update_static_set_t = typename check_update_static_set::type; + + template + struct check_update_dynamic_set + { + using type = static_combined_check_t< + static_check_t::value, assert_update_dynamic_set_statement_dynamic_t>, + check_update_set_t>; + }; + + template + using check_update_dynamic_set_t = typename check_update_dynamic_set::type; + struct no_update_list_t { using _traits = make_traits; @@ -199,14 +240,6 @@ namespace sqlpp using _database_t = typename Policies::_database_t; - // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 - // template - // using _check = logic::all_t::value...>; - template - struct _check : public logic::all_t::value...> - { - }; - template using _new_statement_t = new_statement_t; @@ -214,23 +247,22 @@ namespace sqlpp template auto set(Assignments... assignments) const - -> _new_statement_t<_check, update_list_t> + -> _new_statement_t, update_list_t> { - static_assert(sizeof...(Assignments), "at least one assignment expression required in set()"); - static_assert(_check::value, "at least one argument is not an assignment in set()"); + using Check = check_update_static_set_t; + Check{}._(); - return _set_impl(_check{}, assignments...); + return _set_impl(Check{}, assignments...); } template auto dynamic_set(Assignments... assignments) const - -> _new_statement_t<_check, update_list_t<_database_t, Assignments...>> + -> _new_statement_t, update_list_t<_database_t, Assignments...>> { - static_assert(not std::is_same<_database_t, void>::value, - "dynamic_set() must not be called in a static statement"); - static_assert(_check::value, "at least one argument is not an assignment in set()"); + using Check = check_update_dynamic_set_t; + Check{}._(); - return _set_impl<_database_t>(_check{}, assignments...); + return _set_impl<_database_t>(Check{}, assignments...); } private: @@ -241,15 +273,6 @@ namespace sqlpp auto _set_impl(const std::true_type&, Assignments... assignments) const -> _new_statement_t> { - static_assert(not detail::has_duplicates...>::value, - "at least one duplicate column detected in set()"); - static_assert(logic::none_t>::value...>::value, - "at least one assignment is prohibited by its column definition in set()"); - - using _column_required_tables = detail::make_joined_set_t>...>; - static_assert(sizeof...(Assignments) ? (_column_required_tables::size::value == 1) : true, - "set() contains assignments for columns from more than one table"); - return {static_cast&>(*this), update_list_data_t{assignments...}}; } diff --git a/test_static_asserts/insert.cpp b/test_static_asserts/insert.cpp index 2236add0..9a37014b 100644 --- a/test_static_asserts/insert.cpp +++ b/test_static_asserts/insert.cpp @@ -87,8 +87,8 @@ namespace set_static_check(t.gamma = true, t.delta = 42, t.beta = "fortytwo"); // Try setting alpha - set_static_check(t.alpha = 17, t.beta = "whatever"); - set_static_check(t.beta = "whatever", t.alpha = 17); + set_static_check(t.alpha = 17, t.beta = "whatever"); + set_static_check(t.beta = "whatever", t.alpha = 17); // Try omitting gamma set_static_check(t.delta = 42); @@ -112,7 +112,7 @@ namespace t.gamma = true); // Try multiple tables - set_static_check(f.omega = 41, t.gamma = true); + set_static_check(f.omega = 41, t.gamma = true); } // column alpha is not allowed, column gamma is required @@ -127,8 +127,8 @@ namespace set_dynamic_check(t.gamma = true, t.delta = 42, t.beta = "fortytwo"); // Try setting alpha - set_dynamic_check(t.alpha = 17, t.beta = "whatever"); - set_dynamic_check(t.beta = "whatever", t.alpha = 17); + set_dynamic_check(t.alpha = 17, t.beta = "whatever"); + set_dynamic_check(t.beta = "whatever", t.alpha = 17); // Omitting gamma is OK in the dynamic case, since we have to assume that it gets added later set_dynamic_check(t.delta = 42); @@ -153,7 +153,7 @@ namespace t.gamma = true); // Try multiple tables - set_dynamic_check(f.omega = 41, t.gamma = true); + set_dynamic_check(f.omega = 41, t.gamma = true); // Try dynamic_set on a non-dynamic insert using CheckResult = sqlpp::check_insert_dynamic_set_t; From 1327699f90916b07ff0a9f063b95e47a017f895f Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 5 Jun 2016 21:23:16 +0200 Subject: [PATCH 09/15] Fixed check for updating fields that must not be updated --- include/sqlpp11/update_list.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index a3c1b625..fcdb5b2a 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -161,7 +161,8 @@ namespace sqlpp static_check_t::value...>::value, assert_update_set_assignments_t>, static_check_t::type...>::value, assert_update_set_no_duplicates_t>, - static_check_t::value...>::value, assert_update_set_allowed_t>, + static_check_t::type>::value...>::value, + assert_update_set_allowed_t>, static_check_t< sizeof...(Assignments) == 0 or detail::make_joined_set_t::type>...>::size::value == 1, From 03ab507f696cac4be19bc045bb3d67d258c2959c Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 5 Jun 2016 21:35:49 +0200 Subject: [PATCH 10/15] Some formatting --- include/sqlpp11/chrono.h | 2 +- include/sqlpp11/type_traits.h | 6 ++++-- tests/DateTime.cpp | 6 ++++-- tests/Sample.h | 5 +++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/sqlpp11/chrono.h b/include/sqlpp11/chrono.h index 0e65fad3..49ae37d8 100644 --- a/include/sqlpp11/chrono.h +++ b/include/sqlpp11/chrono.h @@ -45,7 +45,7 @@ namespace sqlpp using ::date::floor; #endif - template + template std::chrono::microseconds time_of_day(T t) { const auto dp = floor(t); diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index f4699233..cf377f07 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -97,10 +97,12 @@ namespace sqlpp // joined data type template - using is_numeric_t = logic::any_t::value, is_unsigned_integral_t::value, is_floating_point_t::value>; + using is_numeric_t = + logic::any_t::value, is_unsigned_integral_t::value, is_floating_point_t::value>; template - using is_numeric_not_unsigned_t = logic::any_t::value, not is_unsigned_integral_t::value, is_floating_point_t::value>; + using is_numeric_not_unsigned_t = + logic::any_t::value, not is_unsigned_integral_t::value, is_floating_point_t::value>; template using is_day_or_time_point_t = logic::any_t::value, is_time_point_t::value>; diff --git a/tests/DateTime.cpp b/tests/DateTime.cpp index 4f042a9c..2e3a6f0c 100644 --- a/tests/DateTime.cpp +++ b/tests/DateTime.cpp @@ -64,10 +64,12 @@ int DateTime(int, char* []) .set(t.colDayPoint = floor<::sqlpp::chrono::days>(std::chrono::system_clock::now())) .where(t.colDayPoint < std::chrono::system_clock::now())); db(update(t) - .set(t.colTimePoint = floor<::sqlpp::chrono::days>(std::chrono::system_clock::now()), t.colTimeOfDay = ::sqlpp::chrono::time_of_day(std::chrono::system_clock::now())) + .set(t.colTimePoint = floor<::sqlpp::chrono::days>(std::chrono::system_clock::now()), + t.colTimeOfDay = ::sqlpp::chrono::time_of_day(std::chrono::system_clock::now())) .where(t.colDayPoint < std::chrono::system_clock::now())); db(update(t) - .set(t.colTimePoint = std::chrono::system_clock::now(), t.colTimeOfDay = ::sqlpp::chrono::time_of_day(std::chrono::system_clock::now())) + .set(t.colTimePoint = std::chrono::system_clock::now(), + t.colTimeOfDay = ::sqlpp::chrono::time_of_day(std::chrono::system_clock::now())) .where(t.colDayPoint < std::chrono::system_clock::now())); db(remove_from(t).where(t.colDayPoint == floor<::sqlpp::chrono::days>(std::chrono::system_clock::now()))); diff --git a/tests/Sample.h b/tests/Sample.h index 7385deee..15e7ee69 100644 --- a/tests/Sample.h +++ b/tests/Sample.h @@ -96,7 +96,7 @@ namespace test }; }; using _traits = sqlpp::make_traits; - }; + }; } struct TabFoo : sqlpp::table_t @@ -306,7 +306,8 @@ namespace test }; } - struct TabDateTime : sqlpp::table_t + struct TabDateTime + : sqlpp::table_t { struct _alias_t { From c65cc7dc648ba50feb22fd732b9c7aedfadb787d Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 5 Jun 2016 21:36:08 +0200 Subject: [PATCH 11/15] Added README to examples, hoping to avoid confusion --- examples/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 examples/README.md diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 00000000..b903cdb6 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,5 @@ +These examples were used for a talk at CppCon 2014 and are kept here for reference. + +They are probably not self explanatory. + +It is certainly more useful to look into the Wiki for documentation. From fe5f2ef2ef046606e52280c63148c392c0f5565e Mon Sep 17 00:00:00 2001 From: Aaron Bishop Date: Tue, 7 Jun 2016 20:43:22 -0400 Subject: [PATCH 12/15] removed datetime and timestamp --- include/sqlpp11/data_types/time_point/data_type.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/sqlpp11/data_types/time_point/data_type.h b/include/sqlpp11/data_types/time_point/data_type.h index 374520dc..ad3f727e 100644 --- a/include/sqlpp11/data_types/time_point/data_type.h +++ b/include/sqlpp11/data_types/time_point/data_type.h @@ -40,8 +40,5 @@ namespace sqlpp template using _is_valid_operand = is_day_or_time_point_t; }; - - using datetime = time_point; - using timestamp = time_point; } #endif From 2d34e57c8f97093c45ccfba38a152197fe240f68 Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 18 Jun 2016 18:28:53 +0200 Subject: [PATCH 13/15] Hopefully fixing MSVC compile problem --- include/sqlpp11/update_list.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index fcdb5b2a..254a21ba 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -158,11 +158,13 @@ namespace sqlpp "dynamic_set() must not be called in a static statement"); template using check_update_set_t = static_combined_check_t< - static_check_t::value...>::value, assert_update_set_assignments_t>, + static_check_t::type::value...>::value, + assert_update_set_assignments_t>, static_check_t::type...>::value, assert_update_set_no_duplicates_t>, - static_check_t::type>::value...>::value, - assert_update_set_allowed_t>, + static_check_t< + logic::none_t::type>::type::value...>::value, + assert_update_set_allowed_t>, static_check_t< sizeof...(Assignments) == 0 or detail::make_joined_set_t::type>...>::size::value == 1, From aeb1ab5e0279b83210539772641ae5c3524bb352 Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 18 Jun 2016 18:54:16 +0200 Subject: [PATCH 14/15] Next attempt to pacify MSVC... --- include/sqlpp11/update_list.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index 254a21ba..d447c8a2 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -156,15 +156,23 @@ namespace sqlpp SQLPP_PORTABLE_STATIC_ASSERT(assert_update_set_count_args_t, "at least one assignment expression required in set()"); SQLPP_PORTABLE_STATIC_ASSERT(assert_update_dynamic_set_statement_dynamic_t, "dynamic_set() must not be called in a static statement"); + namespace detail + { + template + struct lhs_must_not_update + { + static constexpr auto value = detail::must_not_update_impl::type>::type::value; + }; + } + template using check_update_set_t = static_combined_check_t< static_check_t::type::value...>::value, assert_update_set_assignments_t>, static_check_t::type...>::value, assert_update_set_no_duplicates_t>, - static_check_t< - logic::none_t::type>::type::value...>::value, - assert_update_set_allowed_t>, + static_check_t::value...>::value, + assert_update_set_allowed_t>, static_check_t< sizeof...(Assignments) == 0 or detail::make_joined_set_t::type>...>::size::value == 1, From 949f1abfc9d14b44d33c9610b9a0517aa78ae4bc Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 19 Jun 2016 10:41:31 +0200 Subject: [PATCH 15/15] Added static_assert tests for update set/dynamic_set --- include/sqlpp11/update_list.h | 5 +- test_static_asserts/CMakeLists.txt | 1 + test_static_asserts/update_list.cpp | 140 ++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 test_static_asserts/update_list.cpp diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index d447c8a2..c7dc360c 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -268,9 +268,10 @@ namespace sqlpp template auto dynamic_set(Assignments... assignments) const - -> _new_statement_t, update_list_t<_database_t, Assignments...>> + -> _new_statement_t, + update_list_t<_database_t, Assignments...>> { - using Check = check_update_dynamic_set_t; + using Check = check_update_dynamic_set_t<_database_t, Assignments...>; Check{}._(); return _set_impl<_database_t>(Check{}, assignments...); diff --git a/test_static_asserts/CMakeLists.txt b/test_static_asserts/CMakeLists.txt index d1b8c542..f9b76f35 100644 --- a/test_static_asserts/CMakeLists.txt +++ b/test_static_asserts/CMakeLists.txt @@ -33,6 +33,7 @@ test_compile(case) test_compile(from) test_compile(join) test_compile(where) +test_compile(update_list) test_compile(having) test_compile(insert) test_compile(in) diff --git a/test_static_asserts/update_list.cpp b/test_static_asserts/update_list.cpp new file mode 100644 index 00000000..06838013 --- /dev/null +++ b/test_static_asserts/update_list.cpp @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2016-2016, 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 "MockDb.h" +#include "Sample.h" +#include + +namespace +{ + constexpr auto t = test::TabBar{}; + constexpr auto f = test::TabFoo{}; + + template + void print_type_on_error(std::true_type) + { + } + + template + void print_type_on_error(std::false_type) + { + T::_print_me_; + } + + template + void update_set_static_check(const Expressions&... expressions) + { + using CheckResult = sqlpp::check_update_static_set_t; + using ExpectedCheckResult = std::is_same; + print_type_on_error(ExpectedCheckResult{}); + static_assert(ExpectedCheckResult::value, "Unexpected check result"); + + using ReturnType = decltype(update(t).set(expressions...)); + using ExpectedReturnType = + sqlpp::logic::all_t::value>; + print_type_on_error(ExpectedReturnType{}); + static_assert(ExpectedReturnType::value, "Unexpected return type"); + } + + template + void update_set_dynamic_check(const Expressions&... expressions) + { + static auto db = MockDb{}; + using CheckResult = sqlpp::check_update_dynamic_set_t; + using ExpectedCheckResult = std::is_same; + print_type_on_error(ExpectedCheckResult{}); + static_assert(ExpectedCheckResult::value, "Unexpected check result"); + + using ReturnType = decltype(dynamic_update(db, t).dynamic_set(expressions...)); + using ExpectedReturnType = + sqlpp::logic::all_t::value>; + print_type_on_error(ExpectedReturnType{}); + static_assert(ExpectedReturnType::value, "Unexpected return type"); + } + + void static_update_set() + { + // OK + update_set_static_check(t.gamma = true); + update_set_static_check(t.gamma = true, t.beta = ""); + + // Try to update nothing + update_set_static_check(); + + // Try condition as assignment + update_set_static_check(t.gamma == true); + + // Try duplicate columns + update_set_static_check(t.gamma = true, t.gamma = false); + update_set_static_check(t.gamma = true, t.beta = "", t.gamma = false); + + // Try to update prohibited columns + update_set_static_check(t.alpha = 42); + + // Try to update multiple tables at once + update_set_static_check(t.gamma = true, f.omega = 7); + } + + void dynamic_update_set() + { + // OK + update_set_dynamic_check(t.gamma = true); + update_set_dynamic_check(t.gamma = true, t.beta = ""); + + // Try to update nothing + update_set_dynamic_check(); + + // Try condition as assignment + update_set_dynamic_check(t.gamma == true); + + // Try duplicate columns + update_set_dynamic_check(t.gamma = true, t.gamma = false); + update_set_dynamic_check(t.gamma = true, t.beta = "", t.gamma = false); + + // Try to update prohibited columns + update_set_dynamic_check(t.alpha = 42); + + // Try to update multiple tables at once + update_set_dynamic_check(t.gamma = true, f.omega = 7); + + // Try dynamic_set on a non-dynamic update + using CheckResult = sqlpp::check_update_dynamic_set_t; + using ExpectedCheckResult = std::is_same; + print_type_on_error(ExpectedCheckResult{}); + static_assert(ExpectedCheckResult::value, "Unexpected check result"); + + using ReturnType = decltype(update(t).dynamic_set()); + using ExpectedReturnType = std::is_same; + print_type_on_error(ExpectedReturnType{}); + static_assert(ExpectedReturnType::value, "Unexpected return type"); + } +} + +int main(int, char* []) +{ + static_update_set(); + dynamic_update_set(); +}