Python 3.6.0 sqlite3 Module cannot execute vacuum statement

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.