r-dbi / odbc

Connect to ODBC databases (using the DBI interface)
https://odbc.r-dbi.org/
Other
387 stars 107 forks source link

Determine DATETIME2 precision based on parameter description #793

Open detule opened 4 months ago

detule commented 4 months ago

Related to: https://github.com/r-dbi/odbc/issues/790 https://github.com/r-dbi/odbc/issues/208 https://github.com/r-dbi/odbc/issues/130

When writing to a datetime/datetime2 target, we use a fixed precision of three decimals to avoid needing to know the user-configurable precision of the datetime2 field.

However, when writing, we attempt to discover the target table column descriptions and pass these down to nanodbc via statement::describe_parameters. We do this to avoid (nanodbc) needing to call SQLDescribeParams for each of the individual columns/parameters when binding the data buffers.

If we already have the column descriptions, we could have nanodbc::statement expose these - see for example nanodbc::statement::parameter_size(int) that already does something similar. Then we can use this API endpoint in odbc_result to maybe deduce the parameter precision.