0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 04:47:18 +08:00

Merge branch 'release/0.39'

This commit is contained in:
rbock 2016-06-19 11:59:28 +02:00
commit d061010fc3
35 changed files with 1320 additions and 57 deletions

5
examples/README.md Normal file
View File

@ -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.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015-2015, Roland Bock * Copyright (c) 2015-2016, Roland Bock, Aaron Bishop
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
@ -44,6 +44,13 @@ namespace sqlpp
#else #else
using ::date::floor; using ::date::floor;
#endif #endif
template <typename T>
std::chrono::microseconds time_of_day(T t)
{
const auto dp = floor<days>(t);
return std::chrono::duration_cast<std::chrono::microseconds>(::date::make_time(t - dp).to_duration());
}
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013-2015, Roland Bock * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
@ -29,9 +29,11 @@
#include <sqlpp11/data_types/boolean.h> #include <sqlpp11/data_types/boolean.h>
#include <sqlpp11/data_types/integral.h> #include <sqlpp11/data_types/integral.h>
#include <sqlpp11/data_types/unsigned_integral.h>
#include <sqlpp11/data_types/floating_point.h> #include <sqlpp11/data_types/floating_point.h>
#include <sqlpp11/data_types/text.h> #include <sqlpp11/data_types/text.h>
#include <sqlpp11/data_types/day_point.h> #include <sqlpp11/data_types/day_point.h>
#include <sqlpp11/data_types/time_of_day.h>
#include <sqlpp11/data_types/time_point.h> #include <sqlpp11/data_types/time_point.h>
#include <sqlpp11/data_types/no_value.h> #include <sqlpp11/data_types/no_value.h>

View File

@ -39,6 +39,8 @@ namespace sqlpp
template <typename T> template <typename T>
using _is_valid_operand = is_boolean_t<T>; using _is_valid_operand = is_boolean_t<T>;
}; };
using bit = sqlpp::boolean;
} }
#endif #endif

View File

@ -42,5 +42,7 @@ namespace sqlpp
template <typename T> template <typename T>
using _is_valid_assignment_operand = is_day_point_t<T>; using _is_valid_assignment_operand = is_day_point_t<T>;
}; };
using date = day_point;
} }
#endif #endif

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013-2015, Roland Bock * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
@ -43,33 +43,61 @@ namespace sqlpp
}; };
template <typename L, typename R> template <typename L, typename R>
struct return_type_plus<L, R, binary_operand_check_t<L, is_integral_t, R, is_numeric_t>> struct return_type_plus<L, R, binary_operand_check_t<L, is_integral_t, R, is_numeric_not_unsigned_t>>
{ {
using check = consistent_t; using check = consistent_t;
using type = plus_t<wrap_operand_t<L>, value_type_of<wrap_operand_t<R>>, wrap_operand_t<R>>; using type = plus_t<wrap_operand_t<L>, value_type_of<wrap_operand_t<R>>, wrap_operand_t<R>>;
}; };
template <typename L, typename R> template <typename L, typename R>
struct return_type_minus<L, R, binary_operand_check_t<L, is_integral_t, R, is_numeric_t>> struct return_type_plus<L, R, binary_operand_check_t<L, is_integral_t, R, is_unsigned_integral_t>>
{
using check = consistent_t;
using type = integral;
};
template <typename L, typename R>
struct return_type_minus<L, R, binary_operand_check_t<L, is_integral_t, R, is_numeric_not_unsigned_t>>
{ {
using check = consistent_t; using check = consistent_t;
using type = minus_t<wrap_operand_t<L>, value_type_of<wrap_operand_t<R>>, wrap_operand_t<R>>; using type = minus_t<wrap_operand_t<L>, value_type_of<wrap_operand_t<R>>, wrap_operand_t<R>>;
}; };
template <typename L, typename R> template <typename L, typename R>
struct return_type_multiplies<L, R, binary_operand_check_t<L, is_integral_t, R, is_numeric_t>> struct return_type_minus<L, R, binary_operand_check_t<L, is_integral_t, R, is_unsigned_integral_t>>
{
using check = consistent_t;
using type = integral;
};
template <typename L, typename R>
struct return_type_multiplies<L, R, binary_operand_check_t<L, is_integral_t, R, is_numeric_not_unsigned_t>>
{ {
using check = consistent_t; using check = consistent_t;
using type = multiplies_t<wrap_operand_t<L>, value_type_of<wrap_operand_t<R>>, wrap_operand_t<R>>; using type = multiplies_t<wrap_operand_t<L>, value_type_of<wrap_operand_t<R>>, wrap_operand_t<R>>;
}; };
template <typename L, typename R> template <typename L, typename R>
struct return_type_divides<L, R, binary_operand_check_t<L, is_integral_t, R, is_numeric_t>> struct return_type_multiplies<L, R, binary_operand_check_t<L, is_integral_t, R, is_unsigned_integral_t>>
{
using check = consistent_t;
using type = integral;
};
template <typename L, typename R>
struct return_type_divides<L, R, binary_operand_check_t<L, is_integral_t, R, is_numeric_not_unsigned_t>>
{ {
using check = consistent_t; using check = consistent_t;
using type = divides_t<wrap_operand_t<L>, wrap_operand_t<R>>; using type = divides_t<wrap_operand_t<L>, wrap_operand_t<R>>;
}; };
template <typename L, typename R>
struct return_type_divides<L, R, binary_operand_check_t<L, is_integral_t, R, is_unsigned_integral_t>>
{
using check = consistent_t;
using type = integral;
};
template <typename L, typename R> template <typename L, typename R>
struct return_type_modulus<L, R, binary_operand_check_t<L, is_integral_t, R, is_integral_t>> struct return_type_modulus<L, R, binary_operand_check_t<L, is_integral_t, R, is_integral_t>>
{ {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013-2015, Roland Bock * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
@ -35,7 +35,7 @@ namespace sqlpp
struct integral_operand; struct integral_operand;
template <typename T> template <typename T>
struct wrap_operand<T, typename std::enable_if<std::is_integral<T>::value and not std::is_same<bool, T>::value>::type> struct wrap_operand<T, typename std::enable_if<std::is_integral<T>::value and not std::is_same<bool, T>::value and not std::is_unsigned<T>::value>::type>
{ {
using type = integral_operand; using type = integral_operand;
}; };

View File

@ -43,5 +43,7 @@ namespace sqlpp
using blob = text; using blob = text;
using varchar = text; using varchar = text;
using char_ = text; using char_ = text;
using binary = text;
using varbinary = text;
} }
#endif #endif

