我有循环遍历表的python脚本,并根据特定条件更新日期字段。
我是否必须在循环中的每个UPDATE之后执行COMMIT,或者我可以在循环之后在脚本结尾处进行一次COMMIT吗? 以下问题的部分脚本:
for row in rows:
WO = row[0]
PLINE = str(row[2])[5:8].strip()
PPD = row[10]
if PLINE == "IP":
c_IP += 1
cursor.execute("UPDATE KSKWorkOrder SET PlanProductionDate = ? WHERE WorkOrder = ?",PPDates[c2_IP - 1], WO)
if c_IP == IP_CAP:
c_IP = 0
c2_IP = c2_IP + 1
if PLINE == "EB":
c_JB += 1
cursor.execute("UPDATE KSKWorkOrder SET PlanProductionDate = ? WHERE WorkOrder = ?",PPDates[c2_JB - 1], WO)
if c_JB == JB_CAP:
c_JB = 0
c2_JB = c2_JB + 1
if PLINE == "DLF":
c_DLF += 1
cursor.execute("UPDATE KSKWorkOrder SET PlanProductionDate = ? WHERE WorkOrder = ?",PPDates[c2_DLF - 1], WO)
if c_DLF == DLF_CAP:
c_DLF = 0
c2_DLF = c2_DLF + 1
答案 0 :(得分:1)
如果您愿意,退出循环后,您应该可以执行单个commit()
。