there is a bug in Python 3.6.0 's Sqlite3 module(see Issue 29003), and the vacuum statement cannot be executed.
An exception occurs on execution:
Traceback (most recent):
File "D:\desktop\cannot_vacuum.py", line, in <module>
Conn.execute (' VACUUM ')
Sqlite3. Operationalerror:cannot VACUUM from within a transaction
This bug may be resolved in Python 3.6.1.
in Python 3.6.0, to allow the program to function properly , you need to set the Isolation_level parameter to none at Connect, as follows:
conn = Sqlite3.connect (' test.db ', isolation_level=none)
Or do this:
conn = Sqlite3.connect (' test.db ')
Conn.isolation_level = None
To view the document, Isolation_level=none represents an automatic commit:
If you want autocommit modeand then set isolation_level
to None
.
Otherwise leave it at its default, which would result in a plain "BEGIN" statement, or set it to one of SQLite ' s supported Isolation levels: "DEFERRED", "IMMEDIATE" or "EXCLUSIVE".
Changed in version 3.6: sqlite3
used to implicitly commits an open transaction before DDL statements. This is no longer.
If you leave isolation_level as The default value, the "BEGIN" statement is automatically added to each SQL statement to form a transaction.
The vacuum statement cannot be executed in the transaction, so an exception occurs.
Python 3.6.0 sqlite3 Module cannot execute vacuum statement