View File

@ -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 <sqlpp11/data_types/time_of_day/data_type.h>
#include <sqlpp11/data_types/time_of_day/operand.h>
#include <sqlpp11/data_types/time_of_day/wrap_operand.h>
#include <sqlpp11/data_types/time_of_day/expression_operators.h>
#include <sqlpp11/data_types/time_of_day/column_operators.h>
#include <sqlpp11/data_types/time_of_day/parameter_value.h>
#include <sqlpp11/data_types/time_of_day/result_field.h>
#endif

View File

@ -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 <sqlpp11/type_traits.h>
#include <sqlpp11/assignment.h>
#include <sqlpp11/data_types/time_of_day/data_type.h>
#include <sqlpp11/data_types/column_operators.h>
namespace sqlpp
{
template <typename Column>
struct column_operators<Column, time_of_day>
{
template <typename T>
using _is_valid_operand = is_valid_operand<time_of_day, T>;
};
}
#endif

View File

@ -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 <sqlpp11/chrono.h>
#include <sqlpp11/type_traits.h>
namespace sqlpp
{
struct time_of_day
{
using _traits = make_traits<time_of_day, tag::is_value_type>;
using _cpp_value_type = std::chrono::microseconds;
template <typename T>
using _is_valid_operand = is_time_of_day_t<T>;
};
}
#endif

View File

@ -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 <sqlpp11/expression_operators.h>
#include <sqlpp11/basic_expression_operators.h>
#include <sqlpp11/type_traits.h>
#include <sqlpp11/data_types/time_of_day/data_type.h>
namespace sqlpp
{
// time_of_day expression operators
template <typename Expression>
struct expression_operators<Expression, time_of_day> : public basic_expression_operators<Expression>
{
};
}
#endif

View File

@ -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 <sqlpp11/chrono.h>
#include <sqlpp11/type_traits.h>
#include <sqlpp11/alias_operators.h>
#include <sqlpp11/serializer.h>
namespace sqlpp
{
struct time_of_day;
template <typename Period>
struct time_of_day_operand : public alias_operators<time_of_day_operand<Period>>
{
using _traits = make_traits<time_of_day, tag::is_expression, tag::is_wrapped_value>;
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 <typename Context, typename Period>
struct serializer_t<Context, time_of_day_operand<Period>>
{
using _serialize_check = consistent_t;
using Operand = time_of_day_operand<Period>;
static Context& _(const Operand& t, Context& context)
{
context << '\'' << ::date::make_time(t._t) << '\'';
return context;
}
};
}
#endif

View File

@ -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 <sqlpp11/data_types/parameter_value.h>
#include <sqlpp11/data_types/parameter_value_base.h>
#include <sqlpp11/data_types/time_of_day/data_type.h>
#include <sqlpp11/data_types/time_point/wrap_operand.h>
#include <sqlpp11/data_types/time_point/operand.h>
#include <sqlpp11/tvin.h>
namespace sqlpp
{
template <>
struct parameter_value_t<time_of_day> : public parameter_value_base<time_of_day>
{
using base = parameter_value_base<time_of_day>;
using base::base;
using base::operator=;
template <typename Target>
void _bind(Target& target, size_t index) const
{
target._bind_time_of_day_parameter(index, &_value, _is_null);
}
};
}
#endif

View File

@ -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 <sqlpp11/chrono.h>
#include <sqlpp11/basic_expression_operators.h>
#include <sqlpp11/result_field.h>
#include <sqlpp11/result_field_base.h>
#include <sqlpp11/data_types/time_of_day/data_type.h>
#include <sqlpp11/field_spec.h>
#include <ostream>
namespace sqlpp
{
template <typename Db, typename NameType, bool CanBeNull, bool NullIsTrivialValue>
struct result_field_t<Db, field_spec_t<NameType, time_of_day, CanBeNull, NullIsTrivialValue>>
: public result_field_base<Db, field_spec_t<NameType, time_of_day, CanBeNull, NullIsTrivialValue>>
{
template <typename Target>
void _bind(Target& target, size_t i)
{
target._bind_time_of_day_result(i, &this->_value, &this->_is_null);
}
template <typename Target>
void _post_bind(Target& target, size_t i)
{
target._post_bind_time_of_day_result(i, &this->_value, &this->_is_null);
}
};
template <typename Db, typename NameType, bool CanBeNull, bool NullIsTrivialValue>
inline std::ostream& operator<<(
std::ostream& os, const result_field_t<Db, field_spec_t<NameType, time_of_day, CanBeNull, NullIsTrivialValue>>& e)
{
if (e.is_null() and not NullIsTrivialValue)
{
os << "NULL";
}
else
{
os << ::date::make_time(e.value());
}
return os;
}
}
#endif

View File

@ -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 <sqlpp11/wrap_operand.h>
#include <sqlpp11/data_types/time_of_day/operand.h>
namespace sqlpp
{
template <typename Rep, typename Period>
struct wrap_operand<std::chrono::duration<Rep, Period>, void>
{
using type = time_of_day_operand<std::chrono::duration<Rep, Period>>;
};
}
#endif

View File

@ -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 <sqlpp11/data_types/unsigned_integral/data_type.h>
#include <sqlpp11/data_types/unsigned_integral/operand.h>
#include <sqlpp11/data_types/unsigned_integral/wrap_operand.h>
#include <sqlpp11/data_types/unsigned_integral/expression_operators.h>
#include <sqlpp11/data_types/unsigned_integral/column_operators.h>
#include <sqlpp11/data_types/unsigned_integral/parameter_value.h>
#include <sqlpp11/data_types/unsigned_integral/result_field.h>
#endif

View File

@ -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 <sqlpp11/type_traits.h>
#include <sqlpp11/assignment.h>
#include <sqlpp11/value_type.h>
#include <sqlpp11/data_types/unsigned_integral/data_type.h>
#include <sqlpp11/data_types/column_operators.h>
namespace sqlpp
{
template <typename Column>
struct column_operators<Column, unsigned_integral>
{
template <typename T>
using _is_valid_operand = is_valid_operand<unsigned_integral, T>;
template <typename T>
auto operator+=(T t) const -> assignment_t<Column, plus_t<Column, value_type_t<T>, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return {*static_cast<const Column*>(this), {{*static_cast<const Column*>(this), rhs{t}}}};
}
template <typename T>
auto operator-=(T t) const -> assignment_t<Column, minus_t<Column, value_type_t<T>, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return {*static_cast<const Column*>(this), {{*static_cast<const Column*>(this), rhs{t}}}};
}
template <typename T>
auto operator/=(T t) const -> assignment_t<Column, divides_t<Column, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return {*static_cast<const Column*>(this), {{*static_cast<const Column*>(this), rhs{t}}}};
}
template <typename T>
auto operator*=(T t) const -> assignment_t<Column, multiplies_t<Column, value_type_t<T>, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return {*static_cast<const Column*>(this), {{*static_cast<const Column*>(this), rhs{t}}}};
}
};
}
#endif

