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. diff --git a/include/sqlpp11/chrono.h b/include/sqlpp11/chrono.h index 1ab77523..49ae37d8 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, @@ -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..92a9c9ae 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, @@ -29,9 +29,11 @@ #include #include +#include #include #include #include +#include #include #include 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/integral/expression_operators.h b/include/sqlpp11/data_types/integral/expression_operators.h index e42637f1..445703b5 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, @@ -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/integral/wrap_operand.h b/include/sqlpp11/data_types/integral/wrap_operand.h index a395b864..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, @@ -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/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_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..511fe8d6 --- /dev/null +++ b/include/sqlpp11/data_types/time_of_day/result_field.h @@ -0,0 +1,72 @@ +/* + * 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 + { + os << ::date::make_time(e.value()); + } + 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/data_types/unsigned_integral.h b/include/sqlpp11/data_types/unsigned_integral.h new file mode 100644 index 00000000..b37cdbaa --- /dev/null +++ b/include/sqlpp11/data_types/unsigned_integral.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop + * 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..9a4d4269 --- /dev/null +++ b/include/sqlpp11/data_types/unsigned_integral/data_type.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop + * 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..1c016102 --- /dev/null +++ b/include/sqlpp11/data_types/unsigned_integral/expression_operators.h @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop + * 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 +{ + struct integral; + + template + struct expression_operators : public basic_expression_operators + { + }; + + template + struct return_type_plus> + { + using check = consistent_t; + using type = value_type_of>; + }; + + template + struct return_type_minus> + { + using check = consistent_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 = value_type_of>; + }; + + template + struct return_type_divides> + { + using check = consistent_t; + using type = value_type_of>; + }; + + 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..2fa70619 --- /dev/null +++ b/include/sqlpp11/data_types/unsigned_integral/operand.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop + * 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..c7ed7548 --- /dev/null +++ b/include/sqlpp11/data_types/unsigned_integral/parameter_value.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop + * 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..1a54eaa9 --- /dev/null +++ b/include/sqlpp11/data_types/unsigned_integral/result_field.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop + * 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..501d4a55 --- /dev/null +++ b/include/sqlpp11/data_types/unsigned_integral/wrap_operand.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop + * 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/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/type_traits.h b/include/sqlpp11/type_traits.h index 1b2d33ea..cf377f07 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, @@ -79,17 +79,30 @@ 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>; + 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>; // 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_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/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index ab4af1b0..c7dc360c 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -147,6 +147,58 @@ 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"); + 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::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 +251,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 +258,23 @@ 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<_database_t, Assignments...>; + Check{}._(); - return _set_impl<_database_t>(_check{}, assignments...); + return _set_impl<_database_t>(Check{}, assignments...); } private: @@ -241,15 +285,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/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/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; 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(); +} diff --git a/tests/DateTime.cpp b/tests/DateTime.cpp index 669b69a7..2e3a6f0c 100644 --- a/tests/DateTime.cpp +++ b/tests/DateTime.cpp @@ -58,21 +58,25 @@ 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..15e7ee69 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 { @@ -259,9 +281,33 @@ 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 { diff --git a/tests/SelectType.cpp b/tests/SelectType.cpp index 712491e0..26b7857b 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, @@ -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,46 @@ 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"); + //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 { using T = decltype(f.omega); diff --git a/tests/sample.sql b/tests/sample.sql index fc420fd0..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, @@ -28,7 +28,8 @@ CREATE TABLE tab_foo ( delta varchar(255), epsilon bigint, - omega double + omega double, + psi bigint UNSIGNED ); CREATE TABLE tab_bar