@@ -2,7 +2,7 @@ use crate::myc::constants::{ColumnFlags, ColumnType};
22use crate :: myc:: io:: WriteMysqlExt ;
33use crate :: Column ;
44use 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.
88pub trait ToMysqlValue {
@@ -564,17 +564,21 @@ impl ToMysqlValue for myc::value::Value {
564564 myc:: value:: Value :: Double ( f) => f. to_mysql_text ( w) ,
565565 myc:: value:: Value :: Date ( y, mo, d, h, mi, s, us) => {
566566 NaiveDate :: from_ymd_opt ( i32:: from ( y) , u32:: from ( mo) , u32:: from ( d) )
567- . unwrap_or_else ( || panic ! ( "invalid date: y {} mo {} d {}" , y, mo, d) )
567+ . ok_or_else ( || {
568+ io:: Error :: new ( Other , format ! ( "invalid date: y {} mo {} d {}" , y, mo, d) )
569+ } ) ?
568570 . and_hms_micro_opt ( u32:: from ( h) , u32:: from ( mi) , u32:: from ( s) , us)
569- . unwrap_or_else ( || panic ! ( "invalid date: h {} mi {} s {} us {}" , h, mi, 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+ } ) ?
570577 . to_mysql_text ( w)
571578 }
572579 myc:: value:: Value :: Time ( neg, d, h, m, s, us) => {
573580 if neg {
574- return Err ( io:: Error :: new (
575- io:: ErrorKind :: Other ,
576- "negative times not yet supported" ,
577- ) ) ;
581+ return Err ( io:: Error :: new ( Other , "negative times not yet supported" ) ) ;
578582 }
579583 ( chrono:: Duration :: days ( i64:: from ( d) )
580584 + chrono:: Duration :: hours ( i64:: from ( h) )
@@ -631,17 +635,21 @@ impl ToMysqlValue for myc::value::Value {
631635 myc:: value:: Value :: Double ( f) => f. to_mysql_bin ( w, c) ,
632636 myc:: value:: Value :: Date ( y, mo, d, h, mi, s, us) => {
633637 NaiveDate :: from_ymd_opt ( i32:: from ( y) , u32:: from ( mo) , u32:: from ( d) )
634- . unwrap_or_else ( || panic ! ( "invalid date: y {} mo {} d {}" , y, mo, d) )
638+ . ok_or_else ( || {
639+ io:: Error :: new ( Other , format ! ( "invalid date: y {} mo {} d {}" , y, mo, d) )
640+ } ) ?
635641 . and_hms_micro_opt ( u32:: from ( h) , u32:: from ( mi) , u32:: from ( s) , us)
636- . unwrap_or_else ( || panic ! ( "invalid date: h {} mi {} s {} us {}" , h, mi, 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+ } ) ?
637648 . to_mysql_bin ( w, c)
638649 }
639650 myc:: value:: Value :: Time ( neg, d, h, m, s, us) => {
640651 if neg {
641- return Err ( io:: Error :: new (
642- io:: ErrorKind :: Other ,
643- "negative times not yet supported" ,
644- ) ) ;
652+ return Err ( io:: Error :: new ( Other , "negative times not yet supported" ) ) ;
645653 }
646654 ( chrono:: Duration :: days ( i64:: from ( d) )
647655 + chrono:: Duration :: hours ( i64:: from ( h) )
0 commit comments