Skip to content

Instantly share code, notes, and snippets.

@gormih
Last active September 6, 2021 13:18
Show Gist options
  • Save gormih/3b8af6e72b86488d2b6204995650c7c0 to your computer and use it in GitHub Desktop.
Save gormih/3b8af6e72b86488d2b6204995650c7c0 to your computer and use it in GitHub Desktop.
from win32com import client
def process_sql_in_mdb(mdb_file_path: str, sql: str):
'''
:param mdb_file_path: Full path to .mdb file
:param sql: sql query
:return: row set for db
'''
connection = client.Dispatch(r'ADODB.Connection')
row_set = client.Dispatch(r'ADODB.Recordset')
row_set.Cursorlocation = 3
DSN = f'PROVIDER=Microsoft.ACE.OLEDB.12.0;DATA SOURCE={mdb_file_path};'
connection.Open(DSN)
row_set.Open(f'[{sql}]', connection, 1, 3)
row_set.MoveFirst()
return row_set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment