1use std::io::Write;
2use std::os::raw as libc;
3use std::{mem, slice};
4
5use crate::deserialize::{self, FromSql, FromSqlRow};
6use crate::expression::AsExpression;
7use crate::mysql::{Mysql, MysqlValue};
8use crate::serialize::{self, IsNull, Output, ToSql};
9use crate::sql_types::{Date, Datetime, Time, Timestamp};
10
11#[cfg(feature = "chrono")]
12mod chrono;
13#[cfg(feature = "time")]
14mod time;
15
16#[repr(C)]
24#[derive(#[automatically_derived]
impl ::core::fmt::Debug for MysqlTime {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let names: &'static _ =
&["year", "month", "day", "hour", "minute", "second",
"second_part", "neg", "time_type",
"time_zone_displacement"];
let values: &[&dyn ::core::fmt::Debug] =
&[&self.year, &self.month, &self.day, &self.hour, &self.minute,
&self.second, &self.second_part, &self.neg, &self.time_type,
&&self.time_zone_displacement];
::core::fmt::Formatter::debug_struct_fields_finish(f, "MysqlTime",
names, values)
}
}Debug, #[automatically_derived]
impl ::core::clone::Clone for MysqlTime {
#[inline]
fn clone(&self) -> MysqlTime {
let _: ::core::clone::AssertParamIsClone<libc::c_uint>;
let _: ::core::clone::AssertParamIsClone<libc::c_uint>;
let _: ::core::clone::AssertParamIsClone<libc::c_uint>;
let _: ::core::clone::AssertParamIsClone<libc::c_uint>;
let _: ::core::clone::AssertParamIsClone<libc::c_uint>;
let _: ::core::clone::AssertParamIsClone<libc::c_uint>;
let _: ::core::clone::AssertParamIsClone<libc::c_ulong>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<MysqlTimestampType>;
let _: ::core::clone::AssertParamIsClone<libc::c_int>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for MysqlTime { }Copy, const _: () =
{
use diesel;
impl<'__expr> diesel::expression::AsExpression<Timestamp> for
&'__expr MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<Timestamp,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Timestamp>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr>
diesel::expression::AsExpression<diesel::sql_types::Nullable<Timestamp>>
for &'__expr MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Timestamp>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Timestamp>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr, '__expr2> diesel::expression::AsExpression<Timestamp>
for &'__expr2 &'__expr MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<Timestamp,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Timestamp>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr, '__expr2>
diesel::expression::AsExpression<diesel::sql_types::Nullable<Timestamp>>
for &'__expr2 &'__expr MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Timestamp>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Timestamp>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<__DB>
diesel::serialize::ToSql<diesel::sql_types::Nullable<Timestamp>,
__DB> for MysqlTime where __DB: diesel::backend::Backend,
Self: diesel::serialize::ToSql<Timestamp, __DB> {
fn to_sql<'__b>(&'__b self,
out: &mut diesel::serialize::Output<'__b, '_, __DB>)
-> diesel::serialize::Result {
diesel::serialize::ToSql::<Timestamp, __DB>::to_sql(self, out)
}
}
impl diesel::expression::AsExpression<Timestamp> for MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<Timestamp,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Timestamp>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl diesel::expression::AsExpression<diesel::sql_types::Nullable<Timestamp>>
for MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Timestamp>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Timestamp>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr> diesel::expression::AsExpression<Time> for
&'__expr MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<Time, Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Time>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr>
diesel::expression::AsExpression<diesel::sql_types::Nullable<Time>>
for &'__expr MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Time>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Time>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr, '__expr2> diesel::expression::AsExpression<Time> for
&'__expr2 &'__expr MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<Time, Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Time>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr, '__expr2>
diesel::expression::AsExpression<diesel::sql_types::Nullable<Time>>
for &'__expr2 &'__expr MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Time>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Time>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<__DB>
diesel::serialize::ToSql<diesel::sql_types::Nullable<Time>, __DB>
for MysqlTime where __DB: diesel::backend::Backend,
Self: diesel::serialize::ToSql<Time, __DB> {
fn to_sql<'__b>(&'__b self,
out: &mut diesel::serialize::Output<'__b, '_, __DB>)
-> diesel::serialize::Result {
diesel::serialize::ToSql::<Time, __DB>::to_sql(self, out)
}
}
impl diesel::expression::AsExpression<Time> for MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<Time, Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Time>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl diesel::expression::AsExpression<diesel::sql_types::Nullable<Time>>
for MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Time>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Time>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr> diesel::expression::AsExpression<Date> for
&'__expr MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<Date, Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Date>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr>
diesel::expression::AsExpression<diesel::sql_types::Nullable<Date>>
for &'__expr MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Date>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Date>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr, '__expr2> diesel::expression::AsExpression<Date> for
&'__expr2 &'__expr MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<Date, Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Date>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr, '__expr2>
diesel::expression::AsExpression<diesel::sql_types::Nullable<Date>>
for &'__expr2 &'__expr MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Date>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Date>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<__DB>
diesel::serialize::ToSql<diesel::sql_types::Nullable<Date>, __DB>
for MysqlTime where __DB: diesel::backend::Backend,
Self: diesel::serialize::ToSql<Date, __DB> {
fn to_sql<'__b>(&'__b self,
out: &mut diesel::serialize::Output<'__b, '_, __DB>)
-> diesel::serialize::Result {
diesel::serialize::ToSql::<Date, __DB>::to_sql(self, out)
}
}
impl diesel::expression::AsExpression<Date> for MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<Date, Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Date>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl diesel::expression::AsExpression<diesel::sql_types::Nullable<Date>>
for MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Date>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Date>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr> diesel::expression::AsExpression<Datetime> for
&'__expr MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<Datetime,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Datetime>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr>
diesel::expression::AsExpression<diesel::sql_types::Nullable<Datetime>>
for &'__expr MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Datetime>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Datetime>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr, '__expr2> diesel::expression::AsExpression<Datetime> for
&'__expr2 &'__expr MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<Datetime,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Datetime>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr, '__expr2>
diesel::expression::AsExpression<diesel::sql_types::Nullable<Datetime>>
for &'__expr2 &'__expr MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Datetime>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Datetime>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<__DB>
diesel::serialize::ToSql<diesel::sql_types::Nullable<Datetime>,
__DB> for MysqlTime where __DB: diesel::backend::Backend,
Self: diesel::serialize::ToSql<Datetime, __DB> {
fn to_sql<'__b>(&'__b self,
out: &mut diesel::serialize::Output<'__b, '_, __DB>)
-> diesel::serialize::Result {
diesel::serialize::ToSql::<Datetime, __DB>::to_sql(self, out)
}
}
impl diesel::expression::AsExpression<Datetime> for MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<Datetime,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Datetime>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl diesel::expression::AsExpression<diesel::sql_types::Nullable<Datetime>>
for MysqlTime {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Datetime>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Datetime>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
};AsExpression, const _: () =
{
use diesel;
impl<__DB, __ST> diesel::deserialize::Queryable<__ST, __DB> for
MysqlTime where __DB: diesel::backend::Backend,
__ST: diesel::sql_types::SingleValue,
Self: diesel::deserialize::FromSql<__ST, __DB> {
type Row = Self;
fn build(row: Self) -> diesel::deserialize::Result<Self> {
diesel::deserialize::Result::Ok(row)
}
}
};FromSqlRow)]
25#[non_exhaustive]
26#[diesel(sql_type = Timestamp)]
27#[diesel(sql_type = Time)]
28#[diesel(sql_type = Date)]
29#[diesel(sql_type = Datetime)]
30pub struct MysqlTime {
31 pub year: libc::c_uint,
33 pub month: libc::c_uint,
35 pub day: libc::c_uint,
37 pub hour: libc::c_uint,
39 pub minute: libc::c_uint,
41 pub second: libc::c_uint,
43 pub second_part: libc::c_ulong,
45 pub neg: bool,
47 pub time_type: MysqlTimestampType,
49 pub time_zone_displacement: libc::c_int,
51}
52
53impl MysqlTime {
54 #[allow(clippy::too_many_arguments)]
56 pub fn new(
57 year: libc::c_uint,
58 month: libc::c_uint,
59 day: libc::c_uint,
60 hour: libc::c_uint,
61 minute: libc::c_uint,
62 second: libc::c_uint,
63 second_part: libc::c_ulong,
64 neg: bool,
65 time_type: MysqlTimestampType,
66 time_zone_displacement: libc::c_int,
67 ) -> Self {
68 Self {
69 year,
70 month,
71 day,
72 hour,
73 minute,
74 second,
75 second_part,
76 neg,
77 time_type,
78 time_zone_displacement,
79 }
80 }
81}
82
83#[derive(#[automatically_derived]
impl ::core::cmp::PartialEq for MysqlTimestampType {
#[inline]
fn eq(&self, other: &MysqlTimestampType) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]
impl ::core::fmt::Debug for MysqlTimestampType {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"MysqlTimestampType", &&self.0)
}
}Debug, #[automatically_derived]
impl ::core::marker::Copy for MysqlTimestampType { }Copy, #[automatically_derived]
impl ::core::clone::Clone for MysqlTimestampType {
#[inline]
fn clone(&self) -> MysqlTimestampType {
let _: ::core::clone::AssertParamIsClone<libc::c_int>;
*self
}
}Clone, #[automatically_derived]
impl ::core::cmp::Eq for MysqlTimestampType {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) -> () {
let _: ::core::cmp::AssertParamIsEq<libc::c_int>;
}
}Eq)]
90#[repr(transparent)]
91pub struct MysqlTimestampType(libc::c_int);
92
93impl MysqlTimestampType {
94 pub const MYSQL_TIMESTAMP_NONE: MysqlTimestampType = MysqlTimestampType(-2);
97 pub const MYSQL_TIMESTAMP_ERROR: MysqlTimestampType = MysqlTimestampType(-1);
100 pub const MYSQL_TIMESTAMP_DATE: MysqlTimestampType = MysqlTimestampType(0);
103 pub const MYSQL_TIMESTAMP_DATETIME: MysqlTimestampType = MysqlTimestampType(1);
106 pub const MYSQL_TIMESTAMP_TIME: MysqlTimestampType = MysqlTimestampType(2);
109 pub const MYSQL_TIMESTAMP_DATETIME_TZ: MysqlTimestampType = MysqlTimestampType(3);
112}
113
114macro_rules! mysql_time_impls {
115 ($ty:ty) => {
116 #[cfg(feature = "mysql_backend")]
117 impl ToSql<$ty, Mysql> for MysqlTime {
118 #[allow(unsafe_code)] fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Mysql>) -> serialize::Result {
120 let bytes = unsafe {
121 let bytes_ptr = self as *const MysqlTime as *const u8;
122 slice::from_raw_parts(bytes_ptr, mem::size_of::<MysqlTime>())
123 };
124 out.write_all(bytes)?;
125 Ok(IsNull::No)
126 }
127 }
128
129 #[cfg(feature = "mysql_backend")]
130 impl FromSql<$ty, Mysql> for MysqlTime {
131 fn from_sql(value: MysqlValue<'_>) -> deserialize::Result<Self> {
132 value.time_value()
133 }
134 }
135 };
136}
137
138impl ToSql<Datetime, Mysql> for MysqlTime {
#[allow(unsafe_code)]
fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Mysql>)
-> serialize::Result {
let bytes =
unsafe {
let bytes_ptr = self as *const MysqlTime as *const u8;
slice::from_raw_parts(bytes_ptr, mem::size_of::<MysqlTime>())
};
out.write_all(bytes)?;
Ok(IsNull::No)
}
}
impl FromSql<Datetime, Mysql> for MysqlTime {
fn from_sql(value: MysqlValue<'_>) -> deserialize::Result<Self> {
value.time_value()
}
}mysql_time_impls!(Datetime);
139impl ToSql<Timestamp, Mysql> for MysqlTime {
#[allow(unsafe_code)]
fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Mysql>)
-> serialize::Result {
let bytes =
unsafe {
let bytes_ptr = self as *const MysqlTime as *const u8;
slice::from_raw_parts(bytes_ptr, mem::size_of::<MysqlTime>())
};
out.write_all(bytes)?;
Ok(IsNull::No)
}
}
impl FromSql<Timestamp, Mysql> for MysqlTime {
fn from_sql(value: MysqlValue<'_>) -> deserialize::Result<Self> {
value.time_value()
}
}mysql_time_impls!(Timestamp);
140impl ToSql<Time, Mysql> for MysqlTime {
#[allow(unsafe_code)]
fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Mysql>)
-> serialize::Result {
let bytes =
unsafe {
let bytes_ptr = self as *const MysqlTime as *const u8;
slice::from_raw_parts(bytes_ptr, mem::size_of::<MysqlTime>())
};
out.write_all(bytes)?;
Ok(IsNull::No)
}
}
impl FromSql<Time, Mysql> for MysqlTime {
fn from_sql(value: MysqlValue<'_>) -> deserialize::Result<Self> {
value.time_value()
}
}mysql_time_impls!(Time);
141impl ToSql<Date, Mysql> for MysqlTime {
#[allow(unsafe_code)]
fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Mysql>)
-> serialize::Result {
let bytes =
unsafe {
let bytes_ptr = self as *const MysqlTime as *const u8;
slice::from_raw_parts(bytes_ptr, mem::size_of::<MysqlTime>())
};
out.write_all(bytes)?;
Ok(IsNull::No)
}
}
impl FromSql<Date, Mysql> for MysqlTime {
fn from_sql(value: MysqlValue<'_>) -> deserialize::Result<Self> {
value.time_value()
}
}mysql_time_impls!(Date);