1

I was reading up on the documentation and saw that you only have to commit in once in a transaction?

Does the following count as one transaction or does each function count as a transaction?

def main():
    conn=pyodbc.connect(sqlconnectionstring) # Assume this connects to the database
    cursor = conn.cursor()

    function1()
    function2()

    conn.commit()

def function1():
    # does inserting here

def function2():
    # does inserting here and calls function 3
    function3()

def function 3():
    # does more inserting here
main()

Is that conn.commit() enough to commit all insertions in all the functions or would I have to pass the "conn" variable as an argument and commit inside each function?

Thanks!

1 Answer 1

1

yes thats enough to commit all the transactions as the ones like insert and delete will all be performed inside the functions, until one fail then you will find the old row.

but that one commit will change the database status to the recent one

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.