launchbadge / sqlx

🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, and SQLite.
Apache License 2.0
12.36k stars 1.18k forks source link

Track null arguments in order to provide the appropriate type when converting them. #3298

Open etorreborre opened 2 weeks ago

etorreborre commented 2 weeks ago

This PR fixes an issue occurring when:

Since queries are cached by default, the type of value considered for the bound parameter is Option::<i32>::None. This will raise a Postgres error on the second execution "incorrect binary data format in bind parameter <n>".

The fix consists in storing the value type of null values (using the result of the encode function to determine if the value is null), and then using a None value with the correct type (for example Option::<String>::None to persist a nullable TEXT value).

I am quite new to the sqlx library and there might be a better implementation but this one seems to be quite consistent with the implementation for the MySQL driver.

etorreborre commented 1 week ago

@abonander the failures seem to be related to some recent Postgres changes on main. Do you confirm this?

etorreborre commented 4 days ago

Hi @abonander. Is the latest version I pushed ok?