@@ -511,36 +511,28 @@ impl<'a> ToSql for Value<'a> {
511511 ( Value :: Integer ( integer) , & PostgresType :: OID ) => integer. map ( |integer| ( integer as u32 ) . to_sql ( ty, out) ) ,
512512 ( Value :: Integer ( integer) , _) => integer. map ( |integer| ( integer as i64 ) . to_sql ( ty, out) ) ,
513513 ( Value :: Float ( float) , & PostgresType :: FLOAT8 ) => float. map ( |float| ( float as f64 ) . to_sql ( ty, out) ) ,
514- #[ cfg( feature = "bigdecimal" ) ]
515- ( Value :: Float ( float) , & PostgresType :: NUMERIC ) => float
516- . map ( |float| BigDecimal :: from_f32 ( float) . unwrap ( ) )
517- . map ( DecimalWrapper )
518- . map ( |dw| dw. to_sql ( ty, out) ) ,
514+ ( Value :: Float ( _) , & PostgresType :: NUMERIC ) => {
515+ let kind = ErrorKind :: conversion ( format ! (
516+ "Writing a float to a {} column is unstable." ,
517+ PostgresType :: NUMERIC
518+ ) ) ;
519+ return Err ( Error :: builder ( kind) . build ( ) . into ( ) ) ;
520+ }
519521 ( Value :: Float ( float) , _) => float. map ( |float| float. to_sql ( ty, out) ) ,
520522 ( Value :: Double ( double) , & PostgresType :: FLOAT4 ) => double. map ( |double| ( double as f32 ) . to_sql ( ty, out) ) ,
521- #[ cfg( feature = "bigdecimal" ) ]
522- ( Value :: Double ( double) , & PostgresType :: NUMERIC ) => double
523- . map ( |double| BigDecimal :: from_f64 ( double) . unwrap ( ) )
524- . map ( DecimalWrapper )
525- . map ( |dw| dw. to_sql ( ty, out) ) ,
523+ ( Value :: Double ( _) , & PostgresType :: NUMERIC ) => {
524+ let kind = ErrorKind :: conversion ( format ! (
525+ "Writing a double to a {} column is unstable." ,
526+ PostgresType :: NUMERIC
527+ ) ) ;
528+ return Err ( Error :: builder ( kind) . build ( ) . into ( ) ) ;
529+ }
526530 ( Value :: Double ( double) , _) => double. map ( |double| double. to_sql ( ty, out) ) ,
527- #[ cfg( feature = "bigdecimal" ) ]
528- ( Value :: Numeric ( decimal) , & PostgresType :: FLOAT4 ) => decimal. as_ref ( ) . map ( |decimal| {
529- let f = decimal. to_string ( ) . parse :: < f32 > ( ) . expect ( "decimal to f32 conversion" ) ;
530- f. to_sql ( ty, out)
531- } ) ,
532- #[ cfg( feature = "bigdecimal" ) ]
533- ( Value :: Numeric ( decimal) , & PostgresType :: FLOAT8 ) => decimal. as_ref ( ) . map ( |decimal| {
534- let f = decimal. to_string ( ) . parse :: < f64 > ( ) . expect ( "decimal to f64 conversion" ) ;
535- f. to_sql ( ty, out)
536- } ) ,
537- #[ cfg( feature = "bigdecimal" ) ]
538531 ( Value :: Array ( values) , & PostgresType :: FLOAT4_ARRAY ) => values. as_ref ( ) . map ( |values| {
539532 let mut floats = Vec :: with_capacity ( values. len ( ) ) ;
540533
541534 for value in values. iter ( ) {
542535 let float = match value {
543- Value :: Numeric ( n) => n. as_ref ( ) . and_then ( |n| n. to_string ( ) . parse :: < f32 > ( ) . ok ( ) ) ,
544536 Value :: Float ( f) => * f,
545537 Value :: Double ( d) => d. map ( |d| d as f32 ) ,
546538 v => {
@@ -558,13 +550,11 @@ impl<'a> ToSql for Value<'a> {
558550
559551 floats. to_sql ( ty, out)
560552 } ) ,
561- #[ cfg( feature = "bigdecimal" ) ]
562553 ( Value :: Array ( values) , & PostgresType :: FLOAT8_ARRAY ) => values. as_ref ( ) . map ( |values| {
563554 let mut floats = Vec :: with_capacity ( values. len ( ) ) ;
564555
565556 for value in values. iter ( ) {
566557 let float = match value {
567- Value :: Numeric ( n) => n. as_ref ( ) . and_then ( |n| n. to_string ( ) . parse :: < f64 > ( ) . ok ( ) ) ,
568558 Value :: Float ( f) => f. map ( |f| f as f64 ) ,
569559 Value :: Double ( d) => * d,
570560 v => {
@@ -598,9 +588,10 @@ impl<'a> ToSql for Value<'a> {
598588 . as_ref ( )
599589 . map ( |decimal| DecimalWrapper ( decimal. clone ( ) ) . to_sql ( ty, out) ) ,
600590 #[ cfg( feature = "bigdecimal" ) ]
601- ( Value :: Numeric ( float) , _) => float
602- . as_ref ( )
603- . map ( |float| DecimalWrapper ( float. clone ( ) ) . to_sql ( ty, out) ) ,
591+ ( Value :: Numeric ( _) , typ) => {
592+ let kind = ErrorKind :: conversion ( format ! ( "Writing a decimal to a {} column is unstable." , typ) ) ;
593+ return Err ( Error :: builder ( kind) . build ( ) . into ( ) ) ;
594+ }
604595 #[ cfg( feature = "uuid" ) ]
605596 ( Value :: Text ( string) , & PostgresType :: UUID ) => string. as_ref ( ) . map ( |string| {
606597 let parsed_uuid: Uuid = string. parse ( ) ?;
0 commit comments