zillow / ctds

Python DB-API 2.0 library for MS SQL Server
MIT License
83 stars 12 forks source link

Datetime2 inconsistant results #49

Closed COngstad closed 5 years ago

COngstad commented 5 years ago

It seems that the microseconds from a datetime2 column do not get converted properly and at times get rounded.

`import ctds

sql="""select cast('2018-12-11 17:19:30.641' as datetime2),cast('2018-12-11 17:19:30.642' as datetime2),cast('2018-12-11 17:19:30.997' as datetime2)"""

con_args={'server':'localhost','port':1433,'user':'sa','xxxx':'password','xxxx':'xxx','timeout':86400}

conn=ctds.connect(**con_args)

cursor=conn.cursor()

print conn.tds_version

cursor.execute(sql)

print tuple(cursor.fetchone())`

produces the following result

7.4 (datetime.datetime(2018, 12, 11, 17, 19, 30, 640000), datetime.datetime(2018, 12, 11, 17, 19, 30, 643000), datetime.datetime(2018, 12, 11, 17, 19, 30, 997000))

joshuahlang commented 5 years ago

This is an issue I'm aware of. I had started working on supporting this here, but just haven't had time to finish it.

COngstad commented 5 years ago

If you can point me in the right direction of what needs to be completed I'd be happy to try and finish this up.

joshuahlang commented 5 years ago

https://github.com/zillow/ctds/tree/datetime2-support

joshuahlang commented 5 years ago

I have a fix for this merged to master. I'll try and get a release out to pypi in the next few days.

joshuahlang commented 5 years ago

Fixed in 1.10.0