MS Access db (mdb): viewing table attributes

Felipe Almeida Lessa felipe.lessa at gmail.com
Fri Mar 10 13:08:21 EST 2006


Em Sex, 2006-03-10 às 09:53 -0800, gau.tai at gmail.com escreveu:
> I have an Access 2003 database, protected by a workgroup, that I am
> trying to view through python.  Currently, I'm attempting dao with the
> win32 package, and I'm able to view all of the table names, but I don't
> know how to view the attributes of the tables.

I don't know if you can't use ODBC, but that's what I'm using now to
access an Access database. A (maybe) useful snippet:

import dbi, odbc # The order of this import is important!
connection = odbc.odbc('Driver={Microsoft Access Driver (*.mdb)};' +
                       'Dbq=C:\database.mdb;Uid=Admin;Pwd=;')
cursor = connection.cursor()
cursor.execute('SELECT column1, column2, COUNT(*) FROM table' +
               'WHERE column1 < column2' +
               'GROUP BY column1, column2')
print cursor.fetchall()

AFAIK, the main advantage is that it is easier to change to another
database later if needed, as the odbc module uses the same interface as
many others.

At least in my application, it has the same performance as Access itself
(most of my queries return just some sums and groups, none of them
return big chunks of data, so most part of the processing is kept on the
Jet side).

Hope that helps,
Felipe.

-- 
"Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas."

  -- Sun Tzu, em "A arte da guerra"




More information about the Python-list mailing list