mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-13 17:27:50 +00:00
fix and test handling of 0 for BigDecimal in Postgres/MySQL
closes #283
This commit is contained in:
parent
a7d039931c
commit
c285e28670
@ -122,8 +122,12 @@ impl TryFrom<PgNumeric> for BigDecimal {
|
||||
}
|
||||
};
|
||||
|
||||
if digits.is_empty() {
|
||||
// Postgres returns an empty digit array for 0 but BigInt expects at least one zero
|
||||
return Ok(0u64.into());
|
||||
}
|
||||
|
||||
let sign = match sign {
|
||||
_ if digits.is_empty() => Sign::NoSign,
|
||||
PgNumericSign::Positive => Sign::Plus,
|
||||
PgNumericSign::Negative => Sign::Minus,
|
||||
};
|
||||
|
||||
@ -128,6 +128,7 @@ mod time_tests {
|
||||
test_type!(decimal(
|
||||
MySql,
|
||||
sqlx::types::BigDecimal,
|
||||
"CAST(0 as DECIMAL(0, 0))" == "0".parse::<sqlx::types::BigDecimal>().unwrap(),
|
||||
"CAST(1 AS DECIMAL(1, 0))" == "1".parse::<sqlx::types::BigDecimal>().unwrap(),
|
||||
"CAST(10000 AS DECIMAL(5, 0))" == "10000".parse::<sqlx::types::BigDecimal>().unwrap(),
|
||||
"CAST(0.1 AS DECIMAL(2, 1))" == "0.1".parse::<sqlx::types::BigDecimal>().unwrap(),
|
||||
|
||||
@ -166,6 +166,8 @@ test_prepared_type!(numeric(
|
||||
test_type!(decimal(
|
||||
Postgres,
|
||||
sqlx::types::BigDecimal,
|
||||
// https://github.com/launchbadge/sqlx/issues/283
|
||||
"0::numeric" == "0".parse::<sqlx::types::BigDecimal>().unwrap(),
|
||||
"1::numeric" == "1".parse::<sqlx::types::BigDecimal>().unwrap(),
|
||||
"10000::numeric" == "10000".parse::<sqlx::types::BigDecimal>().unwrap(),
|
||||
"0.1::numeric" == "0.1".parse::<sqlx::types::BigDecimal>().unwrap(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user