Repository navigation
Description
Found while investigating #502. Measured against a live MySQL 8 through the real QueryExecutor::execute path, not inferred.
Problem
COLUMN d type=DECIMAL value=Null -- DECIMAL(20,4), actual value 1.5
COLUMN n type=DECIMAL value=Null -- NUMERIC(10,2), actual value 2.5
COLUMN yr type=YEAR value=Null -- YEAR, actual value 2026
COLUMN f type=FLOAT value=Float(3.5)
COLUMN vc type=VARCHAR value=String("text")
Every DECIMAL/NUMERIC and YEAR column displays as NULL, indistinguishable from a real NULL. Nothing is logged. Grid, exports, copy-as-INSERT and generated UPDATE/DELETE predicates are all affected — a WHERE clause built from a NULL-looking decimal will not match the intended row.
DECIMAL is the type used for money, so this is likely to hit real data.
Cause
extract_value in crates/mas-core/src/query/executor.rs decodes each value into a typed Rust enum, then swallows any decode error:
"FLOAT" | "DOUBLE" | "DECIMAL" | "REAL" => row
.try_get::<Option<f64>, _>(index)
.ok() // <-- decode error discarded
.flatten() // <-- becomes None
.map(SqlValue::Float)
.unwrap_or(SqlValue::Null), // <-- surfaces as NULLsqlx refuses DECIMAL outright — the crate is built with default-features = false and neither the bigdecimal nor rust_decimal feature:
as f64: Err("mismatched types; Rust type `f64` (as SQL type `DOUBLE`) is not compatible with SQL type `DECIMAL`")
as String: Err("mismatched types; Rust type `String` (as SQL type `VARCHAR`) is not compatible with SQL type `DECIMAL`")
YEAR fails the same way: it is matched in the DATE | DATETIME | TIMESTAMP | TIME | YEAR arm, which asks for chrono::DateTime<Utc>, and a bare year will not decode as a timestamp.
The .ok().flatten() pattern is the underlying fault: a decode failure is made indistinguishable from a legitimate SQL NULL. Any type sqlx cannot decode into the chosen Rust type disappears silently, so this class of bug can recur with any new type.
Fix directions
- Stop discarding the error. At minimum, fall back to the raw text (or a loud placeholder) and log, so an unsupported type is visible rather than silently NULL. Cheapest, and prevents recurrence.
- Enable sqlx's
rust_decimalorbigdecimalfeature so DECIMAL decodes, and carry it as a string to preserve exactness — decoding it intof64would defeat the point of the type. - Fix the YEAR arm — decode as an integer rather than a timestamp.
(1) is worth doing regardless of how #502 is resolved, since it converts a whole class of silent data loss into something noticeable.
Related
#502 (BIGINT precision) is the same root cause seen from the other side: the pipeline converts values into a closed set of Rust types instead of carrying what the server sent. Both SQLyog (C++) and Beekeeper Studio (Electron/TS) avoid this by never converting — see the discussion there.
Activity
fix(query): stop decode failures masquerading as NULL
fix(query): stop decode failures masquerading as NULL (#509)
fix(query): carry BIGINT as text and quote from column metadata (#510)