ch1zra
ch1zra

Reputation: 183

pyodbc for loop and commit()

I have python script that loops through table, and updates date fields depending on certain criteria.

Do I have to perform COMMIT after every UPDATE in loop, or can I just make one COMMIT at the end of script, after the loop? part of script in question below:

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    

Upvotes: 1

Views: 1148

Answers (1)

Gord Thompson
Gord Thompson

Reputation: 123809

You should be able to perform a single commit() after you exit the loop if that is your preference.

Upvotes: 1

Related Questions