[python-win32] Re: ODBC and Oracle

Roger Upole rwupole at msn.com
Sat Jul 1 05:22:13 CEST 2006


Dean Allen Provins wrote:
> Hello:
> 
> Is there a trick to adding a Python ODBC connection to Oracle?
> 
> Under Windows, with Python's "odbc" module, I can see MS Access (twice), 2
> system databases that the IT people created. and at various times. dbase and
> excel as data sources.
> 
> Curiously, the list of sources varies with my attempts to see what's available.
> The code I used was:
> 
> import odbc
> for i in range (100):
>  try:
>    odbc.SQLDataSources (i)
>    print i
>  except:
>    continue
> 
> This prints the data source and the index at which it was found.  A sample
> listing looks like:
> 
> ('PMO_RO', 'Oracle in OraHome92')
> 1
> ('MS Access Database', 'Microsoft Access Driver (*.mdb)')
> 2
> ('MS Access Database', 'Microsoft Access Driver (*.mdb)')
> 31
> ('CMS', 'Oracle in OraHome92')
> 32
> 
> Note the repetition.  Note also that while Access always appears, the other two
> may be replaced by 'dbase' or 'excel' (very curious).
> 
> I've tried to add the Oracle odbc module to the "data source Administrator' for
> the database I want to access, but it refuses to appear.
> 
> Any ideas?

The parameter to odbc.SQLDataSources is a flag, rather than a position.

import odbc
s=odbc.SQLDataSources(odbc.SQL_FETCH_FIRST)
while s:
    print s
    s=odbc.SQLDataSources (odbc.SQL_FETCH_NEXT)

        Roger



More information about the Python-win32 mailing list