stacks-network/stacks-core

Use `FromSql` and `ToSql` implementations for `u64`

Open

#5 225 ouverte le 23 sept. 2024

Voir sur GitHub
 (0 commentaires) (1 réaction) (0 assignés)Rust (758 forks)auto 404
good first issue

Métriques du dépôt

Stars
 (3 063 stars)
Métriques de merge PR
 (Métriques PR en attente)

Description

I discovered while reviewing #5153 that after updating rusqlite in this repo from 0.24.2 to 0.31.0, rusqlite added FromSql and ToSql impls for u64!

This implementation behaves as we would want: if a u64 is supplied which is greater than an i64::max, it returns an error, and if ToSql gets an i64 less than 0, it errors. Docs link:

ToSql and FromSql are implemented for all primitive number types. FromSql has different behaviour depending on the SQL and Rust types, and the value.

INTEGER to integer: returns an Error::IntegralValueOutOfRange error if the value does not fit in the Rust type.

... ToSql always succeeds except when storing a u64 or usize value that cannot fit in an INTEGER (i64). Also note that SQLite ignores column types, so if you store an i64 in a column with type REAL it will be stored as an INTEGER, not a REAL (unless the column is part of a STRICT table).

Guide contributeur