Skip to content

Commit 200effd

Browse files
authored
Merge pull request #43 from SSebo/master
Fix compile by upgrading mysql crate
2 parents 26a5c35 + b906fdc commit 200effd

File tree

9 files changed

+82
-56
lines changed

9 files changed

+82
-56
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ maintenance = { status = "experimental" }
2828

2929
[dependencies]
3030
nom = "7"
31-
mysql_common = { version = "0.28.0", features = ["chrono"] }
31+
mysql_common = { version = "0.29.1", features = ["chrono"] }
3232
byteorder = "1"
3333
chrono = "0.4"
3434
rustls = {version = "0.20.0", optional=true}
3535

3636
[dev-dependencies]
3737
postgres = "0.19.1"
38-
mysql = "22"
39-
mysql_async = "0.29.0"
38+
mysql = "23"
39+
mysql_async = "0.31.0"
4040
slab = "0.4.2"
4141
tokio = { version = "1.15.0", features = ["full"] }
4242
futures = "0.3.0"

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
jobs:
22
- template: default.yml@templates
33
parameters:
4-
minrust: 1.54
4+
minrust: 1.59
55
codecov_token: $(CODECOV_TOKEN_SECRET)
66

77
resources:

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ pub trait MysqlShim<W: Read + Write> {
207207
}
208208

209209
/// Information about an authenticated user
210+
#[allow(clippy::derive_partial_eq_without_eq)]
210211
#[derive(Debug, Default, Clone, PartialEq)]
211212
pub struct AuthenticationContext<'a> {
212213
/// The username exactly as passed by the client,

src/params.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,10 @@ impl<'a> Iterator for Params<'a> {
7373
self.bound_types.clear();
7474
for i in 0..self.params as usize {
7575
self.bound_types.push((
76-
myc::constants::ColumnType::try_from(typmap[2 * i as usize])
77-
.unwrap_or_else(|e| {
78-
panic!("bad column type 0x{:x}: {}", typmap[2 * i as usize], e)
79-
}),
80-
(typmap[2 * i as usize + 1] & 128) != 0,
76+
myc::constants::ColumnType::try_from(typmap[2 * i]).unwrap_or_else(|e| {
77+
panic!("bad column type 0x{:x}: {}", typmap[2 * i], e)
78+
}),
79+
(typmap[2 * i + 1] & 128) != 0,
8180
));
8281
}
8382
self.input = rest;

src/tls.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub(crate) struct SwitchableConn<T: Read + Write>(pub(crate) Option<EitherConn<T
1717

1818
pub(crate) enum EitherConn<T: Read + Write> {
1919
Plain(T),
20-
Tls(rustls::StreamOwned<ServerConnection, PrependedReader<T>>),
20+
Tls(Box<rustls::StreamOwned<ServerConnection, PrependedReader<T>>>),
2121
}
2222

2323
impl<T: Read + Write> Read for SwitchableConn<T> {
@@ -56,10 +56,10 @@ impl<T: Read + Write> SwitchableConn<T> {
5656
to_prepend: &[u8],
5757
) -> io::Result<()> {
5858
let replacement = match self.0.take() {
59-
Some(EitherConn::Plain(plain)) => Ok(EitherConn::Tls(create_stream(
59+
Some(EitherConn::Plain(plain)) => Ok(EitherConn::Tls(Box::new(create_stream(
6060
PrependedReader::new(to_prepend, plain),
6161
config,
62-
)?)),
62+
)?))),
6363
Some(EitherConn::Tls(_)) => Err(io::Error::new(
6464
io::ErrorKind::Other,
6565
"tls variant found when plain was expected",

src/value/decode.rs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -206,40 +206,44 @@ impl<'a> From<Value<'a>> for NaiveDate {
206206
fn from(val: Value<'a>) -> Self {
207207
if let ValueInner::Date(mut v) = val.0 {
208208
assert_eq!(v.len(), 4);
209-
NaiveDate::from_ymd(
209+
if let Some(d) = NaiveDate::from_ymd_opt(
210210
i32::from(v.read_u16::<LittleEndian>().unwrap()),
211211
u32::from(v.read_u8().unwrap()),
212212
u32::from(v.read_u8().unwrap()),
213-
)
214-
} else {
215-
panic!("invalid type conversion from {:?} to date", val)
213+
) {
214+
return d;
215+
}
216216
}
217+
panic!("invalid type conversion from {:?} to date", val)
217218
}
218219
}
219220

220221
impl<'a> From<Value<'a>> for NaiveDateTime {
221222
fn from(val: Value<'a>) -> Self {
222223
if let ValueInner::Datetime(mut v) = val.0 {
223224
assert!(v.len() == 7 || v.len() == 11);
224-
let d = NaiveDate::from_ymd(
225+
if let Some(d) = NaiveDate::from_ymd_opt(
225226
i32::from(v.read_u16::<LittleEndian>().unwrap()),
226227
u32::from(v.read_u8().unwrap()),
227228
u32::from(v.read_u8().unwrap()),
228-
);
229+
) {
230+
let h = u32::from(v.read_u8().unwrap());
231+
let m = u32::from(v.read_u8().unwrap());
232+
let s = u32::from(v.read_u8().unwrap());
229233

230-
let h = u32::from(v.read_u8().unwrap());
231-
let m = u32::from(v.read_u8().unwrap());
232-
let s = u32::from(v.read_u8().unwrap());
234+
let d = if v.len() == 11 {
235+
let us = v.read_u32::<LittleEndian>().unwrap();
236+
d.and_hms_micro_opt(h, m, s, us)
237+
} else {
238+
d.and_hms_opt(h, m, s)
239+
};
233240

234-
if v.len() == 11 {
235-
let us = v.read_u32::<LittleEndian>().unwrap();
236-
d.and_hms_micro(h, m, s, us)
237-
} else {
238-
d.and_hms(h, m, s)
241+
if let Some(d) = d {
242+
return d;
243+
}
239244
}
240-
} else {
241-
panic!("invalid type conversion from {:?} to datetime", val)
242245
}
246+
panic!("invalid type conversion from {:?} to datetime", val)
243247
}
244248
}
245249

@@ -438,13 +442,16 @@ mod tests {
438442
rt!(
439443
time,
440444
chrono::NaiveDate,
441-
chrono::Local::today().naive_local(),
445+
chrono::Local::now().date_naive(),
442446
ColumnType::MYSQL_TYPE_DATE
443447
);
444448
rt!(
445449
datetime,
446450
chrono::NaiveDateTime,
447-
chrono::Utc.ymd(1989, 12, 7).and_hms(8, 0, 4).naive_utc(),
451+
chrono::Utc
452+
.with_ymd_and_hms(1989, 12, 7, 8, 0, 4)
453+
.unwrap()
454+
.naive_utc(),
448455
ColumnType::MYSQL_TYPE_DATETIME
449456
);
450457
rt!(

src/value/encode.rs

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::myc::constants::{ColumnFlags, ColumnType};
22
use crate::myc::io::WriteMysqlExt;
33
use crate::Column;
44
use byteorder::{LittleEndian, WriteBytesExt};
5-
use std::io::{self, Write};
5+
use std::io::{self, ErrorKind::Other, Write};
66

77
/// Implementors of this trait can be sent as a single resultset value to a MySQL/MariaDB client.
88
pub trait ToMysqlValue {
@@ -392,10 +392,10 @@ impl ToMysqlValue for [u8] {
392392

393393
impl ToMysqlValue for Vec<u8> {
394394
fn to_mysql_text<W: Write>(&self, w: &mut W) -> io::Result<()> {
395-
(&self[..]).to_mysql_text(w)
395+
(self[..]).to_mysql_text(w)
396396
}
397397
fn to_mysql_bin<W: Write>(&self, w: &mut W, c: &Column) -> io::Result<()> {
398-
(&self[..]).to_mysql_bin(w, c)
398+
(self[..]).to_mysql_bin(w, c)
399399
}
400400
}
401401

@@ -563,16 +563,22 @@ impl ToMysqlValue for myc::value::Value {
563563
myc::value::Value::Float(f) => f.to_mysql_text(w),
564564
myc::value::Value::Double(f) => f.to_mysql_text(w),
565565
myc::value::Value::Date(y, mo, d, h, mi, s, us) => {
566-
NaiveDate::from_ymd(i32::from(y), u32::from(mo), u32::from(d))
567-
.and_hms_micro(u32::from(h), u32::from(mi), u32::from(s), us)
566+
NaiveDate::from_ymd_opt(i32::from(y), u32::from(mo), u32::from(d))
567+
.ok_or_else(|| {
568+
io::Error::new(Other, format!("invalid date: y {} mo {} d {}", y, mo, d))
569+
})?
570+
.and_hms_micro_opt(u32::from(h), u32::from(mi), u32::from(s), us)
571+
.ok_or_else(|| {
572+
io::Error::new(
573+
Other,
574+
format!("invalid date: h {} mi {} s {} us {}", h, mi, s, us),
575+
)
576+
})?
568577
.to_mysql_text(w)
569578
}
570579
myc::value::Value::Time(neg, d, h, m, s, us) => {
571580
if neg {
572-
return Err(io::Error::new(
573-
io::ErrorKind::Other,
574-
"negative times not yet supported",
575-
));
581+
return Err(io::Error::new(Other, "negative times not yet supported"));
576582
}
577583
(chrono::Duration::days(i64::from(d))
578584
+ chrono::Duration::hours(i64::from(h))
@@ -628,16 +634,22 @@ impl ToMysqlValue for myc::value::Value {
628634
myc::value::Value::Float(f) => f.to_mysql_bin(w, c),
629635
myc::value::Value::Double(f) => f.to_mysql_bin(w, c),
630636
myc::value::Value::Date(y, mo, d, h, mi, s, us) => {
631-
NaiveDate::from_ymd(i32::from(y), u32::from(mo), u32::from(d))
632-
.and_hms_micro(u32::from(h), u32::from(mi), u32::from(s), us)
637+
NaiveDate::from_ymd_opt(i32::from(y), u32::from(mo), u32::from(d))
638+
.ok_or_else(|| {
639+
io::Error::new(Other, format!("invalid date: y {} mo {} d {}", y, mo, d))
640+
})?
641+
.and_hms_micro_opt(u32::from(h), u32::from(mi), u32::from(s), us)
642+
.ok_or_else(|| {
643+
io::Error::new(
644+
Other,
645+
format!("invalid date: h {} mi {} s {} us {}", h, mi, s, us),
646+
)
647+
})?
633648
.to_mysql_bin(w, c)
634649
}
635650
myc::value::Value::Time(neg, d, h, m, s, us) => {
636651
if neg {
637-
return Err(io::Error::new(
638-
io::ErrorKind::Other,
639-
"negative times not yet supported",
640-
));
652+
return Err(io::Error::new(Other, "negative times not yet supported"));
641653
}
642654
(chrono::Duration::days(i64::from(d))
643655
+ chrono::Duration::hours(i64::from(h))
@@ -719,15 +731,14 @@ mod tests {
719731
rt!(opt_none, Option<u8>, None);
720732
rt!(opt_some, Option<u8>, Some(1));
721733

722-
rt!(
723-
time,
724-
chrono::NaiveDate,
725-
chrono::Local::today().naive_local()
726-
);
734+
rt!(time, chrono::NaiveDate, chrono::Local::now().date_naive());
727735
rt!(
728736
datetime,
729737
chrono::NaiveDateTime,
730-
chrono::Utc.ymd(1989, 12, 7).and_hms(8, 0, 4).naive_utc()
738+
chrono::Utc
739+
.with_ymd_and_hms(1989, 12, 7, 8, 0, 4)
740+
.unwrap()
741+
.naive_utc()
731742
);
732743
rt!(dur, time::Duration, time::Duration::from_secs(1893));
733744
rt!(dur_micro, time::Duration, time::Duration::new(1893, 5000));
@@ -911,13 +922,16 @@ mod tests {
911922
rt!(
912923
time,
913924
chrono::NaiveDate,
914-
chrono::Local::today().naive_local(),
925+
chrono::Local::now().date_naive(),
915926
ColumnType::MYSQL_TYPE_DATE
916927
);
917928
rt!(
918929
datetime,
919930
chrono::NaiveDateTime,
920-
chrono::Utc.ymd(1989, 12, 7).and_hms(8, 0, 4).naive_utc(),
931+
chrono::Utc
932+
.with_ymd_and_hms(1989, 12, 7, 8, 0, 4)
933+
.unwrap()
934+
.naive_utc(),
921935
ColumnType::MYSQL_TYPE_DATETIME
922936
);
923937
rt!(

tests/async.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,10 @@ fn insert_exec() {
508508
);
509509
assert_eq!(
510510
Into::<chrono::NaiveDateTime>::into(params[3].value),
511-
chrono::NaiveDate::from_ymd(2018, 4, 6).and_hms(13, 0, 56)
511+
chrono::NaiveDate::from_ymd_opt(2018, 4, 6)
512+
.unwrap()
513+
.and_hms_opt(13, 0, 56)
514+
.unwrap()
512515
);
513516
assert_eq!(Into::<&str>::into(params[4].value), "token199");
514517
assert_eq!(Into::<&str>::into(params[5].value), "rsstoken199");

tests/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ where
147147
#[cfg(all(feature = "tls", unix))]
148148
fn with_tls(mut self, client: bool, server: bool, use_client_certs: bool) -> Self {
149149
use std::fs::File;
150-
use std::io::Write;
151150

152151
use mysql::ClientIdentity;
153152

@@ -998,7 +997,10 @@ fn insert_exec() {
998997
);
999998
assert_eq!(
1000999
Into::<chrono::NaiveDateTime>::into(params[3].value),
1001-
chrono::NaiveDate::from_ymd(2018, 4, 6).and_hms(13, 0, 56)
1000+
chrono::NaiveDate::from_ymd_opt(2018, 4, 6)
1001+
.unwrap()
1002+
.and_hms_opt(13, 0, 56)
1003+
.unwrap()
10021004
);
10031005
assert_eq!(Into::<&str>::into(params[4].value), "token199");
10041006
assert_eq!(Into::<&str>::into(params[5].value), "rsstoken199");

0 commit comments

Comments
 (0)