i read somewhere to save data to a sqlite3 database in python you got to call the commit() function on the connection object. i never do this but my database still gets the data saved to it... why?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
With the
sqlite3
module for Python, autocommit is off by default (as required by PEP 249):You can check that:
Note. — This test will fail using an in-memory database (with the
":memory:"
argument passed to the functionsqlite3.connect
) instead of an on-disk database, since an in-memory database is freed when the connection is closed.also connection objects can be used as context managers that automatically commit or rollback transactions. 11.13.7.3. on docs.python
Probably autocommit is on, it is by default http://www.sqlite.org/c3ref/get_autocommit.html
Add
isolation_level=None
to connect (Ref)Python sqlite3 issues a BEGIN statement automatically before "INSERT" or "UPDATE". After that it automatically commits on any other command or db.close()