淘先锋技术网

首页 1 2 3 4 5 6 7

classBuffer(object):MAXSIZE=8192def__init__(self,conn,sql):self.conn=connself.sql=sqlself.buffer=[]defappend(self,data):self.buffer.append(data)iflen(self.buffer)>self.MAXSIZE:self.flush()defflush(self):data,self.buffer=self.buffer,[]curr=self.conn.cursor()curr.executemany(self.sql,data)self.conn.commit()#hereareyourcodeforinitdatabaseconnectconn_srcandconn_store...buff=Buffer(conn_store,"insertintosybase_uservalues(%s,%s)")sql_query="selecta.id,a.namefromuser_infoawherea.id=%s"curr_src=conn_src.cursor()curr_src.execute(sql_query,'0001')forrowincurr_src:buff.append(row)buff.flush()