prisma / tiberius

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

allow converting from DateTime2 to Datetimen in 'tds73' #298

Open Geo-W opened 1 year ago

Geo-W commented 1 year ago

This pr tries to address the following problem: When inserting NaiveDateTime into ms datetime columns with bulk_insert and tds73 is turned on by default, it would raise
Err` value: BulkInput("invalid data type, expecting Some(VarLenSized(VarLenContext { type: Datetimen, len: 8, collation: None })) but found DateTime2(Some(DateTime2 { date: Date(693604), time: Time { increments: 330110000000, scale: 7 } }))

cannot just disable tds73 feature as date/time might in the same table with datetime simultaneously and into_sql/to_sql is impl for date/time in without tds73 only.

normal inserting with execute does not get this issue as it calls DateTime2 to None when converting. https://github.com/prisma/tiberius/blob/98943b21b5f7a5135d3ae4bd51acbf268bb99189/src/tds/codec/column_data.rs#L615-L619

Don't know whether it is a good solution. Or maybe any other impl can solve this issue is appreciated. Thank you so much~