Skip to content

Commit

Permalink
fix issue w/ pyodbc port in sql server 2017
Browse files Browse the repository at this point in the history
  • Loading branch information
tim.reichard committed Jun 3, 2021
1 parent 441ac66 commit bfa5fa2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
3 changes: 2 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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. "<server>,5123")


v0.13.8 (2021-06-02)
Expand Down
19 changes: 9 additions & 10 deletions aioradio/pyodbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='',
Expand All @@ -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 ''.
Expand All @@ -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:
Expand All @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion aioradio/tests/pyodbc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit bfa5fa2

Please sign in to comment.