Python 3.6.0的sqlite3模块存在一个bug(见issue 29003),无法执行VACUUM语句。

一执行就出现异常:

Traceback (most recent call last):
  File "D:\desktop\cannot_vacuum.py", line 25, in <module>
    conn.execute('VACUUM')
sqlite3.OperationalError: cannot VACUUM from within a transaction

这个bug也许会在Python 3.6.1中解决。

在Python 3.6.0,要想让程序正常运行,需要在connect时设置isolation_level参数为None,如下:

conn = sqlite3.connect('test.db', isolation_level=None)

或者这样做:

conn = sqlite3.connect('test.db')
conn.isolation_level = None

查看文档,isolation_level=None表示自动commit:

If you want autocommit mode, then set isolation_level to None.

Otherwise leave it at its default, which will 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 commit an open transaction before DDL statements. This is no longer the case.

如果保持isolation_level为默认值,则会在执行每条SQL语句之前,自动加上"BEGIN"语句,从而形成一个事务。

而VACUUM语句是不能在事务中执行的,因此出现了异常。

Python 3.6.0的sqlite3模块无法执行VACUUM语句的更多相关文章

  1. python已安装了DNS处理模块,执行时却报错ImportError

    一.代码: #!/usr/bin/python import dns.resolver ............此处省略 二.故障报错 ubuntu:~/automation/001_base$ py ...

  2. 吴裕雄--python学习笔记:sqlite3 模块

    1 sqlite3.connect(database [,timeout ,other optional arguments]) 该 API 打开一个到 SQLite 数据库文件 database 的 ...

  3. Python: sqlite3模块

    sqlite3 --- SQLite 数据库 DB-API 2.0 接口模块 SQLite 是一个C语言库,它可以提供一种轻量级的基于磁盘的数据库,这种数据库不需要独立的服务器进程,也允许需要使用一种 ...

  4. Python之sqlite3模块

    python自带有sqlite3模块,该模块可以方便我们操作sqlite数据库,下面一起跟随示例了解sqlite3模块的具体用法. import sqlite3 # 连接数据库 connection ...

  5. python用sqlite3模块操作sqlite数据库-乾颐堂

    SQLite是一个包含在C库中的轻量级数据库.它并不需要独立的维护进程,并且允许使用非标准变体(nonstandard variant)的SQL查询语句来访问数据库. 一些应用可是使用SQLite保存 ...

  6. 利用python将数据转存入sqlite3

    案例的目标是将存在文件中的json格式数据转存到sqlite数据库中.因此,需要利用python逐行读取json文件中数据,对数据进行解析和入库.具体操作步骤如下: 1.逐行读取json文件 for ...

  7. Python学习之路13☞常用模块

    一 time模块 在Python中,通常有这几种方式来表示时间: 时间戳(timestamp):通常来说,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量.我们运行“type(t ...

  8. Python中操作mysql的pymysql模块详解

    Python中操作mysql的pymysql模块详解 前言 pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb几乎相同.但目前pymysql支持python3.x而后者不支持 ...

  9. Python黑帽编程2.6 模块

    Python黑帽编程2.6 模块 我们已经学习了如何在你的程序中定义一次函数而重用代码.如果你想要在其他程序中重用很多函数,那么你该如何编写程序呢?你可能已经猜到了,答案是使用模块.模块基本上就是一个 ...

随机推荐

  1. 为linux普通用户添加超级用户权限sudo

    问题:假设用户名为:ali如果用户名没有超级用户权限,当输入 sudo + 命令 时, 系统提示: ali is not in the sudoers file.  This incident wil ...

  2. My Construct

    1.构造函数定义 类中的构造函数用来初始化一个类.构造函数为公有类型,无返回值,用来从类实例中访问类时初始化此类的私有变量. 2.代码 public class UseConstruct { publ ...

  3. 黄聪:关闭Win2003开机提示“上次意外关机”对话框

    很多人在使用win2003服务器(特别是vps)的时候,都会意外关机,然后出现开机提示“上次意外关机”对话框,如果不及时发现,会影响到使用该服务器的网站,所以必须把这提示关闭,方法如下: 1.开始菜单 ...

  4. git基本用法说明(原创+验证)

      关于文件状态   一般仓库中的文件可能存在于这4种状态: 1)Untracked files                     → 文件未被跟踪(A)  2)Untracked but no ...

  5. [转]Django与遗留系统和数据库集成

    From:http://www.czug.org/python/django/17.html 尽管Django最适合从零开始开发项目--所谓的"绿色领域"开发--将框架与遗留系统和 ...

  6. Node.js文件系统、路径的操作详解

    17173 17173 2 75 2014-12-12T05:06:00Z 2014-12-12T05:06:00Z 21 2735 15595 www.17173.com 129 36 18294 ...

  7. Ubuntu14.04安装搜狗拼音输入法

    删除ibus输入法 sudo apt-get purge ibus sudo apt-get autoremove 安装fcitx和拼音输入法 sudo apt-get install fcitx f ...

  8. (Skill)238. Product of Array Except Self

    Given an array of n integers where n > 1, nums, return an array output such that output[i] is equ ...

  9. rpm命令

    RPM 安装.卸载.升级.查询和验证. RPM 安装 命令: rpm -i 文件名 如: rpm -i example.rpm 安装 example.rpm 包: rpm -iv example.rp ...

  10. LeetCode 328. Odd Even Linked List

    Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...