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

Cleaned up date/time structs a bit

This commit is contained in:
rbock 2015-10-27 16:13:36 +01:00
parent 56d312a59b
commit 31b7ac4c4a
4 changed files with 26 additions and 37 deletions

View File

@ -42,7 +42,7 @@ namespace sqlpp
{ {
using _traits = make_traits<date, tag::is_value_type>; using _traits = make_traits<date, tag::is_value_type>;
using _tag = tag::is_date; using _tag = tag::is_date;
using _cpp_value_type = day_point; using _cpp_value_type = cpp::day_point;
template <typename T> template <typename T>
using _is_valid_operand = is_time_point_t<T>; using _is_valid_operand = is_time_point_t<T>;
@ -74,7 +74,7 @@ namespace sqlpp
{ {
if (t._is_trivial()) if (t._is_trivial())
{ {
_value = day_point{}; _value = _cpp_value_type{};
_is_null = true; _is_null = true;
} }
else else
@ -87,7 +87,7 @@ namespace sqlpp
void set_null() void set_null()
{ {
_value = day_point{}; _value = _cpp_value_type{};
_is_null = true; _is_null = true;
} }
@ -148,7 +148,7 @@ namespace sqlpp
{ {
_is_valid = false; _is_valid = false;
_is_null = true; _is_null = true;
_value = day_point{}; _value = _cpp_value_type{};
} }
void _validate() void _validate()
@ -168,7 +168,7 @@ namespace sqlpp
if (not _is_valid) if (not _is_valid)
throw exception("accessing is_null in non-existing row"); throw exception("accessing is_null in non-existing row");
return value() == day_point{}; return value() == _cpp_value_type{};
} }
_cpp_value_type value() const _cpp_value_type value() const
@ -184,7 +184,7 @@ namespace sqlpp
} }
else else
{ {
return day_point{}; return _cpp_value_type{};
} }
} }
return _value; return _value;
@ -193,7 +193,7 @@ namespace sqlpp
template <typename Target> template <typename Target>
void _bind(Target& target, size_t i) void _bind(Target& target, size_t i)
{ {
target._bind_date_result(i, &_value, &_is_null); target._bind_day_point_result(i, &_value, &_is_null);
} }
private: private:
@ -201,12 +201,5 @@ namespace sqlpp
bool _is_null; bool _is_null;
_cpp_value_type _value; _cpp_value_type _value;
}; };
// ostream operator for date result field
template <typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<date, Db, FieldSpec>& e)
{
return serialize(e, os);
}
} }
#endif #endif

View File

@ -42,7 +42,7 @@ namespace sqlpp
{ {
using _traits = make_traits<date_time, tag::is_value_type>; using _traits = make_traits<date_time, tag::is_value_type>;
using _tag = tag::is_date_time; using _tag = tag::is_date_time;
using _cpp_value_type = ms_point; using _cpp_value_type = cpp::ms_point;
template <typename T> template <typename T>
using _is_valid_operand = is_time_point_t<T>; using _is_valid_operand = is_time_point_t<T>;
@ -74,7 +74,7 @@ namespace sqlpp
{ {
if (t._is_trivial()) if (t._is_trivial())
{ {
_value = day_point{}; _value = _cpp_value_type{};
_is_null = true; _is_null = true;
} }
else else
@ -87,7 +87,7 @@ namespace sqlpp
void set_null() void set_null()
{ {
_value = day_point{}; _value = _cpp_value_type{};
_is_null = true; _is_null = true;
} }
@ -149,7 +149,7 @@ namespace sqlpp
{ {
_is_valid = false; _is_valid = false;
_is_null = true; _is_null = true;
_value = day_point{}; _value = _cpp_value_type{};
} }
void _validate() void _validate()
@ -169,7 +169,7 @@ namespace sqlpp
if (not _is_valid) if (not _is_valid)
throw exception("accessing is_null in non-existing row"); throw exception("accessing is_null in non-existing row");
return value() == day_point{}; return value() == _cpp_value_type{};
} }
_cpp_value_type value() const _cpp_value_type value() const
@ -185,7 +185,7 @@ namespace sqlpp
} }
else else
{ {
return day_point{}; return _cpp_value_type{};
} }
} }
return _value; return _value;
@ -202,12 +202,5 @@ namespace sqlpp
bool _is_null; bool _is_null;
_cpp_value_type _value; _cpp_value_type _value;
}; };
// ostream operator for date_time result field
template <typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<date_time, Db, FieldSpec>& e)
{
return serialize(e, os);
}
} }
#endif #endif

View File

@ -30,11 +30,14 @@
#include <chrono> #include <chrono>
namespace sqlpp namespace sqlpp
{
namespace cpp
{ {
using days = std::chrono::duration<int, std::ratio_multiply<std::ratio<24>, std::chrono::hours::period>>; using days = std::chrono::duration<int, std::ratio_multiply<std::ratio<24>, std::chrono::hours::period>>;
using day_point = std::chrono::time_point<std::chrono::system_clock, days>; using day_point = std::chrono::time_point<std::chrono::system_clock, days>;
using ms_point = std::chrono::time_point<std::chrono::system_clock, std::chrono::microseconds>; using ms_point = std::chrono::time_point<std::chrono::system_clock, std::chrono::microseconds>;
}
struct date; struct date;
struct date_time; struct date_time;

View File

@ -71,14 +71,14 @@ namespace sqlpp
_value_t _t; _value_t _t;
}; };
template <typename Rep, typename Period> template <typename Period>
struct date_time_operand : public alias_operators<date_time_operand<Rep, Period>> struct date_time_operand : public alias_operators<date_time_operand<Period>>
{ {
using _traits = make_traits<date, tag::is_expression, tag::is_wrapped_value>; using _traits = make_traits<date, tag::is_expression, tag::is_wrapped_value>;
using _nodes = detail::type_vector<>; using _nodes = detail::type_vector<>;
using _is_aggregate_expression = std::true_type; using _is_aggregate_expression = std::true_type;
using _value_t = std::chrono::time_point<Rep, Period>; using _value_t = std::chrono::time_point<std::chrono::system_clock, Period>;
date_time_operand() : _t{} date_time_operand() : _t{}
{ {
@ -96,7 +96,7 @@ namespace sqlpp
bool _is_trivial() const bool _is_trivial() const
{ {
return _t == day_point{}; return _t == _value_t{};
} }
_value_t _t; _value_t _t;
@ -256,10 +256,10 @@ namespace sqlpp
using type = boolean_operand; using type = boolean_operand;
}; };
template <typename Rep, typename Period> template <typename Period>
struct wrap_operand<std::chrono::time_point<Rep, Period>, void> struct wrap_operand<std::chrono::time_point<std::chrono::system_clock, Period>, void>
{ {
using type = date_time_operand<Rep, Period>; using type = date_time_operand<Period>;
}; };
template <typename T> template <typename T>