Skip to content

fix(mysql): support DECIMAL/NEWDECIMAL decoding in tauri-plugin-sql#3286

Open
AbdenourTadjer33 wants to merge 2 commits intotauri-apps:v2from
AbdenourTadjer33:patch-1
Open

fix(mysql): support DECIMAL/NEWDECIMAL decoding in tauri-plugin-sql#3286
AbdenourTadjer33 wants to merge 2 commits intotauri-apps:v2from
AbdenourTadjer33:patch-1

Conversation

@AbdenourTadjer33
Copy link
Copy Markdown

Summary

This PR fixes MySQL decimal column decoding in tauri-plugin-sql.

Before this change, selecting rows containing DECIMAL columns could fail with:

  • unsupported datatype: DECIMAL (when type was unhandled), or
  • null decoded values (when trying incompatible string decoding).

Root cause

src/decode/mysql.rs did not properly decode MySQL decimal types through a compatible SQLx type.

DECIMAL / NEWDECIMAL require decimal-aware decoding in SQLx, not plain String decode compatibility.

Changes

1) MySQL decode support

  • Updated src/decode/mysql.rs
  • Added handling for:
    • DECIMAL
    • NEWDECIMAL
  • Decode path:
    • try_decode::<BigDecimal>()
    • serialize as JSON string via to_string()

This preserves precision and avoids float conversion loss.

2) Dependency feature

  • Updated plugin Cargo.toml
  • Enabled SQLx feature:
    • bigdecimal

Why JSON string output?

Decimal values are precision-sensitive (money/tax/rates).
Returning as string avoids precision loss and matches common JS/TS handling for fixed-point values.

Compatibility

  • No breaking API changes.
  • Existing consumers receive decimal values as JSON strings instead of decode errors/nulls.
  • Behavior for non-decimal MySQL types is unchanged.

Validation

  • Build/check passes with patched plugin.
  • Queries against decimal columns now return non-null values.
  • No regressions observed in non-decimal query paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant