I have code as follows:
try:
conn = db_connection()
cur = conn.cursor()
if is_address_changed(vehicle, conn, cur):
update_vehicle_address(vehicle, conn, cur)
conn.commit()
if is_price_changed(vehicle, conn, cur):
update_vehicle(vehicle, conn, cur)
insert_vehicle_price(vehicle, conn, cur)
conn.commit()
conn.close()
except Exception as e:
capture_error(str(e))
Thus, in my code I have conn.commit() in both if statements.
Is this correct approach? Or could I add only one above conn.close()
What would happen in one and in other case?