View File

@ -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 <sqlpp11/type_traits.h>
namespace sqlpp
{
struct unsigned_integral
{
using _traits = make_traits<unsigned_integral, tag::is_value_type>;
using _cpp_value_type = uint64_t;
template <typename T>
using _is_valid_operand = is_numeric_t<T>;
};
using tinyint_unsigned = unsigned_integral;
using smallint_unsigned = unsigned_integral;
using integer_unsigned = unsigned_integral;
using bigint_unsigned = unsigned_integral;
}
#endif

View File

@ -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 <sqlpp11/expression_return_types.h>
#include <sqlpp11/operand_check.h>
#include <sqlpp11/expression_operators.h>
#include <sqlpp11/basic_expression_operators.h>
#include <sqlpp11/value_type.h>
#include <sqlpp11/type_traits.h>
#include <sqlpp11/data_types/unsigned_integral/data_type.h>
namespace sqlpp
{
struct integral;
template <typename Expression>
struct expression_operators<Expression, unsigned_integral> : public basic_expression_operators<Expression>
{
};
template <typename L, typename R>
struct return_type_plus<L, R, binary_operand_check_t<L, is_unsigned_integral_t, R, is_numeric_t>>
{
using check = consistent_t;
using type = value_type_of<wrap_operand_t<R>>;
};
template <typename L, typename R>
struct return_type_minus<L, R, binary_operand_check_t<L, is_unsigned_integral_t, R, is_numeric_not_unsigned_t>>
{
using check = consistent_t;
using type = value_type_of<wrap_operand_t<R>>;
};
template <typename L, typename R>
struct return_type_minus<L, R, binary_operand_check_t<L, is_unsigned_integral_t, R, is_unsigned_integral_t>>
{
using check = consistent_t;
using type = minus_t<wrap_operand_t<L>, integral, wrap_operand_t<R>>;
};
template <typename L, typename R>
struct return_type_multiplies<L, R, binary_operand_check_t<L, is_unsigned_integral_t, R, is_numeric_t>>
{
using check = consistent_t;
using type = value_type_of<wrap_operand_t<R>>;
};
template <typename L, typename R>
struct return_type_divides<L, R, binary_operand_check_t<L, is_unsigned_integral_t, R, is_numeric_t>>
{
using check = consistent_t;
using type = value_type_of<wrap_operand_t<R>>;
};
template <typename L, typename R>
struct return_type_modulus<L, R, binary_operand_check_t<L, is_unsigned_integral_t, R, is_unsigned_integral_t>>
{
using check = consistent_t;
using type = modulus_t<wrap_operand_t<L>, wrap_operand_t<R>>;
};
template <typename T, typename Defer>
struct return_type_unary_plus<T, Defer, unary_operand_check_t<T, is_unsigned_integral_t>>
{
using check = consistent_t;
using type = unary_plus_t<unsigned_integral, wrap_operand_t<T>>;
};
template <typename T, typename Defer>
struct return_type_unary_minus<T, Defer, unary_operand_check_t<T, is_unsigned_integral_t>>
{
using check = consistent_t;
using type = unary_minus_t<integral, wrap_operand_t<T>>;
};
template <typename L, typename R>
struct return_type_bitwise_and<L, R, binary_operand_check_t<L, is_unsigned_integral_t, R, is_unsigned_integral_t>>
{
using check = consistent_t;
using type = bitwise_and_t<wrap_operand_t<L>, unsigned_integral, wrap_operand_t<R>>;
};
template <typename L, typename R>
struct return_type_bitwise_or<L, R, binary_operand_check_t<L, is_unsigned_integral_t, R, is_unsigned_integral_t>>
{
using check = consistent_t;
using type = bitwise_or_t<wrap_operand_t<L>, unsigned_integral, wrap_operand_t<R>>;
};
}
#endif

