Why doesn’t SQLite3 require a commit() call to save data in Python?

前端 未结 5 1264
轮回少年
轮回少年 2020-12-09 18:48

I read somewhere that to save data to a SQLite3 database in Python, the method commit of the connection object should be called. Yet I have never needed to do t

5条回答
  •  醉梦人生
    2020-12-09 19:11

    also connection objects can be used as context managers that automatically commit or rollback transactions. 11.13.7.3. on docs.python

    # Successful, con.commit() is called automatically afterwards
    with con:
        con.execute("insert into person(firstname) values (?)", ("Joe",))
    

提交回复
热议问题