zillow / ctds

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

ctds does not take client TDS version into account #68

Closed joshuahlang closed 4 years ago

joshuahlang commented 4 years ago

ctds doesn't properly convert Python types to aSQL type supported by the TDS version the client requested at connection time. See below for a simple example:

import datetime

import ctds

params = {
    'server': 'localhost',
    # ....
    'tds_version': '7.2'
}

with ctds.connect(**params) as connection:
    with connection.cursor() as cursor:
        cursor.execute(
            '''
            SELECT :0
            ''',
            (datetime.datetime.now(),)
        )

This results in the following error: _tds.ProgrammingError: The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 3 (""): Data type 0x2A is unknown.

In this example, the client requested TDS 7.2, but ctds converted the datetime Python object to a DATETIME2 SQL type, which is not support until TDS 7.3.

joshuahlang commented 4 years ago

Fixed in v1.12.0