Skip to content

Commit 57d023f

Browse files
committed
Merge branch 'main' into c5soft/main
2 parents 296c027 + cf2cfa4 commit 57d023f

File tree

10 files changed

+246
-66
lines changed

10 files changed

+246
-66
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## 0.6.43
9+
- Fix decoding of small negative unsigned integer in Mssql.
10+
- The subdependency on aws-lc-rs (dependency of rustls) is no optional. You can use your own crypto provider (such as ring or openssl) by using the new crate feature `runtime-tokio-rustls-nocrypto` instead of `runtime-tokio-rustls`.
11+
812
## 0.6.42
913
- Fix `QueryBuilder` for Microsoft SQL Server: https://github.com/sqlpage/sqlx-oldapi/issues/11
1014
- Add support for Microsoft SQL Server DateTime columns in sqlx macros: macros https://github.com/sqlpage/sqlx-oldapi/issues/16

Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ members = [
2020

2121
[package]
2222
name = "sqlx-oldapi"
23-
version = "0.6.42"
23+
version = "0.6.43"
2424
license = "MIT OR Apache-2.0"
2525
readme = "README.md"
2626
repository = "https://github.com/lovasoa/sqlx"
@@ -90,15 +90,32 @@ runtime-tokio-native-tls = [
9090

9191
runtime-actix-rustls = ["runtime-tokio-rustls"]
9292
runtime-async-std-rustls = [
93+
"sqlx-core/runtime-async-std-rustls",
94+
"sqlx-macros/runtime-async-std-rustls",
95+
"aws_lc_rs",
96+
"tls12",
97+
"_rt-async-std",
98+
]
99+
runtime-async-std-rustls-nocrypto = [
93100
"sqlx-core/runtime-async-std-rustls",
94101
"sqlx-macros/runtime-async-std-rustls",
95102
"_rt-async-std",
96103
]
97104
runtime-tokio-rustls = [
98105
"sqlx-core/runtime-tokio-rustls",
99106
"sqlx-macros/runtime-tokio-rustls",
107+
"aws_lc_rs",
108+
"tls12",
100109
"_rt-tokio",
101110
]
111+
runtime-tokio-rustls-nocrypto = [
112+
"sqlx-core/runtime-tokio-rustls",
113+
"sqlx-macros/runtime-tokio-rustls",
114+
"_rt-tokio",
115+
]
116+
117+
aws_lc_rs = ["sqlx-core/aws_lc_rs"]
118+
tls12 = ["sqlx-core/tls12"]
102119

103120
# for conditional compilation
104121
_rt-async-std = []
@@ -126,8 +143,8 @@ bstr = ["sqlx-core/bstr"]
126143
git2 = ["sqlx-core/git2"]
127144

128145
[dependencies]
129-
sqlx-core = { package = "sqlx-core-oldapi", version = "0.6.42", path = "sqlx-core", default-features = false }
130-
sqlx-macros = { package = "sqlx-macros-oldapi", version = "0.6.42", path = "sqlx-macros", default-features = false, optional = true }
146+
sqlx-core = { package = "sqlx-core-oldapi", version = "0.6.43", path = "sqlx-core", default-features = false }
147+
sqlx-macros = { package = "sqlx-macros-oldapi", version = "0.6.43", path = "sqlx-macros", default-features = false, optional = true }
131148

132149
[dev-dependencies]
133150
anyhow = "1.0.52"

examples/postgres/axum-social-with-tests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ edition = "2021"
88
[dependencies]
99
# Primary crates
1010
axum = { version = "0.5.13", features = ["macros"] }
11-
sqlx = { package = "sqlx-oldapi", version = "0.6.42", path = "../../../", features = ["runtime-tokio-rustls", "postgres", "time", "uuid"] }
11+
sqlx = { package = "sqlx-oldapi", version = "0.6.43", path = "../../../", features = ["runtime-tokio-rustls", "postgres", "time", "uuid"] }
1212
tokio = { version = "1.20.1", features = ["rt-multi-thread", "macros"] }
1313

1414
# Important secondary crates

sqlx-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sqlx-cli"
3-
version = "0.6.42"
3+
version = "0.6.43"
44
description = "Command-line utility for SQLx, the Rust SQL toolkit."
55
edition = "2021"
66
readme = "README.md"

sqlx-core/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sqlx-core-oldapi"
3-
version = "0.6.42"
3+
version = "0.6.43"
44
repository = "https://github.com/lovasoa/sqlx"
55
description = "Core of SQLx, the rust SQL toolkit. Not intended to be used directly."
66
license = "MIT OR Apache-2.0"
@@ -93,6 +93,8 @@ _rt-async-std = []
9393
_rt-tokio = ["tokio-stream", "tokio-util"]
9494
_tls-native-tls = []
9595
_tls-rustls = ["rustls", "rustls-pemfile", "webpki-roots"]
96+
aws_lc_rs = ["rustls/aws_lc_rs", "sqlx-rt/aws_lc_rs"]
97+
tls12 = ["rustls/tls12"]
9698

9799
# support offline/decoupled building (enables serialization of `Describe`)
98100
offline = ["serde", "either/serde"]
@@ -101,7 +103,7 @@ offline = ["serde", "either/serde"]
101103
paste = "1.0.6"
102104
ahash = "0.8.3"
103105
atoi = "2.0.0"
104-
sqlx-rt = { path = "../sqlx-rt", version = "0.6.42", package = "sqlx-rt-oldapi" }
106+
sqlx-rt = { path = "../sqlx-rt", version = "0.6.43", package = "sqlx-rt-oldapi" }
105107
base64 = { version = "0.22", default-features = false, optional = true, features = ["std"] }
106108
bigdecimal_ = { version = "0.4.1", optional = true, package = "bigdecimal" }
107109
rust_decimal = { version = "1.19.0", optional = true }
@@ -144,7 +146,7 @@ percent-encoding = "2.1.0"
144146
rand = { version = "0.8", default-features = false, optional = true, features = ["std", "std_rng"] }
145147
regex = { version = "1.5.5", optional = true }
146148
rsa = { version = "0.9.2", optional = true }
147-
rustls = { version = "0.23", optional = true }
149+
rustls = { version = "0.23", optional = true, default-features = false }
148150
rustls-pemfile = { version = "2.1", optional = true }
149151
serde = { version = "1.0.132", features = ["derive", "rc"], optional = true }
150152
serde_json = { version = "1.0.73", features = ["raw_value"], optional = true }

sqlx-core/src/mssql/types/int.rs

Lines changed: 85 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::any::type_name;
22
use std::convert::TryFrom;
3-
use std::i16;
43

54
use crate::decode::Decode;
65
use crate::encode::{Encode, IsNull};
@@ -27,10 +26,85 @@ impl Encode<'_, Mssql> for i8 {
2726
}
2827
}
2928