View File

@ -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 <sqlpp11/type_traits.h>
#include <sqlpp11/alias_operators.h>
#include <sqlpp11/serializer.h>
namespace sqlpp
{
struct unsigned_integral;
struct unsigned_integral_operand : public alias_operators<unsigned_integral_operand>
{
using _traits = make_traits<unsigned_integral, tag::is_expression, tag::is_wrapped_value>;
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 <typename Context>
struct serializer_t<Context, unsigned_integral_operand>
{
using _serialize_check = consistent_t;
using Operand = unsigned_integral_operand;
static Context& _(const Operand& t, Context& context)
{
context << t._t;
return context;
}
};
}
#endif

View File

@ -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 <sqlpp11/data_types/parameter_value.h>
#include <sqlpp11/data_types/parameter_value_base.h>
#include <sqlpp11/data_types/unsigned_integral/data_type.h>
#include <sqlpp11/tvin.h>
namespace sqlpp
{
template <>
struct parameter_value_t<unsigned_integral> : public parameter_value_base<unsigned_integral>
{
using base = parameter_value_base<unsigned_integral>;
using base::base;
using base::operator=;
template <typename Target>
void _bind(Target& target, size_t index) const
{
target._bind_unsigned_integral_parameter(index, &_value, _is_null);
}
};
}
#endif

View File

@ -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 <sqlpp11/basic_expression_operators.h>
#include <sqlpp11/result_field.h>
#include <sqlpp11/result_field_base.h>
#include <sqlpp11/data_types/unsigned_integral/data_type.h>
#include <sqlpp11/field_spec.h>
namespace sqlpp
{
template <typename Db, typename NameType, bool CanBeNull, bool NullIsTrivialValue>
struct result_field_t<Db, field_spec_t<NameType, unsigned_integral, CanBeNull, NullIsTrivialValue>>
: public result_field_base<Db, field_spec_t<NameType, unsigned_integral, CanBeNull, NullIsTrivialValue>>
{
template <typename Target>
void _bind(Target& target, size_t index)
{
target._bind_unsigned_integral_result(index, &this->_value, &this->_is_null);
}
template <typename Target>
void _post_bind(Target& target, size_t index)
{
target._post_bind_unsigned_integral_result(index, &this->_value, &this->_is_null);
}
};
}
#endif

View File

@ -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 <utility>
#include <sqlpp11/wrap_operand.h>
namespace sqlpp
{
struct unsigned_integral_operand;
template <typename T>
struct wrap_operand<T, typename std::enable_if<std::is_integral<T>::value and not std::is_same<bool, T>::value and std::is_unsigned<T>::value>::type>
{
using type = unsigned_integral_operand;
};
}
#endif

View File

@ -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_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_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()"); "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"); "set() arguments contain assignments from more than one table");
SQLPP_PORTABLE_STATIC_ASSERT(assert_insert_static_set_count_args_t, SQLPP_PORTABLE_STATIC_ASSERT(assert_insert_static_set_count_args_t,
"at least one assignment expression required in set()"); "at least one assignment expression required in set()");
@ -163,10 +163,10 @@ namespace sqlpp
// static_check_t<logic::all_t<is_assignment_t<Assignments>::value...>::value, assert_insert_set_assignments_t>, // static_check_t<logic::all_t<is_assignment_t<Assignments>::value...>::value, assert_insert_set_assignments_t>,
// static_check_t<not detail::has_duplicates<lhs_t<Assignments>...>::value, assert_insert_set_no_duplicates_t>, // static_check_t<not detail::has_duplicates<lhs_t<Assignments>...>::value, assert_insert_set_no_duplicates_t>,
// static_check_t<logic::none_t<must_not_insert_t<lhs_t<Assignments>>::value...>::value, // static_check_t<logic::none_t<must_not_insert_t<lhs_t<Assignments>>::value...>::value,
// assert_insert_set_prohibited_t>, // assert_insert_set_allowed_t>,
// static_check_t<sizeof...(Assignments) == 0 or // static_check_t<sizeof...(Assignments) == 0 or
// detail::make_joined_set_t<required_tables_of<lhs_t<Assignments>>...>::size::value == 1, // detail::make_joined_set_t<required_tables_of<lhs_t<Assignments>>...>::size::value == 1,
// assert_insert_set_one_table_t>>; // assert_insert_set_single_table_t>>;
template <typename Expr> template <typename Expr>
struct must_not_insert struct must_not_insert
@ -180,11 +180,11 @@ namespace sqlpp
assert_insert_set_assignments_t>, assert_insert_set_assignments_t>,
static_check_t<not detail::has_duplicates<typename lhs<Assignments>::type...>::value, static_check_t<not detail::has_duplicates<typename lhs<Assignments>::type...>::value,
assert_insert_set_no_duplicates_t>, assert_insert_set_no_duplicates_t>,
static_check_t<logic::none_t<must_not_insert<Assignments>::value...>::value, assert_insert_set_prohibited_t>, static_check_t<logic::none_t<must_not_insert<Assignments>::value...>::value, assert_insert_set_allowed_t>,
static_check_t< static_check_t<
sizeof...(Assignments) == 0 or sizeof...(Assignments) == 0 or
detail::make_joined_set_t<required_tables_of<typename lhs<Assignments>::type>...>::size::value == 1, detail::make_joined_set_t<required_tables_of<typename lhs<Assignments>::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 // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269
// template <typename... Assignments> // template <typename... Assignments>

View File

@ -92,7 +92,7 @@ namespace sqlpp
assert_no_unknown_tables_in_selected_columns_t, assert_no_unknown_tables_in_selected_columns_t,
"at least one selected column requires a table which is otherwise not known in the statement"); "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, 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 // SELECTED COLUMNS
template <typename Database, typename... Columns> template <typename Database, typename... Columns>

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013-2015, Roland Bock * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
@ -79,17 +79,30 @@ namespace sqlpp
template <typename T> template <typename T>
using is_integral_t = std::is_same<value_type_of<T>, integral>; using is_integral_t = std::is_same<value_type_of<T>, integral>;
struct unsigned_integral;
template <typename T>
using is_unsigned_integral_t = std::is_same<value_type_of<T>, unsigned_integral>;
struct text; struct text;
template <typename T> template <typename T>
using is_text_t = std::is_same<value_type_of<T>, text>; using is_text_t = std::is_same<value_type_of<T>, text>;
struct time_of_day;
template <typename T>
using is_time_of_day_t = std::is_same<value_type_of<T>, time_of_day>;
struct time_point; struct time_point;
template <typename T> template <typename T>
using is_time_point_t = std::is_same<value_type_of<T>, time_point>; using is_time_point_t = std::is_same<value_type_of<T>, time_point>;
// joined data type // joined data type
template <typename T> template <typename T>
using is_numeric_t = logic::any_t<is_integral_t<T>::value, is_floating_point_t<T>::value>; using is_numeric_t =
logic::any_t<is_integral_t<T>::value, is_unsigned_integral_t<T>::value, is_floating_point_t<T>::value>;
template <typename T>
using is_numeric_not_unsigned_t =
logic::any_t<is_integral_t<T>::value, not is_unsigned_integral_t<T>::value, is_floating_point_t<T>::value>;
template <typename T> template <typename T>
using is_day_or_time_point_t = logic::any_t<is_day_point_t<T>::value, is_time_point_t<T>::value>; using is_day_or_time_point_t = logic::any_t<is_day_point_t<T>::value, is_time_point_t<T>::value>;

