odbc and accessing database results by field

Robert Brewer fumanchu at amor.org
Tue Oct 28 18:30:16 EST 2003


If you already have separate code for MySQL and ODBC, you should
consider accessing MS SQL Server via ADO instead of odbc. Check out:
http://www.e-coli.net/pyado.html Interface to ADO via Mark Hammond's
win32com.client module. This will give you a more direct, specific, and
yes, more MS-approved interface to MS SQL Server.


Once you run makepy on your version of ADO (read the docs), access can
be as simple as:

import win32com.client
adOpenDynamic = 2
adLockOptimistic = 3

connection = win32com.client.Dispatch(r'ADODB.Connection')
connection.Open("DSN=MSSQL13")

anRS = win32com.client.Dispatch(r'ADODB.Recordset')
anRS.Open("SELECT ID FROM Directory", connection, adOpenDynamic,
adLockOptimistic)

while not anRS.EOF:
    anID = anRS.Fields.Item(u'ID')
    do_something_with(anID)
    anRS.MoveNext()

connection.Close()


If you're using ODBC for both Win and Lin, I pity you. :)

Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org


> -----Original Message-----
> From: JZ [mailto:jroznfgre at jngpugbjreXEBCXNbet.cy] 
> Sent: Tuesday, October 28, 2003 3:20 PM
> To: python-list at python.org
> Subject: Re: odbc and accessing database results by field
> 
> 
> On Tue, 28 Oct 2003 13:57:05 -0800, "Robert Brewer"
> <fumanchu at amor.org> wrote:
> 
> >Does it have to be odbc? 
> 
> Have I a better choice? I am using MSSQL2000 and Win32 system. My
> application works on MySQL/Linux RedHat, but it has to works under
> MSSQL2000/Win32 as well. For Linux I use MySQLdb. For Win32 I use
> odbc.
> 
> --
> JZ ICQ:6712522
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 





More information about the Python-list mailing list