29+
fn decode_int_bytes<T, U, const N: usize>(
30+
bytes: &[u8],
31+
type_info: &MssqlTypeInfo,
32+
from_le_bytes: impl Fn([u8; N]) -> U,
33+
) -> Result<T, BoxDynError>
34+
where
35+
T: TryFrom<U>,
36+
T::Error: std::error::Error + Send + Sync + 'static,
37+
U: std::fmt::Display + Copy,
38+
{
39+
if bytes.len() != N {
40+
return Err(err_protocol!(
41+
"{} should have exactly {} byte(s), got {}",
42+
type_info,
43+
N,
44+
bytes.len()
45+
)
46+
.into());
47+
}
48+
49+
let mut buf = [0u8; N];
50+
buf.copy_from_slice(bytes);
51+
let val = from_le_bytes(buf);
52+
53+
T::try_from(val).map_err(|err| {
54+
err_protocol!(
55+
"Converting {} {} to {} failed: {}",
56+
type_info,
57+
val,
58+
type_name::<T>(),
59+
err
60+
)
61+
.into()
62+
})
63+
}
64+
65+
fn decode_int_direct<T>(value: MssqlValueRef<'_>) -> Result<T, BoxDynError>
66+
where
67+
T: TryFrom<i64> + TryFrom<u8> + TryFrom<i16> + TryFrom<i32>,
68+
<T as TryFrom<i64>>::Error: std::error::Error + Send + Sync + 'static,
69+
<T as TryFrom<u8>>::Error: std::error::Error + Send + Sync + 'static,
70+
<T as TryFrom<i16>>::Error: std::error::Error + Send + Sync + 'static,
71+
<T as TryFrom<i32>>::Error: std::error::Error + Send + Sync + 'static,
72+
{
73+
let type_info = &value.type_info;
74+
let ty = type_info.0.ty;
75+
let precision = type_info.0.precision;
76+
let scale = type_info.0.scale;
77+
let bytes_val = value.as_bytes()?;
78+
79+
match ty {
80+
DataType::TinyInt => decode_int_bytes(bytes_val, type_info, u8::from_le_bytes),
81+
DataType::SmallInt => decode_int_bytes(bytes_val, type_info, i16::from_le_bytes),
82+
DataType::Int => decode_int_bytes(bytes_val, type_info, i32::from_le_bytes),
83+
DataType::BigInt => decode_int_bytes(bytes_val, type_info, i64::from_le_bytes),
84+
DataType::IntN => match bytes_val.len() {
85+
1 => decode_int_bytes(bytes_val, type_info, u8::from_le_bytes),
86+
2 => decode_int_bytes(bytes_val, type_info, i16::from_le_bytes),
87+
4 => decode_int_bytes(bytes_val, type_info, i32::from_le_bytes),
88+
8 => decode_int_bytes(bytes_val, type_info, i64::from_le_bytes),
89+
len => Err(err_protocol!("IntN with {} bytes is not supported", len).into()),
90+
},
91+
DataType::Numeric | DataType::NumericN | DataType::Decimal | DataType::DecimalN => {
92+
let i64_val = decode_numeric(bytes_val, precision, scale)?;
93+
convert_integer::<T>(i64_val)
94+
}
95+
_ => Err(err_protocol!(
96+
"Decoding {:?} as {} failed because type {:?} is not supported",
97+
value,
98+
type_name::<T>(),
99+
ty
100+
)
101+
.into()),
102+
}
103+
}
104+
30105
impl Decode<'_, Mssql> for i8 {
31106
fn decode(value: MssqlValueRef<'_>) -> Result<Self, BoxDynError> {
32-
let i64_val = <i64 as Decode<Mssql>>::decode(value)?;
33-
convert_integer::<Self>(i64_val)
107+
decode_int_direct(value)
34108
}
35109
}
36110

