Closed markhilb closed 1 year ago
Hey.
So... the value is not stored as a string in the database, but with the following setup:
For datetimeoffset(n)
, we
n
in the type), is either as u16
+ u8
, u32
or u32
+ u8
i16
This is in the TDS standard, and comparison is done in the byte level, not by string. The database can render the value how it wants, but under the surface the storage is as written here. E.g. not a bug, unless you can find a test that clearly shows we do something wrong!
Yes, I understand how dates are stored and displayed in a database.
The issue I observed is that the way tiberius stores the values does not seem to be compatible with other languages.
For example, if I insert the same date 2022-05-20T11:30:11.642+02:00
using C# or python, they are displayed in the database as 2022-05-20T11:30:11.642+02:00
, and retrieved from the database as the same value.
However, if I insert that value using tiberius, it is displayed in the database as 2022-05-20 13:30:11.6420000 +02:00
and retrieving that value using C# or python will also yield 2022-05-20 13:30:11.6420000 +02:00
, which is inconsistent with tiberius, which retrieves the value as 2022-05-20T11:30:11.642+02:00
.
The expected behavior should be that inserting and retrieving a date should yield the same value regardless of which language does the inserting and retrieving. However, this is not the case here.
Hmm, I'd love to see a test and PR to fix this, if you find what we do differently!
While inserting and retrieving DateTimeOffset values from a SQL Server database, I noticed a surprising behavior where the inserted value is stored differently in the database than what was inserted and retrieved.
Setup
main.rs
Cargo.toml
docker-compose.yml
Execution
Result
As shown, the inserted and retrieved DateTimeOffset values are the same while using tiberius. However, when looking at the actual value stored in the database using something like sqlcmd there is a different value. The inserted value was
2022-05-20T11:30:11.642+02:00
, but the database shows the value to be2022-05-20 13:30:11.6420000 +02:00
. This means that if you interact with the database using something other than tiberius you would get the wrong value.Is this the intended outcome, or a bug?