0
我使用Python 2.7,Peewee和MySQL。我的程序從csv文件讀取並更新字段,如果訂單號碼存在於csv中。可以有2000-3000次更新,我正在使用天真的方法逐一更新記錄,這種方法速度很慢。我已經從使用Peewee更新轉移到原始查詢,這有點快。但是,它仍然非常緩慢。我想知道如何在不使用循環的情況下以更少的事務更新記錄。Python Peewee MySQL批量更新
def mark_as_uploaded_to_zoho(self, which_file):
print "->Started marking the order as uploaded to zoho."
with open(which_file, 'rb') as file:
reader = csv.reader(file, encoding='utf-8')
next(reader, None) ## skipping the header
for r in reader:
order_no = r[0]
query = '''UPDATE sales SET UploadedToZoho=1 WHERE OrderNumber="%s" and UploadedToZoho=0''' %order_no
SalesOrderLine.raw(query).execute()
print "->Marked as uploaded to zoho."