Consider pandas' read_sql
to directly query the database. Currently, though you will recieve an error:
KeyError: '_typ'
However, there is a working fix thanks to @TomAubrunner on this Github ticket which appears to be a bug in adodbapi
.
- Find location of
adodpapi
: print(adodbapi.__file__)
- Open the script in folder:
apibase.py
Locate: return self._getValue(self.rows.columnNames[name.lower()])
and replace with below try/execpt
block:
try:
return self._getValue(self.rows.columnNames[name.lower()])
except:
return False
Once done, simply run as you would any DB-API pandas connection even with qmark parameters:
import pandas as pd
import adodbapi
conn = adodbapi.connect("PROVIDER=SQLOLEDB;Data Source={0};Database={1}; \
UID={2};PWD={3};".format(server,db,user,pwd))
# WITHOUT PARAMS
df = pd.read_sql("SELECT * FROM myTable", conn)
# WITH PARAMS
df = pd.read_sql("SELECT * FROM myTable WHERE [Col]= ?", conn, params=['myValue'])
conn.close()