Skip to content

Commit

Permalink
Fix reflection with accented table names
Browse files Browse the repository at this point in the history
  • Loading branch information
gordthompson committed Jun 28, 2022
1 parent bc8e756 commit 670eecf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion sqlalchemy_access/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import pyodbc

__version__ = "1.1.3.dev0"
__version__ = "1.1.3"

pyodbc.pooling = False # required for Access databases with ODBC linked tables
_registry.register(
Expand Down
18 changes: 15 additions & 3 deletions sqlalchemy_access/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,11 @@ def last_inserted_ids(self):

def has_table(self, connection, tablename, schema=None):
pyodbc_crsr = connection.connection.cursor()
result = pyodbc_crsr.tables(table=tablename).fetchone()
result = [
row.table_name
for row in pyodbc_crsr.tables().fetchall()
if row.table_name == tablename
]
return bool(result)

@reflection.cache
Expand Down Expand Up @@ -778,7 +782,11 @@ def _get_dao_string(self, crsr):
@reflection.cache
def get_pk_constraint(self, connection, table_name, schema=None, **kw):
pyodbc_crsr = connection.connection.cursor()
db_path = pyodbc_crsr.tables(table=table_name).fetchval()
db_path = None
for row in pyodbc_crsr.tables():
if row.table_name == table_name:
db_path = row.table_cat
break
if db_path:
db_engine = win32com.client.Dispatch(
self._get_dao_string(pyodbc_crsr)
Expand Down Expand Up @@ -806,7 +814,11 @@ def get_pk_constraint(self, connection, table_name, schema=None, **kw):
@reflection.cache
def get_foreign_keys(self, connection, table_name, schema=None, **kw):
pyodbc_crsr = connection.connection.cursor()
db_path = pyodbc_crsr.tables(table=table_name).fetchval()
db_path = None
for row in pyodbc_crsr.tables():
if row.table_name == table_name:
db_path = row.table_cat
break
if db_path:
db_engine = win32com.client.Dispatch(
self._get_dao_string(pyodbc_crsr)
Expand Down

0 comments on commit 670eecf

Please sign in to comment.