mysql: decode computed DECIMAL columns as strings, not raw buffers (#31513)
Any computed/aggregate MySQL `DECIMAL` — `SUM`/`AVG`/`MIN`/`MAX`,
arithmetic, `CAST(x AS DECIMAL)`, `ROUND(...)`, a decimal literal, and
`SUM`/`AVG` of INT columns (which MySQL returns as DECIMAL) — was
returned by `Bun.sql` as a `Buffer`/`Uint8Array` instead of a decimal
string (so `value.toFixed()` throws and `JSON.stringify` shows
`{"type":"Buffer",…}`). A plain stored DECIMAL column returns a string
correctly.
`MYSQL_TYPE_NEWDECIMAL` was grouped with the STRING/BLOB types, which
apply a `binary && charset == 63 → return a Buffer` heuristic. DECIMAL
values are always ASCII decimal text, always have charset 63, and MySQL
sets the BINARY column flag on every *computed* decimal — so the
heuristic misfired for all of them.
Give `NEWDECIMAL` an explicit arm in both the binary
(`DecodeBinaryValue.rs`) and text (`ResultSet.rs`) decoders that always
decodes to a string. A `.raw()` query still gets raw bytes. ENUM/SET
were checked against a real server and are unaffected — they carry the
connection's real charset, so the heuristic never fires for them.
Matches node `mysql2`.
Adds a real-MySQL test covering
`SUM`/`AVG`/`CAST`/arithmetic/`ROUND`/literal/`SUM`-of-INT on both the
binary and text protocols (plus `.raw()` still returning bytes).
---------
Co-authored-by: robobun <117481402+robobun@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> A
Alistair Smith committed
e3481db80ce068f36771da14cc05ad747225ecb1
Parent: bb94ed4
Committed by GitHub <noreply@github.com>
on 5/29/2026, 6:40:38 PM