View File

@ -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_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 <typename Assignment>
struct lhs_must_not_update
{
static constexpr auto value = detail::must_not_update_impl<typename lhs<Assignment>::type>::type::value;
};
}
template <typename... Assignments>
using check_update_set_t = static_combined_check_t<
static_check_t<logic::all_t<detail::is_assignment_impl<Assignments>::type::value...>::value,
assert_update_set_assignments_t>,
static_check_t<not detail::has_duplicates<typename lhs<Assignments>::type...>::value,
assert_update_set_no_duplicates_t>,
static_check_t<logic::none_t<detail::lhs_must_not_update<Assignments>::value...>::value,
assert_update_set_allowed_t>,
static_check_t<
sizeof...(Assignments) == 0 or
detail::make_joined_set_t<required_tables_of<typename lhs<Assignments>::type>...>::size::value == 1,
assert_update_set_single_table_t>>;
template <typename... Assignments>
struct check_update_static_set
{
using type = static_combined_check_t<check_update_set_t<Assignments...>,
static_check_t<sizeof...(Assignments) != 0, assert_update_set_count_args_t>>;
};
template <typename... Assignments>
using check_update_static_set_t = typename check_update_static_set<Assignments...>::type;
template <typename Database, typename... Assignments>
struct check_update_dynamic_set
{
using type = static_combined_check_t<
static_check_t<not std::is_same<Database, void>::value, assert_update_dynamic_set_statement_dynamic_t>,
check_update_set_t<Assignments...>>;
};
template <typename... Assignments>
using check_update_dynamic_set_t = typename check_update_dynamic_set<Assignments...>::type;
struct no_update_list_t struct no_update_list_t
{ {
using _traits = make_traits<no_value_t, tag::is_where>; using _traits = make_traits<no_value_t, tag::is_where>;
@ -199,14 +251,6 @@ namespace sqlpp
using _database_t = typename Policies::_database_t; using _database_t = typename Policies::_database_t;
// workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269
// template <typename... T>
// using _check = logic::all_t<is_assignment_t<T>::value...>;
template <typename... T>
struct _check : public logic::all_t<is_assignment_t<T>::value...>
{
};
template <typename Check, typename T> template <typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_update_list_t, T>; using _new_statement_t = new_statement_t<Check::value, Policies, no_update_list_t, T>;
@ -214,23 +258,23 @@ namespace sqlpp
template <typename... Assignments> template <typename... Assignments>
auto set(Assignments... assignments) const auto set(Assignments... assignments) const
-> _new_statement_t<_check<Assignments...>, update_list_t<void, Assignments...>> -> _new_statement_t<check_update_static_set_t<Assignments...>, update_list_t<void, Assignments...>>
{ {
static_assert(sizeof...(Assignments), "at least one assignment expression required in set()"); using Check = check_update_static_set_t<Assignments...>;
static_assert(_check<Assignments...>::value, "at least one argument is not an assignment in set()"); Check{}._();
return _set_impl<void>(_check<Assignments...>{}, assignments...); return _set_impl<void>(Check{}, assignments...);
} }
template <typename... Assignments> template <typename... Assignments>
auto dynamic_set(Assignments... assignments) const auto dynamic_set(Assignments... assignments) const
-> _new_statement_t<_check<Assignments...>, update_list_t<_database_t, Assignments...>> -> _new_statement_t<check_update_dynamic_set_t<_database_t, Assignments...>,
update_list_t<_database_t, Assignments...>>
{ {
static_assert(not std::is_same<_database_t, void>::value, using Check = check_update_dynamic_set_t<_database_t, Assignments...>;
"dynamic_set() must not be called in a static statement"); Check{}._();
static_assert(_check<Assignments...>::value, "at least one argument is not an assignment in set()");
return _set_impl<_database_t>(_check<Assignments...>{}, assignments...); return _set_impl<_database_t>(Check{}, assignments...);
} }
private: private:
@ -241,15 +285,6 @@ namespace sqlpp
auto _set_impl(const std::true_type&, Assignments... assignments) const auto _set_impl(const std::true_type&, Assignments... assignments) const
-> _new_statement_t<std::true_type, update_list_t<Database, Assignments...>> -> _new_statement_t<std::true_type, update_list_t<Database, Assignments...>>
{ {
static_assert(not detail::has_duplicates<lhs_t<Assignments>...>::value,
"at least one duplicate column detected in set()");
static_assert(logic::none_t<must_not_update_t<lhs_t<Assignments>>::value...>::value,
"at least one assignment is prohibited by its column definition in set()");
using _column_required_tables = detail::make_joined_set_t<required_tables_of<lhs_t<Assignments>>...>;
static_assert(sizeof...(Assignments) ? (_column_required_tables::size::value == 1) : true,
"set() contains assignments for columns from more than one table");
return {static_cast<const derived_statement_t<Policies>&>(*this), return {static_cast<const derived_statement_t<Policies>&>(*this),
update_list_data_t<Database, Assignments...>{assignments...}}; update_list_data_t<Database, Assignments...>{assignments...}};
} }

View File

@ -33,6 +33,7 @@ test_compile(case)
test_compile(from) test_compile(from)
test_compile(join) test_compile(join)
test_compile(where) test_compile(where)
test_compile(update_list)
test_compile(having) test_compile(having)
test_compile(insert) test_compile(insert)
test_compile(in) test_compile(in)

View File

@ -87,8 +87,8 @@ namespace
set_static_check<sqlpp::consistent_t>(t.gamma = true, t.delta = 42, t.beta = "fortytwo"); set_static_check<sqlpp::consistent_t>(t.gamma = true, t.delta = 42, t.beta = "fortytwo");
// Try setting alpha // Try setting alpha
set_static_check<sqlpp::assert_insert_set_prohibited_t>(t.alpha = 17, t.beta = "whatever"); set_static_check<sqlpp::assert_insert_set_allowed_t>(t.alpha = 17, t.beta = "whatever");
set_static_check<sqlpp::assert_insert_set_prohibited_t>(t.beta = "whatever", t.alpha = 17); set_static_check<sqlpp::assert_insert_set_allowed_t>(t.beta = "whatever", t.alpha = 17);
// Try omitting gamma // Try omitting gamma
set_static_check<sqlpp::assert_insert_static_set_all_required_t>(t.delta = 42); set_static_check<sqlpp::assert_insert_static_set_all_required_t>(t.delta = 42);
@ -112,7 +112,7 @@ namespace
t.gamma = true); t.gamma = true);
// Try multiple tables // Try multiple tables
set_static_check<sqlpp::assert_insert_set_one_table_t>(f.omega = 41, t.gamma = true); set_static_check<sqlpp::assert_insert_set_single_table_t>(f.omega = 41, t.gamma = true);
} }
// column alpha is not allowed, column gamma is required // column alpha is not allowed, column gamma is required
@ -127,8 +127,8 @@ namespace
set_dynamic_check<sqlpp::consistent_t>(t.gamma = true, t.delta = 42, t.beta = "fortytwo"); set_dynamic_check<sqlpp::consistent_t>(t.gamma = true, t.delta = 42, t.beta = "fortytwo");
// Try setting alpha // Try setting alpha
set_dynamic_check<sqlpp::assert_insert_set_prohibited_t>(t.alpha = 17, t.beta = "whatever"); set_dynamic_check<sqlpp::assert_insert_set_allowed_t>(t.alpha = 17, t.beta = "whatever");
set_dynamic_check<sqlpp::assert_insert_set_prohibited_t>(t.beta = "whatever", t.alpha = 17); set_dynamic_check<sqlpp::assert_insert_set_allowed_t>(t.beta = "whatever", t.alpha = 17);
// Omitting gamma is OK in the dynamic case, since we have to assume that it gets added later // Omitting gamma is OK in the dynamic case, since we have to assume that it gets added later
set_dynamic_check<sqlpp::consistent_t>(t.delta = 42); set_dynamic_check<sqlpp::consistent_t>(t.delta = 42);
@ -153,7 +153,7 @@ namespace
t.gamma = true); t.gamma = true);
// Try multiple tables // Try multiple tables
set_dynamic_check<sqlpp::assert_insert_set_one_table_t>(f.omega = 41, t.gamma = true); set_dynamic_check<sqlpp::assert_insert_set_single_table_t>(f.omega = 41, t.gamma = true);
// Try dynamic_set on a non-dynamic insert // Try dynamic_set on a non-dynamic insert
using CheckResult = sqlpp::check_insert_dynamic_set_t<void>; using CheckResult = sqlpp::check_insert_dynamic_set_t<void>;

