mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.92k stars 563 forks source link

Solving issue with infinity dates #992

Closed lsrzj closed 2 years ago

lsrzj commented 2 years ago

PostgreSQL ODBC driver returns year -9999 for -infinity dates, so python raises ValueError exception when reading cursor data, because the year field cannot be less than 1. So, I made modifications to bring the value brought by the ODBC driver to python's accepted limits that are years between 1 and 9999. That way the cursor will not raise any exception and pyodbc becomes compatible with infinity dates, just like psycopg2. The big changes seen on removed and added lines are due to autoformat tool in my VSCode, the only part I touched was the switch case part, to add the SQL_TYPE_TIMESTAMP to correct the values to python's limits.

mkleehammer commented 2 years ago

Thanks for this.

Can we get a copy without the autoformatting, though? It makes it hard to diff things over time.

lsrzj commented 2 years ago

Thanks for this.

Can we get a copy without the autoformatting, though? It makes it hard to diff things over time.

For sure, make it the best way for the project. I forgot to disable the auto format tool. It's a good ideia to document this and tell explicitly that dates are being altered when out of python's standard date and time limits, because it can restrict PyODBC usage in projects that needs to deal with BC dates or above 9999 year. Or we can think of a way to create a new date/time type that goes beyond python's standard limits and return that type instead, more complicated, but the best solution to make the driver have a better support for postgres date and time data types and don't alter the data when being read.

lsrzj commented 2 years ago

Thanks for this.

Can we get a copy without the autoformatting, though? It makes it hard to diff things over time.

I already made another pull request removing all the autoformat.