A performance tip for manipulating MS Access Tables

Bill Wilkinson yopen at my-dejanews.com
Thu May 13 15:21:46 EDT 1999


This might be of value to someone using MS Access:
I am a newbie, so there might be speed opportunities that I have missed
here, but, I have found a way to speed up my Access table routines.  I
use a routine called "scatter" that takes an Access
recordset and dumps it into a list of dictionaries.  In the first few
versions of scatter, it took about 12-13 seconds to dump a 3000 record
table with about 5 fields.  I added a few object variables to hold
references to the recordset.Field object and to the recordset.Fields(x)
objects (each individual field).  This took my process time down to
around 4 seconds, a pretty good performance increase.  Listed below is
the scatter function from my mdb class.  If you would like the whole
class listing, let me know.
If the code listing loses its whitespace formatting, let me know and I
will email the code to you.

	def scatter(self,rsname,fldlist = []):
         """ rsname is a recordset object, fldlist is a optional list
of fields"""

		f = rsname.Fields
		rsname.MoveFirst()
		tmp = []
		y = 0
		if len(fldlist) == 0: #if there is no optional list.
			flds = self.enumfields(rsname)
		else:
			flds = fldlist
		rsname.MoveFirst()
		rfld = [] # a list to hold references to field objects.
		for x in flds:
			rfld.append(f(x))
		while not rsname.EOF:
			tmp.append({})
			gg = 0
			for x in flds:
				tmp[y][x] = rfld[gg].Value
				gg = gg + 1
			y = y + 1
			rsname.MoveNext()
		return tmp


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---




More information about the Python-list mailing list