newbie database question

james kowalka jkowalka at nycap.rr.com
Wed Jan 9 08:48:40 EST 2002


I did get the dynwin package, but was unable to get it properly installed.
But you mentioned something I hadn't thought about.  ADO would enable me to
do this better.  Whats the easiest way to use ADO with python?

"Bill Tate" <tatebll at aol.com> wrote in message
news:cb4ba455.0201090416.74263ebc at posting.google.com...
> "Steve Holden" <sholden at holdenweb.com> wrote in message
news:<l9P_7.112255$2b1.5277218 at atlpnn01.usenetserver.com>...
> > "Bill Tate" <tatebll at aol.com> wrote in message
> > news:cb4ba455.0201081921.b8c8194 at posting.google.com...
> > > "james kowalka" <jkowalka at nycap.rr.com> wrote in message
> >  news:<0cI_7.33086$bZ5.5274497 at typhoon.nyroc.rr.com>...
> > > > I am brand new to Python, and need to develop some database programs
to
> > > > read/write some old DBF file info.  I installed mxODBC, but can't
seem
> >  to
> > > > figure out how to access a particular field to read or write it's
data.
> >  How
> > > > can I access fields directly through a connection cursor (ie,
db->fname
> >  =
> > > > "Steve", or firstname = db->fname), like in c++ or delphi.
> > > >
> > > > Thanks in advance,
> > > >
> > > > Jim Kowalka
> > >
> > > Jim,
> > > I hadn't used plain dbf files before so I just tried this and it
> > > seemed to work ok. Create a Data Source Name via the ODBC facility -
> > > select Microsoft dbase driver which should be present.  Specify the
> > > directory that the source *.dbf files are located - assume you called
> > > the DSN - 'TEST_DBF'
> > >
> > > Create a new python script that does essentially the following
> > >
> > > import odbc
> > > conn = odbc.odbc('TEST_DBF') #normally its like
> > > "DSN/UserName/Password"
> > > #use connection to create cursor
> > > cursor = conn.cursor()
> > > #create a simple sql string - leave off the <>'s obviously
> > > sql = 'Select <field name1>, <field name2>,.... from <dbf-table>'
> > > #probably best if wrap the following in try - except clause akin to
> > > try:
> > >    cursor.execute(sql)
> > >    dbList = cursor.fetchall()
> > >    for item in dbList:
> > >       #iterate over your list and do something with it.
> > > except:
> > >    #handle exception
> > >
> > > conn.close() #close the connection when done with it
> > >
> > Although Bill doesn't mention it, you should know that the odbc module
to
> > which he refers is a part of the Windows extensions. You will have htese
> > already if you installed ActiveState's distribution, or you can add them
to
> > an existing standard Windows Python after downloading the Win32all
> > extensions from ActiveState's web site.
> >
> > regards
> >  Steve
>
> Thanks Steve,
> James - you may also want to look at Sam Rushing's Dynwin package.  It
> has lots of good stuff in it including an odbc module that exposes
> alot more of the odbc api. I would recommend this version if you plan
> on using ODBC rather than say oledb, ado, etc.





More information about the Python-list mailing list