@@ -57,8 +131,7 @@ impl Encode<'_, Mssql> for i16 {
57131

58132
impl Decode<'_, Mssql> for i16 {
59133
fn decode(value: MssqlValueRef<'_>) -> Result<Self, BoxDynError> {
60-
let i64_val = <i64 as Decode<Mssql>>::decode(value)?;
61-
convert_integer::<Self>(i64_val)
134+
decode_int_direct(value)
62135
}
63136
}
64137

@@ -82,8 +155,7 @@ impl Encode<'_, Mssql> for i32 {
82155

83156
impl Decode<'_, Mssql> for i32 {
84157
fn decode(value: MssqlValueRef<'_>) -> Result<Self, BoxDynError> {
85-
let i64_val = <i64 as Decode<Mssql>>::decode(value)?;
86-
convert_integer::<Self>(i64_val)
158+
decode_int_direct(value)
87159
}
88160
}
89161

@@ -118,43 +190,7 @@ impl Encode<'_, Mssql> for i64 {
118190

119191
impl Decode<'_, Mssql> for i64 {
120192
fn decode(value: MssqlValueRef<'_>) -> Result<Self, BoxDynError> {
121-
let ty = value.type_info.0.ty;
122-
let precision = value.type_info.0.precision;
123-
let scale = value.type_info.0.scale;
124-
125-
match ty {
126-
DataType::SmallInt
127-
| DataType::Int
128-
| DataType::TinyInt
129-
| DataType::BigInt
130-
| DataType::IntN => {
131-
let mut buf = [0u8; 8];
132-
let bytes_val = value.as_bytes()?;
133-
let len = bytes_val.len();
134-
135-
if len > buf.len() {
136-
return Err(err_protocol!(
137-
"Decoding {:?} as a i64 failed because type {:?} has more than {} bytes",
138-
value,
139-
ty,
140-
buf.len()
141-
)
142-
.into());
143-
}
144-
145-
buf[..len].copy_from_slice(bytes_val);
146-
Ok(i64::from_le_bytes(buf))
147-
}
148-
DataType::Numeric | DataType::NumericN | DataType::Decimal | DataType::DecimalN => {
149-
decode_numeric(value.as_bytes()?, precision, scale)
150-
}
151-
_ => Err(err_protocol!(
152-
"Decoding {:?} as a i64 failed because type {:?} is not implemented",
153-
value,
154-
ty
155-
)
156-
.into()),
157-
}
193+
decode_int_direct(value)
158194
}
159195
}
160196

