2017-08-16 77 views
1

我有python脚本循环通过表,并根据特定的标准更新日期字段。pyodbc for循环和提交()

我是否必须在循环中的每个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  

回答

1

您应该能够执行单一commit()退出循环之后,如果这是你的偏好。