prisma / tiberius

TDS 7.2+ (Microsoft SQL Server) driver for Rust
Apache License 2.0
321 stars 119 forks source link

f64::NAN #221

Open bbigras opened 2 years ago

bbigras commented 2 years ago

I got some f64::NAN from a source I don't control.

I got some errors when inserting into a decimal(19, 4) (null allowed) column.

error:

The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 13 ("@P1
1"): The supplied value is not a valid instance of data type float. Check the source data for invalid values. An example of an invalid value is data of numeric type with scale greater than precision. code=8023

I have no idea how other SQL crates handle this.

Should tiberius handle NaN?

pimeys commented 2 years ago

Hey! I'm currently reading the TDS manual, and SQL Server TDS protocol should support IEEE 754 floating point values. We do set the server to use the standard in the login message, but when we try to convert a f64::NAN to bytes, the server does not accept the value as a valid floating point. It's kind of tricky to find any good information about the protocol for floats, and the manual doesn't mention NaN values at all... The best I could find is some MSDN discussion where a user wants to store NaN values and has trouble with it:

https://social.msdn.microsoft.com/Forums/en-US/358533db-2c5a-429f-b855-c943e43bf5c9/inserting-a-nan-value

For your question, if the server allows NaN, Infinity and -Infinity, we should for sure support it in Tiberius too. If this is the case, we should find out do they have some special non-standard encoding in the protocol we should implement. The standard IEEE 754 encoding does not seem to work for the special values.