View File

@ -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 <iostream>
#include "MockDb.h"
#include "Sample.h"
#include <sqlpp11/sqlpp11.h>
namespace
{
constexpr auto t = test::TabBar{};
constexpr auto f = test::TabFoo{};
template <typename T>
void print_type_on_error(std::true_type)
{
}
template <typename T>
void print_type_on_error(std::false_type)
{
T::_print_me_;
}
template <typename Assert, typename... Expressions>
void update_set_static_check(const Expressions&... expressions)
{
using CheckResult = sqlpp::check_update_static_set_t<Expressions...>;
using ExpectedCheckResult = std::is_same<CheckResult, Assert>;
print_type_on_error<CheckResult>(ExpectedCheckResult{});
static_assert(ExpectedCheckResult::value, "Unexpected check result");
using ReturnType = decltype(update(t).set(expressions...));
using ExpectedReturnType =
sqlpp::logic::all_t<Assert::value xor std::is_same<ReturnType, sqlpp::bad_statement>::value>;
print_type_on_error<ReturnType>(ExpectedReturnType{});
static_assert(ExpectedReturnType::value, "Unexpected return type");
}
template <typename Assert, typename... Expressions>
void update_set_dynamic_check(const Expressions&... expressions)
{
static auto db = MockDb{};
using CheckResult = sqlpp::check_update_dynamic_set_t<decltype(db), Expressions...>;
using ExpectedCheckResult = std::is_same<CheckResult, Assert>;
print_type_on_error<CheckResult>(ExpectedCheckResult{});
static_assert(ExpectedCheckResult::value, "Unexpected check result");
using ReturnType = decltype(dynamic_update(db, t).dynamic_set(expressions...));
using ExpectedReturnType =
sqlpp::logic::all_t<Assert::value xor std::is_same<ReturnType, sqlpp::bad_statement>::value>;
print_type_on_error<ReturnType>(ExpectedReturnType{});
static_assert(ExpectedReturnType::value, "Unexpected return type");
}
void static_update_set()
{
// OK
update_set_static_check<sqlpp::consistent_t>(t.gamma = true);
update_set_static_check<sqlpp::consistent_t>(t.gamma = true, t.beta = "");
// Try to update nothing
update_set_static_check<sqlpp::assert_update_set_count_args_t>();
// Try condition as assignment
update_set_static_check<sqlpp::assert_update_set_assignments_t>(t.gamma == true);
// Try duplicate columns
update_set_static_check<sqlpp::assert_update_set_no_duplicates_t>(t.gamma = true, t.gamma = false);
update_set_static_check<sqlpp::assert_update_set_no_duplicates_t>(t.gamma = true, t.beta = "", t.gamma = false);
// Try to update prohibited columns
update_set_static_check<sqlpp::assert_update_set_allowed_t>(t.alpha = 42);
// Try to update multiple tables at once
update_set_static_check<sqlpp::assert_update_set_single_table_t>(t.gamma = true, f.omega = 7);
}
void dynamic_update_set()
{
// OK
update_set_dynamic_check<sqlpp::consistent_t>(t.gamma = true);
update_set_dynamic_check<sqlpp::consistent_t>(t.gamma = true, t.beta = "");
// Try to update nothing
update_set_dynamic_check<sqlpp::consistent_t>();
// Try condition as assignment
update_set_dynamic_check<sqlpp::assert_update_set_assignments_t>(t.gamma == true);
// Try duplicate columns
update_set_dynamic_check<sqlpp::assert_update_set_no_duplicates_t>(t.gamma = true, t.gamma = false);
update_set_dynamic_check<sqlpp::assert_update_set_no_duplicates_t>(t.gamma = true, t.beta = "", t.gamma = false);
// Try to update prohibited columns
update_set_dynamic_check<sqlpp::assert_update_set_allowed_t>(t.alpha = 42);
// Try to update multiple tables at once
update_set_dynamic_check<sqlpp::assert_update_set_single_table_t>(t.gamma = true, f.omega = 7);
// Try dynamic_set on a non-dynamic update
using CheckResult = sqlpp::check_update_dynamic_set_t<void, sqlpp::boolean_operand>;
using ExpectedCheckResult = std::is_same<CheckResult, sqlpp::assert_update_dynamic_set_statement_dynamic_t>;
print_type_on_error<CheckResult>(ExpectedCheckResult{});
static_assert(ExpectedCheckResult::value, "Unexpected check result");
using ReturnType = decltype(update(t).dynamic_set());
using ExpectedReturnType = std::is_same<ReturnType, sqlpp::bad_statement>;
print_type_on_error<ReturnType>(ExpectedReturnType{});
static_assert(ExpectedReturnType::value, "Unexpected return type");
}
}
int main(int, char* [])
{
static_update_set();
dynamic_update_set();
}

