@@ -86,10 +86,9 @@ macro_rules! define_fn_to_int {
86
86
flt_to_int!( self . get_f32_unchecked( ) ?, f32 , $type) ,
87
87
NativeType :: Double =>
88
88
flt_to_int!( self . get_f64_unchecked( ) ?, f64 , $type) ,
89
- NativeType :: Char |
90
- NativeType :: Clob |
91
- NativeType :: Number =>
92
- Ok ( self . get_cow_str( ) ?. parse( ) ?) ,
89
+ NativeType :: Char =>Ok ( self . get_cow_str_unchecked( ) ?. parse( ) ?) ,
90
+ NativeType :: Number =>Ok ( self . get_str_unchecked( ) ?. parse( ) ?) ,
91
+ NativeType :: Clob =>Ok ( self . get_clob_as_string_unchecked( ) ?. parse( ) ?) ,
93
92
_ =>
94
93
self . invalid_conversion_to_rust_type( stringify!( $type) )
95
94
}
@@ -445,14 +444,6 @@ impl SqlValue<'_> {
445
444
}
446
445
}
447
446
448
- fn get_cow_str ( & self ) ->Result < Cow < str > > {
449
- match self . native_type {
450
- NativeType :: Char |NativeType :: Number =>self . get_cow_str_unchecked ( ) ,
451
- NativeType :: Clob =>Ok ( self . get_clob_as_string_unchecked ( ) ?. into ( ) ) ,
452
- _ =>self . invalid_conversion_to_rust_type ( "String" ) ,
453
- }
454
- }
455
-
456
447
//
457
448
// get_TYPE_unchecked methods
458
449
//
@@ -497,6 +488,20 @@ impl SqlValue<'_> {
497
488
}
498
489
}
499
490
491
+ /// Gets the SQL value as utf8 string. The native_type must be
492
+ /// NativeType::Char or NativeType::Number. Otherwise, this may cause access
493
+ /// violation.
494
+ /// Unlike get_cow_str_unchecked() this doesn't check whether the byte sequence
495
+ /// is a valid UTF-8.
496
+ fn get_str_unchecked ( & self ) ->Result < & str > {
497
+ self . check_not_null ( ) ?;
498
+ unsafe {
499
+ let bytes =dpiData_getBytes ( self . data ( ) ?) ;
500
+ let s = slice:: from_raw_parts ( ( * bytes) . ptr as * mut u8 , ( * bytes) . length as usize ) ;
501
+ Ok ( str:: from_utf8_unchecked ( s) )
502
+ }
503
+ }
504
+
500
505
/// Gets the SQL value as Vec<u8>. The native_type must be
501
506
/// NativeType::Raw. Otherwise, this may cause access violation.
502
507
fn get_raw_unchecked ( & self ) ->Result < Vec < u8 > > {
@@ -907,9 +912,9 @@ impl SqlValue<'_> {
907
912
NativeType :: UInt64 =>Ok ( self . get_u64_unchecked ( ) ?. try_into ( ) ?) ,
908
913
NativeType :: Float =>flt_to_int ! ( self . get_f32_unchecked( ) ?, f32 , i64 ) ,
909
914
NativeType :: Double =>flt_to_int ! ( self . get_f64_unchecked( ) ?, f64 , i64 ) ,
910
- NativeType :: Char | NativeType :: Clob | NativeType :: Number =>{
911
- Ok ( self . get_cow_str ( ) ?. parse ( ) ?)
912
- }
915
+ NativeType :: Char =>Ok ( self . get_cow_str_unchecked ( ) ? . parse ( ) ? ) ,
916
+ NativeType :: Number => Ok ( self . get_str_unchecked ( ) ?. parse ( ) ?) ,
917
+ NativeType :: Clob => Ok ( self . get_clob_as_string_unchecked ( ) ? . parse ( ) ? ) ,
913
918
_ =>self . invalid_conversion_to_rust_type ( "i64" ) ,
914
919
}
915
920
}
@@ -939,9 +944,9 @@ impl SqlValue<'_> {
939
944
NativeType :: UInt64 =>self . get_u64_unchecked ( ) ,
940
945
NativeType :: Float =>flt_to_int ! ( self . get_f32_unchecked( ) ?, f32 , u64 ) ,
941
946
NativeType :: Double =>flt_to_int ! ( self . get_f64_unchecked( ) ?, f64 , u64 ) ,
942
- NativeType :: Char | NativeType :: Clob | NativeType :: Number =>{
943
- Ok ( self . get_cow_str ( ) ?. parse ( ) ?)
944
- }
947
+ NativeType :: Char =>Ok ( self . get_cow_str_unchecked ( ) ? . parse ( ) ? ) ,
948
+ NativeType :: Number => Ok ( self . get_str_unchecked ( ) ?. parse ( ) ?) ,
949
+ NativeType :: Clob => Ok ( self . get_clob_as_string_unchecked ( ) ? . parse ( ) ? ) ,
945
950
_ =>self . invalid_conversion_to_rust_type ( "u64" ) ,
946
951
}
947
952
}
@@ -954,9 +959,9 @@ impl SqlValue<'_> {
954
959
NativeType :: UInt64 =>Ok ( self . get_u64_unchecked ( ) ?as f32 ) ,
955
960
NativeType :: Float =>self . get_f32_unchecked ( ) ,
956
961
NativeType :: Double =>Ok ( self . get_f64_unchecked ( ) ?as f32 ) ,
957
- NativeType :: Char | NativeType :: Clob | NativeType :: Number =>{
958
- Ok ( self . get_cow_str ( ) ?. parse ( ) ?)
959
- }
962
+ NativeType :: Char =>Ok ( self . get_cow_str_unchecked ( ) ? . parse ( ) ? ) ,
963
+ NativeType :: Number => Ok ( self . get_str_unchecked ( ) ?. parse ( ) ?) ,
964
+ NativeType :: Clob => Ok ( self . get_clob_as_string_unchecked ( ) ? . parse ( ) ? ) ,
960
965
_ =>self . invalid_conversion_to_rust_type ( "f32" ) ,
961
966
}
962
967
}
@@ -969,9 +974,9 @@ impl SqlValue<'_> {
969
974
NativeType :: UInt64 =>Ok ( self . get_u64_unchecked ( ) ?as f64 ) ,
970
975
NativeType :: Float =>Ok ( self . get_f32_unchecked ( ) ?as f64 ) ,
971
976
NativeType :: Double =>self . get_f64_unchecked ( ) ,
972
- NativeType :: Char | NativeType :: Clob | NativeType :: Number =>{
973
- Ok ( self . get_cow_str ( ) ?. parse ( ) ?)
974
- }
977
+ NativeType :: Char =>Ok ( self . get_cow_str_unchecked ( ) ? . parse ( ) ? ) ,
978
+ NativeType :: Number => Ok ( self . get_str_unchecked ( ) ?. parse ( ) ?) ,
979
+ NativeType :: Clob => Ok ( self . get_clob_as_string_unchecked ( ) ? . parse ( ) ? ) ,
975
980
_ =>self . invalid_conversion_to_rust_type ( "f64" ) ,
976
981
}
977
982
}
@@ -983,7 +988,8 @@ impl SqlValue<'_> {
983
988
NativeType :: UInt64 =>Ok ( self . get_u64_unchecked ( ) ?. to_string ( ) ) ,
984
989
NativeType :: Float =>Ok ( self . get_f32_unchecked ( ) ?. to_string ( ) ) ,
985
990
NativeType :: Double =>Ok ( self . get_f64_unchecked ( ) ?. to_string ( ) ) ,
986
- NativeType :: Char |NativeType :: Number =>Ok ( self . get_cow_str_unchecked ( ) ?. into ( ) ) ,
991
+ NativeType :: Char =>Ok ( self . get_cow_str_unchecked ( ) ?. into ( ) ) ,
992
+ NativeType :: Number =>Ok ( self . get_str_unchecked ( ) ?. into ( ) ) ,
987
993
NativeType :: Raw =>self . get_raw_as_hex_string_unchecked ( ) ,
988
994
NativeType :: Timestamp =>Ok ( self . get_timestamp_unchecked ( ) ?. to_string ( ) ) ,
989
995
NativeType :: IntervalDS =>Ok ( self . get_interval_ds_unchecked ( ) ?. to_string ( ) ) ,
@@ -1012,7 +1018,8 @@ impl SqlValue<'_> {
1012
1018
match self . native_type {
1013
1019
NativeType :: Raw =>self . get_raw_unchecked ( ) ,
1014
1020
NativeType :: Blob =>self . get_blob_unchecked ( ) ,
1015
- NativeType :: Char |NativeType :: Clob =>Ok ( parse_str_into_raw ( & self . get_cow_str ( ) ?) ?) ,
1021
+ NativeType :: Char =>Ok ( parse_str_into_raw ( & self . get_cow_str_unchecked ( ) ?) ?) ,
1022
+ NativeType :: Clob =>Ok ( parse_str_into_raw ( & self . get_clob_as_string_unchecked ( ) ?) ?) ,
1016
1023
_ =>self . invalid_conversion_to_rust_type ( "raw" ) ,
1017
1024
}
1018
1025
}
@@ -1022,7 +1029,8 @@ impl SqlValue<'_> {
1022
1029
pub ( crate ) fn to_timestamp ( & self ) ->Result < Timestamp > {
1023
1030
match self . native_type {
1024
1031
NativeType :: Timestamp =>self . get_timestamp_unchecked ( ) ,
1025
- NativeType :: Char |NativeType :: Clob =>Ok ( self . get_cow_str ( ) ?. parse ( ) ?) ,
1032
+ NativeType :: Char =>Ok ( self . get_cow_str_unchecked ( ) ?. parse ( ) ?) ,
1033
+ NativeType :: Clob =>Ok ( self . get_clob_as_string_unchecked ( ) ?. parse ( ) ?) ,
1026
1034
_ =>self . invalid_conversion_to_rust_type ( "Timestamp" ) ,
1027
1035
}
1028
1036
}
@@ -1032,7 +1040,8 @@ impl SqlValue<'_> {
1032
1040
pub ( crate ) fn to_interval_ds ( & self ) ->Result < IntervalDS > {
1033
1041
match self . native_type {
1034
1042
NativeType :: IntervalDS =>self . get_interval_ds_unchecked ( ) ,
1035
- NativeType :: Char |NativeType :: Clob =>Ok ( self . get_cow_str ( ) ?. parse ( ) ?) ,
1043
+ NativeType :: Char =>Ok ( self . get_cow_str_unchecked ( ) ?. parse ( ) ?) ,
1044
+ NativeType :: Clob =>Ok ( self . get_clob_as_string_unchecked ( ) ?. parse ( ) ?) ,
1036
1045
_ =>self . invalid_conversion_to_rust_type ( "IntervalDS" ) ,
1037
1046
}
1038
1047
}
@@ -1042,7 +1051,8 @@ impl SqlValue<'_> {
1042
1051
pub ( crate ) fn to_interval_ym ( & self ) ->Result < IntervalYM > {
1043
1052
match self . native_type {
1044
1053
NativeType :: IntervalYM =>self . get_interval_ym_unchecked ( ) ,
1045
- NativeType :: Char |NativeType :: Clob =>Ok ( self . get_cow_str ( ) ?. parse ( ) ?) ,
1054
+ NativeType :: Char =>Ok ( self . get_cow_str_unchecked ( ) ?. parse ( ) ?) ,
1055
+ NativeType :: Clob =>Ok ( self . get_clob_as_string_unchecked ( ) ?. parse ( ) ?) ,
1046
1056
_ =>self . invalid_conversion_to_rust_type ( "IntervalYM" ) ,
1047
1057
}
1048
1058
}