MS Access db (mdb): viewing table attributes

gau.tai at gmail.com gau.tai at gmail.com
Fri Mar 10 13:25:35 EST 2006


Here is the full code I'm using now to try out your sample:

import dbi, odbc
import win32com.client
from pprint import pprint

#sample code to list all tables in the selected database
daoEngine = win32com.client.Dispatch('DAO.DBEngine.36')
dtbs = daoEngine.OpenDatabase('database.mdb')
for table in dtbs.TableDefs:
    if table.Name[:4] <> "MSys" and table.Name[:4] <> "~TMP":
        pprint(table.Name.encode('utf-8'))

#sample code that will execute a stored query with parameters
dbconn = odbc.odbc('DSN=db; UID=user; PWD=pass')
dbcursor = dbconn.cursor()
dbcursor.execute('execute "result specs" 1')
dbcursor.execute('SELECT column1, column2, COUNT(*) FROM Weight ' +
               'WHERE column1 < column2 ' +
               'GROUP BY column1, column2')
#pprint(dbcursor.fetchall())
dbcursor.close()
dbconn.close()

I get the error: dbcursor.execute('SELECT column1, column2, COUNT(*)
FROM Weight ' +
dbi.program-error: [Microsoft][ODBC Microsoft Access Driver] Too few
parameters. Expected 2. in EXEC




More information about the Python-list mailing list