fun with ADO

Jim Abrams jim at publishingresources.com
Tue Feb 26 16:44:24 EST 2002


tom at peresys.co.za (Tomasz Stochmal) wrote in 
news:f20ea932.0202230533.6a01ac4b at posting.google.com:

>> 
>>     rs=win32com.client.Dispatch(r'ADODB.Recordset')
>>     rs.Open(sql,connectString)
>>     while not rs.EOF:
>>         name=str(rs.Fields("clientname").Value)  #oink!
>>         gid=str(rs.Fields("gid").Value)
>>         (- do something fun with fields -)
>>         rs.MoveNext()
>>     rs.Close()
>> 
> 
> Use rs.GetRows() to retrieve all rows & fields with one call only
> on python side you can extract the field values that you need
> 

I've found GetRows() to be the fastest method of all. 
Here's my gig:

def getdicts(self, rows=0, _lower=1):	
    	fieldnames = map(str, self.get_field_names())
	if _lower: fieldnames = map(lower, fieldnames)
	ret = []
	if not self.EOF: ret = [dict(zip(fieldnames, l)) for l in zip
(*self.getrows(rows))]
	return ret


Watch the wrapping.



More information about the Python-list mailing list