Hello, I'm updating a database from a text file, the table have a primary key so I just do:
def importaElettroIngross(self,nomefile): risultato=False def valPrezzo(valore,moltiplicatore): val=float(valore) molt=float(moltiplicatore) return str(val/molt/100) file= codecs.open(nomefile,"r","latin-1") righe=file.readlines() max=len(righe) aggiornati=0 aggiunti=0 file.close() dlg = wx.ProgressDialog("Importazione in corso", "Importazione di "+self.dittaScelta, maximum = max, parent=self, style = wx.PD_CAN_ABORT | wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME #| wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME ) keepGoing = True count = 0 adesso=datetime.date.today().strftime("%Y/%m/%d") #self.session.begin() while keepGoing: (keepGoing, skip) = dlg.Update(count) record=righe[count] # faccio solo per i record validi if len(record)>=156: codart=(record[137:156]).strip() # cerco questo codice...se lo trovo lo aggiorno self.produttore=codart[:3] codiceditta=codart merce=self.session.query(Merce).filter(and_(Merce.listino==self.dittaScelta , Merce.codart==codart)).first() if merce!=None: aggiornati+=1 else: aggiunti+=1 # altrimenti lo aggiungo merce=Merce() merce.codart=codart merce.gestito=False merce.codiceditta=codiceditta merce.produttore=self.produttore merce.descrizione=record[15:50].strip() moltiplicatore=record[77:83].strip() merce.prezzo=valPrezzo(record[50:62].strip(),moltiplicatore) merce.prezzosonepar=valPrezzo(record[63:75].strip(),moltiplicatore) #merce.barre=record[119:136].strip() merce.um=record[75:77].strip() merce.listino=self.dittaScelta merce.data=adesso self.session.add(merce) self.session.flush() count += 1 #dlg.Update(count-1,"Salvataggio dati") dlg.Destroy() if keepGoing: self.session.commit() risultato=True wx.MessageBox("Record presenti:" +str(max) +"\nRecord aggiornati:"+str(aggiornati)+"\nRecord aggiunti:"+str(aggiunti),"Risultati") if risultato==False: self.session.rollback() wx.MessageBox("Errore","Errore") return risultato This way the program works, but it's very slow. There are any way to speed up the process, the text file contains 400.000 record and it's 72 MB. Thanks. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.