Mx.odbc is cross platform and very fast, I have used it to go through a few hundred thousand rows of an access database in seconds where pure ADO would take 30 min (or 3 min if you use the ADO type library). Here is a simple example of how to talk to a database, in this case an access file, get the columns of a table and get data from the table.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | import mx.ODBC.Windows as odbc
#To find out what you can use to access the database, run this command
#datasource = odbc.DataSources()
#2 possible ways to hit an access file
driv='DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:/tmp/a.mdb'
#driv2='FILEDSN=c:/tmp/a.mdb'
conn = odbc.DriverConnect(driv)
c = conn.cursor()
c.execute ("select * from the_table_name where columna = 'fred'")
#get column names
cols= [ i[0] for i in c.description ]
print '\n\ncols=',cols
##print '\n\n',c.fetchone()
rows = c.fetchall()
print '\n\n','length of rows: ',len(rows)
print '\n\n'
cnt = 0
for r in rows:
cnt += 1
print cnt,' ',r
if cnt > 10:
break
|
This is hopefully enough to get one started on mx.ODBC (a great open source package that is free for non-commerical use).
Any more? John, I really appreciate this mx.ODBC example. It's one of the only examples I've found out there for beginners. Do you have anymore examples that use mx.ODBC (in Access or in Oracle) to manipulate data? I'm sure other people out there who would appreciate other examples also.
Thanks Greg Corradini