Something for speedfreaks and pythongoeroes

BuCoDI-Rony Steelandt rsteelandt at bucodi.com
Tue Jun 13 11:09:52 EDT 2000


Hello,
 I was wondering if this code could be speed up by using some tricks
# sqlquery.py
# The query object for sqlia
import dbi,odbc
from string_man import *

connectstring = 'Urk/sa/'

class connection:
 def __init__(self):
  self.dbc = odbc.odbc(connectstring)
  self.crsr = self.dbc.cursor()
 def close(self):
  self.dbc.close()
class querry(connection):
 def cmd(self,command):
  self.t=[] ## self.t is the resultset
  numbcol = 0
  self.listcol = [] ## contains the length of the colums
  self.crsr.execute(command)
  ## -- Get columndescription
  for col in self.crsr.description:
   numbcol = numbcol +1
   self.listcol.append(col[3])
  self.result = self.crsr.fetchall()
  # Add the formatted strings to the result list
  for tmp in self.result[0:]:
   self.row=''
   for y in range(0,numbcol):
    self.row=self.row + " " +
formatstr(str(tmp[y]),int(self.listcol[y]))
   self.t.append(self.row)
  self.close()
  return self.t

if __name__ == "__main__":
 from time import *
 numlines = 0
        print "Application started"
        start=time()
        result = querry().cmd("SELECT * FROM TBL_BUYERS")
        for cnt in result:
                #print cnt
                numlines = numlines + 1
 print 'Execution time=',time()-start
 print 'Number of lines=',numlines
 print 'Application ended'


--
======================================================
Bureau de Conseil et de Développement Informatique
2, Rue Henri Avril
22480 Saint - Nicolas du Pelem

Tél : +33.2.96.29.79.08
Fax : +33.2.96.29.79.09

e-mail : bucodi at worldnet.fr
======================================================





More information about the Python-list mailing list