View File

@ -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.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 = 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.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) db(update(t)
.set(t.colDayPoint = floor<::sqlpp::chrono::days>(std::chrono::system_clock::now())) .set(t.colDayPoint = floor<::sqlpp::chrono::days>(std::chrono::system_clock::now()))
.where(t.colDayPoint < std::chrono::system_clock::now())); .where(t.colDayPoint < std::chrono::system_clock::now()));
db(update(t) 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())); .where(t.colDayPoint < std::chrono::system_clock::now()));
db(update(t) 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())); .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 == 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.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 == 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.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; return 0;
} }

View File

@ -75,9 +75,31 @@ namespace test
}; };
using _traits = sqlpp::make_traits<sqlpp::floating_point, sqlpp::tag::can_be_null>; using _traits = sqlpp::make_traits<sqlpp::floating_point, sqlpp::tag::can_be_null>;
}; };
struct Psi
{
struct _alias_t
{
static constexpr const char _literal[] = "psi";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
struct _member_t
{
T psi;
T& operator()()
{
return psi;
}
const T& operator()() const
{
return psi;
}
};
};
using _traits = sqlpp::make_traits<sqlpp::bigint_unsigned, sqlpp::tag::can_be_null>;
};
} }
struct TabFoo : sqlpp::table_t<TabFoo, TabFoo_::Delta, TabFoo_::Epsilon, TabFoo_::Omega> struct TabFoo : sqlpp::table_t<TabFoo, TabFoo_::Delta, TabFoo_::Epsilon, TabFoo_::Omega, TabFoo_::Psi>
{ {
struct _alias_t struct _alias_t
{ {
@ -259,9 +281,33 @@ namespace test
}; };
using _traits = sqlpp::make_traits<sqlpp::time_point, sqlpp::tag::can_be_null>; using _traits = sqlpp::make_traits<sqlpp::time_point, sqlpp::tag::can_be_null>;
}; };
struct ColTimeOfDay
{
struct _alias_t
{
static constexpr const char _literal[] = "col_time_of_day";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
struct _member_t
{
T colTimeOfDay;
T& operator()()
{
return colTimeOfDay;
}
const T& operator()() const
{
return colTimeOfDay;
}
};
};
using _traits = sqlpp::make_traits<sqlpp::time_of_day, sqlpp::tag::can_be_null>;
};
} }
struct TabDateTime : sqlpp::table_t<TabDateTime, TabDateTime_::ColDayPoint, TabDateTime_::ColTimePoint> struct TabDateTime
: sqlpp::table_t<TabDateTime, TabDateTime_::ColDayPoint, TabDateTime_::ColTimePoint, TabDateTime_::ColTimeOfDay>
{ {
struct _alias_t struct _alias_t
{ {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013-2016, Roland Bock * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * 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); using T = decltype(t.alpha);
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement"); static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
static_assert(sqlpp::is_integral_t<T>::value, "type requirement"); static_assert(sqlpp::is_integral_t<T>::value, "type requirement");
static_assert(not sqlpp::is_unsigned_integral_t<T>::value, "type requirement");
static_assert(not sqlpp::is_floating_point_t<T>::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t<T>::value, "type requirement");
static_assert(sqlpp::is_expression_t<T>::value, "type requirement"); static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
static_assert(sqlpp::is_selectable_t<T>::value, "type requirement"); static_assert(sqlpp::is_selectable_t<T>::value, "type requirement");
@ -121,6 +122,46 @@ int SelectType(int, char* [])
static_assert(sqlpp::is_regular<T>::value, "type requirement"); static_assert(sqlpp::is_regular<T>::value, "type requirement");
} }
// Test an unsigned integral table column
{
using T = decltype(f.psi);
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
static_assert(not sqlpp::is_integral_t<T>::value, "type requirement");
static_assert(sqlpp::is_unsigned_integral_t<T>::value, "type requirement");
static_assert(not sqlpp::is_floating_point_t<T>::value, "type requirement");
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
static_assert(sqlpp::is_selectable_t<T>::value, "type requirement");
static_assert(not sqlpp::require_insert_t<T>::value, "type requirement");
static_assert(not sqlpp::is_boolean_t<T>::value, "type requirement");
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
static_assert(not sqlpp::is_alias_t<T>::value, "type requirement");
static_assert(not sqlpp::is_table_t<T>::value, "type requirement");
static_assert(sqlpp::is_regular<T>::value, "type requirement");
//subtraction on unsigned makes it signed
static_assert(sqlpp::is_integral_t<sqlpp::return_type_minus_t<T,T>>::value, "type requirement");
static_assert(sqlpp::is_integral_t<sqlpp::return_type_unary_minus_t<T,T>>::value, "type requirement");
//any operation on float makes it float
static_assert(sqlpp::is_floating_point_t<sqlpp::return_type_minus_t<T,sqlpp::floating_point>>::value, "type requirement");
static_assert(sqlpp::is_floating_point_t<sqlpp::return_type_plus_t<T,sqlpp::floating_point>>::value, "type requirement");
static_assert(sqlpp::is_floating_point_t<sqlpp::return_type_multiplies_t<T,sqlpp::floating_point>>::value, "type requirement");
static_assert(sqlpp::is_floating_point_t<sqlpp::return_type_divides_t<T,sqlpp::floating_point>>::value, "type requirement");
static_assert(sqlpp::is_floating_point_t<sqlpp::return_type_minus_t<sqlpp::floating_point,T>>::value, "type requirement");
static_assert(sqlpp::is_floating_point_t<sqlpp::return_type_plus_t<sqlpp::floating_point,T>>::value, "type requirement");
static_assert(sqlpp::is_floating_point_t<sqlpp::return_type_multiplies_t<sqlpp::floating_point,T>>::value, "type requirement");
static_assert(sqlpp::is_floating_point_t<sqlpp::return_type_divides_t<sqlpp::floating_point,T>>::value, "type requirement");
static_assert(sqlpp::is_floating_point_t<sqlpp::return_type_modulus_t<sqlpp::floating_point,T>>::value, "type requirement");
//signed operation on unsigned makes it signed
static_assert(sqlpp::is_integral_t<sqlpp::return_type_minus_t<T,sqlpp::integral>>::value, "type requirement");
static_assert(sqlpp::is_integral_t<sqlpp::return_type_plus_t<T,sqlpp::integral>>::value, "type requirement");
static_assert(sqlpp::is_integral_t<sqlpp::return_type_multiplies_t<T,sqlpp::integral>>::value, "type requirement");
static_assert(sqlpp::is_integral_t<sqlpp::return_type_divides_t<T,sqlpp::integral>>::value, "type requirement");
static_assert(sqlpp::is_integral_t<sqlpp::return_type_minus_t<sqlpp::integral,T>>::value, "type requirement");
static_assert(sqlpp::is_integral_t<sqlpp::return_type_plus_t<sqlpp::integral,T>>::value, "type requirement");
static_assert(sqlpp::is_integral_t<sqlpp::return_type_multiplies_t<sqlpp::integral,T>>::value, "type requirement");
static_assert(sqlpp::is_integral_t<sqlpp::return_type_divides_t<sqlpp::integral,T>>::value, "type requirement");
static_assert(sqlpp::is_integral_t<sqlpp::return_type_modulus_t<sqlpp::integral,T>>::value, "type requirement");
}
// Test a floating point table column // Test a floating point table column
{ {
using T = decltype(f.omega); using T = decltype(f.omega);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013-2015, Roland Bock * Copyright (c) 2013-2016, Roland Bock, Aaron Bishop
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
@ -28,7 +28,8 @@ CREATE TABLE tab_foo
( (
delta varchar(255), delta varchar(255),
epsilon bigint, epsilon bigint,
omega double omega double,
psi bigint UNSIGNED
); );
CREATE TABLE tab_bar CREATE TABLE tab_bar