Skip to content

Commit bbb69eb

Browse files
committed
Add support for decoding all numeric types as either f32 or f64 in mssql
1 parent 8f30800 commit bbb69eb

File tree

10 files changed

+47
-37
lines changed

10 files changed

+47
-37
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.33
9+
10+
- Add support for decoding all numeric types as either f32 or f64 in mssql.
11+
812
## 0.6.32
913
- Make `AnyTypeInfoKind` public
1014

Cargo.lock

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

Cargo.toml

Lines changed: 3 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.32"
23+
version = "0.6.33"
2424
license = "MIT OR Apache-2.0"
2525
readme = "README.md"
2626
repository = "https://github.com/lovasoa/sqlx"
@@ -125,8 +125,8 @@ bstr = ["sqlx-core/bstr"]
125125
git2 = ["sqlx-core/git2"]
126126

127127
[dependencies]
128-
sqlx-core = { package = "sqlx-core-oldapi", version = "0.6.32", path = "sqlx-core", default-features = false }
129-
sqlx-macros = { package = "sqlx-macros-oldapi", version = "0.6.32", path = "sqlx-macros", default-features = false, optional = true }
128+
sqlx-core = { package = "sqlx-core-oldapi", version = "0.6.33", path = "sqlx-core", default-features = false }
129+
sqlx-macros = { package = "sqlx-macros-oldapi", version = "0.6.33", path = "sqlx-macros", default-features = false, optional = true }
130130

131131
[dev-dependencies]
132132
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.32", path = "../../../", features = ["runtime-tokio-rustls", "postgres", "time", "uuid"] }
11+
sqlx = { package = "sqlx-oldapi", version = "0.6.33", 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.32"
3+
version = "0.6.33"
44
description = "Command-line utility for SQLx, the Rust SQL toolkit."
55
edition = "2021"
66
readme = "README.md"

sqlx-core/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sqlx-core-oldapi"
3-
version = "0.6.32"
3+
version = "0.6.33"
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"
@@ -101,7 +101,7 @@ offline = ["serde", "either/serde"]
101101
paste = "1.0.6"
102102
ahash = "0.8.3"
103103
atoi = "2.0.0"
104-
sqlx-rt = { path = "../sqlx-rt", version = "0.6.32", package = "sqlx-rt-oldapi" }
104+
sqlx-rt = { path = "../sqlx-rt", version = "0.6.33", package = "sqlx-rt-oldapi" }
105105
base64 = { version = "0.22", default-features = false, optional = true, features = ["std"] }
106106
bigdecimal_ = { version = "0.4.1", optional = true, package = "bigdecimal" }
107107
rust_decimal = { version = "1.19.0", optional = true }

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ impl Encode<'_, Mssql> for f32 {
2727

2828
impl Decode<'_, Mssql> for f32 {
2929
fn decode(value: MssqlValueRef<'_>) -> Result<Self, BoxDynError> {
30-
Ok(LittleEndian::read_f32(value.as_bytes()?))
30+
let as_f64 = <f64 as Decode<'_, Mssql>>::decode(value)?;
31+
Ok(as_f64 as f32)
3132
}
3233
}
3334

@@ -67,6 +68,9 @@ impl Decode<'_, Mssql> for f64 {
6768
DataType::Float | DataType::FloatN if size == 8 => {
6869
Ok(LittleEndian::read_f64(value.as_bytes()?))
6970
}
71+
DataType::Float | DataType::FloatN if size == 4 => {
72+
Ok(f64::from(LittleEndian::read_f32(value.as_bytes()?)))
73+
}
7074
DataType::Numeric | DataType::NumericN | DataType::Decimal | DataType::DecimalN => {
7175
decode_numeric(value.as_bytes()?, precision, scale)
7276
}

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.32"
3+
version = "0.6.33"
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.32", default-features = false, features = ["any"], path = "../sqlx-core" }
79-
sqlx-rt = { version = "0.6.32", default-features = false, path = "../sqlx-rt", package = "sqlx-rt-oldapi" }
78+
sqlx-core = { package = "sqlx-core-oldapi", version = "0.6.33", default-features = false, features = ["any"], path = "../sqlx-core" }
79+
sqlx-rt = { version = "0.6.33", default-features = false, path = "../sqlx-rt", package = "sqlx-rt-oldapi" }
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sqlx-rt-oldapi"
3-
version = "0.6.32"
3+
version = "0.6.33"
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."

tests/mssql/types.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ test_type!(i64(Mssql, "CAST(32324324432 AS BIGINT)" == 32324324432_i64));
4545

4646
test_type!(f32(
4747
Mssql,
48-
"CAST(3.14159265358979323846264338327950288 AS REAL)" == f32::consts::PI
48+
"CAST(3.14159265358979323846264338327950288 AS REAL)" == f32::consts::PI,
49+
"CAST(0.5 AS DECIMAL(3,2))" == 0.5_f32,
4950
));
5051

5152
test_type!(f64(
5253
Mssql,
53-
"CAST(939399419.1225182 AS FLOAT)" == 939399419.1225182_f64
54+
"CAST(939399419.1225182 AS FLOAT)" == 939399419.1225182_f64,
55+
"CAST(9.75 AS REAL)" == 9.75_f64,
5456
));
5557

5658
test_type!(numeric<f64>(Mssql,

0 commit comments

Comments
 (0)