[Tutor] Difficulties reading from database.

Michael P. Reilly arcege@speakeasy.net
Tue, 29 May 2001 16:40:05 -0400 (EDT)


kromag@nsacom.net wrote
> 
> I have been having some difficulty reading from an access database using 
> win32com.client. I can write and execute SQL commands just fine, but actually 
> getting readable output has eluded me thus far.
> 
> When I try the following in IDLE:
> 
> 
> >>> import win32com.client
> >>> engine=win32com.client.Dispatch("DAO.DBEngine.35")
> >>> db=engine.OpenDatabase("\windows\desktop\db1.mdb")
> >>> rs=db.OpenRecordset("select * from food")
> >>> rs
> <COMObject OpenRecordset>
> 
> results. I get the same results from the interpreter started on the command 
> line.
> 
> I got my howto info from http://starship.python.net/crew/bwilk/access.html. 
> 
> I have had similar difficulties using idle under linux accessing postgres 
> with pygresql, but when I ran the interpreter from the command line the 
> results were as I expected. Clues?

I'm not a M$ user, but according to Hammond's (very good for WinXX) book
"Python Programming on Win32", this is what you are supposed to get,
an OpenRecordset object.

>>> rs = DB.OpenRecordset('SELECT ClientID, InvoiceData, \
  Consultant, Hours FROM Invoices')
>>> rs.MoveLast()
>>> rs.RecordCount
>>> for i in range(rs.Count):
...   field = rs.Fields[i]
...   print '%s = %s' % (rs.Name, rs.Value)
...
>>>

I'm assuming this would be explained in the "win32com" documentation
(under "Data Access Object" or DAO?).

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |