@@ -958,8 +958,7 @@ pub trait QueryBuilder: QuotedBuilder + EscapeBuilder + TableRefBuilder {
958
958
write ! ( sql, " WHEN " ) . unwrap ( ) ;
959
959
self . prepare_simple_expr ( & order_expr. expr , sql, collector) ;
960
960
write ! ( sql, "=" ) . unwrap ( ) ;
961
- let value = self . value_to_string ( value) ;
962
- write ! ( sql, "{}" , value) . unwrap ( ) ;
961
+ write ! ( sql, "{}" , value. to_sql_string( ) ) . unwrap ( ) ;
963
962
write ! ( sql, " THEN {} " , i) . unwrap ( ) ;
964
963
i += 1 ;
965
964
}
@@ -975,8 +974,7 @@ pub trait QueryBuilder: QuotedBuilder + EscapeBuilder + TableRefBuilder {
975
974
976
975
/// Write [`Value`] inline.
977
976
fn prepare_constant ( & self , value : & Value , sql : & mut SqlWriter ) {
978
- let string = self . value_to_string ( value) ;
979
- write ! ( sql, "{}" , string) . unwrap ( ) ;
977
+ write ! ( sql, "{}" , value. to_sql_string( ) ) . unwrap ( ) ;
980
978
}
981
979
982
980
/// Translate a `&[ValueTuple]` into a VALUES list.
@@ -1048,144 +1046,6 @@ pub trait QueryBuilder: QuotedBuilder + EscapeBuilder + TableRefBuilder {
1048
1046
}
1049
1047
}
1050
1048
1051
- /// Convert a SQL value into syntax-specific string
1052
- fn value_to_string ( & self , v : & Value ) -> String {
1053
- let mut s = String :: new ( ) ;
1054
- match v {
1055
- Value :: Bool ( None )
1056
- | Value :: TinyInt ( None )
1057
- | Value :: SmallInt ( None )
1058
- | Value :: Int ( None )
1059
- | Value :: BigInt ( None )
1060
- | Value :: TinyUnsigned ( None )
1061
- | Value :: SmallUnsigned ( None )
1062
- | Value :: Unsigned ( None )
1063
- | Value :: BigUnsigned ( None )
1064
- | Value :: Float ( None )
1065
- | Value :: Double ( None )
1066
- | Value :: String ( None )
1067
- | Value :: Char ( None )
1068
- | Value :: Bytes ( None ) => write ! ( s, "NULL" ) . unwrap ( ) ,
1069
- #[ cfg( feature = "with-json" ) ]
1070
- Value :: Json ( None ) => write ! ( s, "NULL" ) . unwrap ( ) ,
1071
- #[ cfg( feature = "with-chrono" ) ]
1072
- Value :: ChronoDate ( None ) => write ! ( s, "NULL" ) . unwrap ( ) ,
1073
- #[ cfg( feature = "with-chrono" ) ]
1074
- Value :: ChronoTime ( None ) => write ! ( s, "NULL" ) . unwrap ( ) ,
1075
- #[ cfg( feature = "with-chrono" ) ]
1076
- Value :: ChronoDateTime ( None ) => write ! ( s, "NULL" ) . unwrap ( ) ,
1077
- #[ cfg( feature = "with-chrono" ) ]
1078
- Value :: ChronoDateTimeUtc ( None ) => write ! ( s, "NULL" ) . unwrap ( ) ,
1079
- #[ cfg( feature = "with-chrono" ) ]
1080
- Value :: ChronoDateTimeLocal ( None ) => write ! ( s, "NULL" ) . unwrap ( ) ,
1081
- #[ cfg( feature = "with-chrono" ) ]
1082
- Value :: ChronoDateTimeWithTimeZone ( None ) => write ! ( s, "NULL" ) . unwrap ( ) ,
1083
- #[ cfg( feature = "with-time" ) ]
1084
- Value :: TimeDate ( None ) => write ! ( s, "NULL" ) . unwrap ( ) ,
1085
- #[ cfg( feature = "with-time" ) ]
1086
- Value :: TimeTime ( None ) => write ! ( s, "NULL" ) . unwrap ( ) ,
1087
- #[ cfg( feature = "with-time" ) ]
1088
- Value :: TimeDateTime ( None ) => write ! ( s, "NULL" ) . unwrap ( ) ,
1089
- #[ cfg( feature = "with-time" ) ]
1090
- Value :: TimeDateTimeWithTimeZone ( None ) => write ! ( s, "NULL" ) . unwrap ( ) ,
1091
- #[ cfg( feature = "with-rust_decimal" ) ]
1092
- Value :: Decimal ( None ) => write ! ( s, "NULL" ) . unwrap ( ) ,
1093
- #[ cfg( feature = "with-bigdecimal" ) ]
1094
- Value :: BigDecimal ( None ) => write ! ( s, "NULL" ) . unwrap ( ) ,
1095
- #[ cfg( feature = "with-uuid" ) ]
1096
- Value :: Uuid ( None ) => write ! ( s, "NULL" ) . unwrap ( ) ,
1097
- #[ cfg( feature = "with-ipnetwork" ) ]
1098
- Value :: IpNetwork ( None ) => write ! ( s, "NULL" ) . unwrap ( ) ,
1099
- #[ cfg( feature = "with-mac_address" ) ]
1100
- Value :: MacAddress ( None ) => write ! ( s, "NULL" ) . unwrap ( ) ,
1101
- #[ cfg( feature = "postgres-array" ) ]
1102
- Value :: Array ( None ) => write ! ( s, "NULL" ) . unwrap ( ) ,
1103
- Value :: Bool ( Some ( b) ) => write ! ( s, "{}" , if * b { "TRUE" } else { "FALSE" } ) . unwrap ( ) ,
1104
- Value :: TinyInt ( Some ( v) ) => write ! ( s, "{}" , v) . unwrap ( ) ,
1105
- Value :: SmallInt ( Some ( v) ) => write ! ( s, "{}" , v) . unwrap ( ) ,
1106
- Value :: Int ( Some ( v) ) => write ! ( s, "{}" , v) . unwrap ( ) ,
1107
- Value :: BigInt ( Some ( v) ) => write ! ( s, "{}" , v) . unwrap ( ) ,
1108
- Value :: TinyUnsigned ( Some ( v) ) => write ! ( s, "{}" , v) . unwrap ( ) ,
1109
- Value :: SmallUnsigned ( Some ( v) ) => write ! ( s, "{}" , v) . unwrap ( ) ,
1110
- Value :: Unsigned ( Some ( v) ) => write ! ( s, "{}" , v) . unwrap ( ) ,
1111
- Value :: BigUnsigned ( Some ( v) ) => write ! ( s, "{}" , v) . unwrap ( ) ,
1112
- Value :: Float ( Some ( v) ) => write ! ( s, "{}" , v) . unwrap ( ) ,
1113
- Value :: Double ( Some ( v) ) => write ! ( s, "{}" , v) . unwrap ( ) ,
1114
- Value :: String ( Some ( v) ) => self . write_string_quoted ( v, & mut s) ,
1115
- Value :: Char ( Some ( v) ) => {
1116
- self . write_string_quoted ( std:: str:: from_utf8 ( & [ * v as u8 ] ) . unwrap ( ) , & mut s)
1117
- }
1118
- Value :: Bytes ( Some ( v) ) => write ! (
1119
- s,
1120
- "x'{}'" ,
1121
- v. iter( ) . map( |b| format!( "{:02X}" , b) ) . collect:: <String >( )
1122
- )
1123
- . unwrap ( ) ,
1124
- #[ cfg( feature = "with-json" ) ]
1125
- Value :: Json ( Some ( v) ) => self . write_string_quoted ( & v. to_string ( ) , & mut s) ,
1126
- #[ cfg( feature = "with-chrono" ) ]
1127
- Value :: ChronoDate ( Some ( v) ) => write ! ( s, "'{}'" , v. format( "%Y-%m-%d" ) ) . unwrap ( ) ,
1128
- #[ cfg( feature = "with-chrono" ) ]
1129
- Value :: ChronoTime ( Some ( v) ) => write ! ( s, "'{}'" , v. format( "%H:%M:%S" ) ) . unwrap ( ) ,
1130
- #[ cfg( feature = "with-chrono" ) ]
1131
- Value :: ChronoDateTime ( Some ( v) ) => {
1132
- write ! ( s, "'{}'" , v. format( "%Y-%m-%d %H:%M:%S" ) ) . unwrap ( )
1133
- }
1134
- #[ cfg( feature = "with-chrono" ) ]
1135
- Value :: ChronoDateTimeUtc ( Some ( v) ) => {
1136
- write ! ( s, "'{}'" , v. format( "%Y-%m-%d %H:%M:%S %:z" ) ) . unwrap ( )
1137
- }
1138
- #[ cfg( feature = "with-chrono" ) ]
1139
- Value :: ChronoDateTimeLocal ( Some ( v) ) => {
1140
- write ! ( s, "'{}'" , v. format( "%Y-%m-%d %H:%M:%S %:z" ) ) . unwrap ( )
1141
- }
1142
- #[ cfg( feature = "with-chrono" ) ]
1143
- Value :: ChronoDateTimeWithTimeZone ( Some ( v) ) => {
1144
- write ! ( s, "'{}'" , v. format( "%Y-%m-%d %H:%M:%S %:z" ) ) . unwrap ( )
1145
- }
1146
- #[ cfg( feature = "with-time" ) ]
1147
- Value :: TimeDate ( Some ( v) ) => {
1148
- write ! ( s, "'{}'" , v. format( time_format:: FORMAT_DATE ) . unwrap( ) ) . unwrap ( )
1149
- }
1150
- #[ cfg( feature = "with-time" ) ]
1151
- Value :: TimeTime ( Some ( v) ) => {
1152
- write ! ( s, "'{}'" , v. format( time_format:: FORMAT_TIME ) . unwrap( ) ) . unwrap ( )
1153
- }
1154
- #[ cfg( feature = "with-time" ) ]
1155
- Value :: TimeDateTime ( Some ( v) ) => {
1156
- write ! ( s, "'{}'" , v. format( time_format:: FORMAT_DATETIME ) . unwrap( ) ) . unwrap ( )
1157
- }
1158
- #[ cfg( feature = "with-time" ) ]
1159
- Value :: TimeDateTimeWithTimeZone ( Some ( v) ) => write ! (
1160
- s,
1161
- "'{}'" ,
1162
- v. format( time_format:: FORMAT_DATETIME_TZ ) . unwrap( )
1163
- )
1164
- . unwrap ( ) ,
1165
- #[ cfg( feature = "with-rust_decimal" ) ]
1166
- Value :: Decimal ( Some ( v) ) => write ! ( s, "{}" , v) . unwrap ( ) ,
1167
- #[ cfg( feature = "with-bigdecimal" ) ]
1168
- Value :: BigDecimal ( Some ( v) ) => write ! ( s, "{}" , v) . unwrap ( ) ,
1169
- #[ cfg( feature = "with-uuid" ) ]
1170
- Value :: Uuid ( Some ( v) ) => write ! ( s, "'{}'" , v) . unwrap ( ) ,
1171
- #[ cfg( feature = "postgres-array" ) ]
1172
- Value :: Array ( Some ( v) ) => write ! (
1173
- s,
1174
- "'{{{}}}'" ,
1175
- v. iter( )
1176
- . map( |element| self . value_to_string( element) )
1177
- . collect:: <Vec <String >>( )
1178
- . join( "," )
1179
- )
1180
- . unwrap ( ) ,
1181
- #[ cfg( feature = "with-ipnetwork" ) ]
1182
- Value :: IpNetwork ( Some ( v) ) => write ! ( s, "'{}'" , v) . unwrap ( ) ,
1183
- #[ cfg( feature = "with-mac_address" ) ]
1184
- Value :: MacAddress ( Some ( v) ) => write ! ( s, "'{}'" , v) . unwrap ( ) ,
1185
- } ;
1186
- s
1187
- }
1188
-
1189
1049
#[ doc( hidden) ]
1190
1050
/// Write ON CONFLICT expression
1191
1051
fn prepare_on_conflict (
@@ -1414,12 +1274,12 @@ pub trait QueryBuilder: QuotedBuilder + EscapeBuilder + TableRefBuilder {
1414
1274
match * frame {
1415
1275
Frame :: UnboundedPreceding => write ! ( sql, " UNBOUNDED PRECEDING " ) . unwrap ( ) ,
1416
1276
Frame :: Preceding ( v) => {
1417
- self . prepare_value ( & Some ( v ) . into ( ) , sql, collector) ;
1277
+ self . prepare_value ( & v . into ( ) , sql, collector) ;
1418
1278
write ! ( sql, " PRECEDING " ) . unwrap ( ) ;
1419
1279
}
1420
1280
Frame :: CurrentRow => write ! ( sql, " CURRENT ROW " ) . unwrap ( ) ,
1421
1281
Frame :: Following ( v) => {
1422
- self . prepare_value ( & Some ( v ) . into ( ) , sql, collector) ;
1282
+ self . prepare_value ( & v . into ( ) , sql, collector) ;
1423
1283
write ! ( sql, " FOLLOWING " ) . unwrap ( ) ;
1424
1284
}
1425
1285
Frame :: UnboundedFollowing => write ! ( sql, " UNBOUNDED FOLLOWING " ) . unwrap ( ) ,
0 commit comments