From bfa5fa2d75f2839301705af9f3006a023aeb2eec Mon Sep 17 00:00:00 2001 From: "tim.reichard" Date: Thu, 3 Jun 2021 15:39:50 -0500 Subject: [PATCH] fix issue w/ pyodbc port in sql server 2017 --- HISTORY.rst | 3 ++- aioradio/pyodbc.py | 19 +++++++++---------- aioradio/tests/pyodbc_test.py | 2 +- setup.py | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index a75d48a..87147b6 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,9 +3,10 @@ History ======= -v0.13.9 (2021-06-03) +v0.13.10 (2021-06-03) * Add SQL Server 2017 driver path for Debian operating systems. +* Moving pyodbc.connect port reference within the SERVER term (ex. ",5123") v0.13.8 (2021-06-02) diff --git a/aioradio/pyodbc.py b/aioradio/pyodbc.py index 362de69..42c5d76 100644 --- a/aioradio/pyodbc.py +++ b/aioradio/pyodbc.py @@ -46,7 +46,7 @@ async def establish_pyodbc_connection( pwd: str, port: int=None, database: str='', - tds_version: str='8.0', + tds_version: str='7.4', trusted_connection: str='', multi_subnet_failover: str='', driver: str='', @@ -62,7 +62,7 @@ async def establish_pyodbc_connection( pwd (str): password port (int, optional): port. Defaults to None. database (str, optional): database. Defaults to ''. - tds_version (str, optional): TDS_Version. Defaults to '8.0'. + tds_version (str, optional): TDS_Version. Defaults to '7.4'. trusted_connection (str, optional): Trusted_Connection. Defaults to ''. multi_subnet_failover (str, optional): MultiSubnetFailover. Defaults to ''. driver (str, optional): unixodbc driver. Defaults to ''. @@ -80,18 +80,15 @@ async def establish_pyodbc_connection( if OPERATING_SYSTEM == 'Windows': verified_driver = driver else: - if driver: - verified_driver = await get_unixodbc_driver_path([driver]) - else: - verified_driver = await get_unixodbc_driver_path(UNIXODBC_DRIVER_PATHS) - + verified_driver = driver if driver else await get_unixodbc_driver_path(UNIXODBC_DRIVER_PATHS) if verified_driver is None: raise FileNotFoundError('Unable to locate unixodbc driver file: libtdsodbc.so') - conn_string = f'DRIVER={verified_driver};SERVER={host};UID={user};PWD={pwd}' - conn_string += f';TDS_Version={tds_version if tds_version else "7.4"}' if port is not None: - conn_string += f';PORT={port}' + host += f',{port}' + + conn_string = f'DRIVER={verified_driver};SERVER={host};UID={user};PWD={pwd};TDS_Version={tds_version}' + if database: conn_string += f';DATABASE={database}' if trusted_connection: @@ -101,6 +98,8 @@ async def establish_pyodbc_connection( if application_intent: conn_string += f';ApplicationIntent={application_intent}' + print(conn_string) + return pyodbc.connect(conn_string, autocommit=autocommit) diff --git a/aioradio/tests/pyodbc_test.py b/aioradio/tests/pyodbc_test.py index 48ca679..50195df 100644 --- a/aioradio/tests/pyodbc_test.py +++ b/aioradio/tests/pyodbc_test.py @@ -11,7 +11,7 @@ async def test_bad_unixodbc_driver(): """Test using a bad unixodbc_driver that the proper exception is raised.""" - await establish_pyodbc_connection(host='unknown', user='psuedo', pwd='no-way-jose', driver='/usr/lib/bogus.so') + await establish_pyodbc_connection(host='unknown', port=5123, user='psuedo', pwd='no-way-jose', driver='/usr/lib/bogus.so') async def test_pyodbc_query_fetchone_and_fetchall(): diff --git a/setup.py b/setup.py index f5ed95f..ddfa3d3 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ long_description = fileobj.read() setup(name='aioradio', - version='0.13.9', + version='0.13.10', description='Generic asynchronous i/o python utilities for AWS services (SQS, S3, DynamoDB, Secrets Manager), Redis, MSSQL (pyodbc), JIRA and more', long_description=long_description, long_description_content_type="text/markdown",