@@ -164,9 +200,12 @@ fn decode_numeric(bytes: &[u8], _precision: u8, mut scale: u8) -> Result<i64, Bo
164200
let mut fixed_bytes = [0u8; 16];
165201
fixed_bytes[0..rest.len()].copy_from_slice(rest);
166202
let mut numerator = u128::from_le_bytes(fixed_bytes);
167-
while scale > 0 {
168-
scale -= 1;
203+
while numerator % 10 == 0 && scale > 0 {
169204
numerator /= 10;
205+
scale -= 1;
206+
}
207+
if scale > 0 {
208+
numerator /= 10u128.pow(scale as u32);
170209
}
171210
let n = i64::try_from(numerator)?;
172211
Ok(n * if negative { -1 } else { 1 })

sqlx-macros/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sqlx-macros-oldapi"
3-
version = "0.6.42"
3+
version = "0.6.43"
44
repository = "https://github.com/lovasoa/sqlx"
55
description = "Macros for SQLx, the rust SQL toolkit. Not intended to be used directly."
66
license = "MIT OR Apache-2.0"
@@ -75,8 +75,8 @@ heck = { version = "0.5" }
7575
either = "1.6.1"
7676
once_cell = "1.9.0"
7777
proc-macro2 = { version = "1.0.36", default-features = false }
78-
sqlx-core = { package = "sqlx-core-oldapi", version = "0.6.42", default-features = false, features = ["any"], path = "../sqlx-core" }
79-
sqlx-rt = { version = "0.6.42", default-features = false, path = "../sqlx-rt", package = "sqlx-rt-oldapi" }
78+
sqlx-core = { package = "sqlx-core-oldapi", version = "0.6.43", default-features = false, features = ["any", "aws_lc_rs", "tls12"], path = "../sqlx-core" }
79+
sqlx-rt = { version = "0.6.43", default-features = false, path = "../sqlx-rt", package = "sqlx-rt-oldapi", features = ["aws_lc_rs"] }
8080
serde = { version = "1.0.132", features = ["derive"], optional = true }
8181
serde_json = { version = "1.0.73", optional = true }
8282
sha2 = { version = "0.10.0", optional = true }

sqlx-rt/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sqlx-rt-oldapi"
3-
version = "0.6.42"
3+
version = "0.6.43"
44
repository = "https://github.com/launchbadge/sqlx"
55
license = "MIT OR Apache-2.0"
66
description = "Runtime abstraction used by SQLx, the Rust SQL toolkit. Not intended to be used directly."
@@ -21,6 +21,7 @@ runtime-tokio-native-tls = ["_rt-tokio", "_tls-native-tls", "tokio-native-tls"]
2121
runtime-actix-rustls = ["runtime-tokio-rustls"]
2222
runtime-async-std-rustls = ["_rt-async-std", "_tls-rustls", "futures-rustls"]
2323
runtime-tokio-rustls = ["_rt-tokio", "_tls-rustls", "tokio-rustls"]
24+
aws_lc_rs = ["tokio-rustls/aws_lc_rs"]
2425

2526
# Not used directly and not re-exported from sqlx
2627
_rt-async-std = ["async-std"]
@@ -34,7 +35,7 @@ async-native-tls = { version = "0.5.0", optional = true }
3435
futures-rustls = { version = "0.26", optional = true }
3536
async-std = { version = "1.7.0", features = ["unstable"], optional = true }
3637
tokio-native-tls = { version = "0.3.0", optional = true }
37-
tokio-rustls = { version = "0.26", optional = true }
38+
tokio-rustls = { version = "0.26", optional = true, default-features = false }
3839
native-tls = { version = "0.2.4", optional = true }
3940
once_cell = { version = "1.4", features = ["std"], optional = true }
4041

0 commit comments

Comments
 (0)