【问题标题】:using an sqlite3 database with WAL enabled -Python使用启用了 WAL 的 sqlite3 数据库 -Python
【发布时间】:2012-07-12 16:44:15
【问题描述】:

我正在尝试修改 Google Drive 使用的两个数据库文件,以通过脚本(snapshot.db 和 sync_conf.db)重定向我的同步文件夹。虽然我可以在某些 sqlite 浏览器(不是全部)中打开文件,但我无法让 python 执行查询。我刚收到消息:sqlite3.DatabaseError: file is encrypted or is not a database

显然 google 正在数据库上使用预写日志 (WAL) 配置,可以通过对数据库运行 PRAGMA journal_mode=DELETE;(根据 sqlite.org)将其关闭,但我不知道如何如果 python 无法读取它,则对数据库运行它。

这就是我所拥有的(我尝试执行 PRAGMA 命令并提交然后重新打开,但它没有用):

import sqlite3

snapShot = 'C:\Documents and Settings\user\Local Settings\Application Data\Google\Drive\snapshot.db'
sync_conf = 'C:\Documents and Settings\user\Local Settings\Application Data\Google\Drive\sync_config.db'
sync_folder_path = 'H:\Google Drive'

conn = sqlite3.connect(snapShot)

cursor = conn.cursor()
#cursor.execute('PRAGMA journal_mode=DELETE;')
#conn.commit()
#conn= sqlite3.connect(snapShot)
#cursor = conn.cursor()
query = "UPDATE local_entry SET filename = '\\?\\" + sync_folder_path +"' WHERE filename ='\\?\C:Users\\admin\Google Drive'"
print query
cursor.execute(query)

【问题讨论】:

    标签: python sqlite google-drive-api


    【解决方案1】:

    问题解决了。我刚刚从 http://www.sqlite.org/download.html 下载了最新版本的 sqlite,并覆盖了我的 python27/DLL 目录中的旧 .dll。现在工作正常。

    真讨厌。

    【讨论】:

      【解决方案2】:

      我不认为 journal_mode 杂注应该让 sqlite3 根本无法打开数据库。也许您使用的是过旧版本的 sqlite3 库?您使用的是什么版本的 Python,以及什么版本的 sqlite3 库?

      import sqlite3
      print sqlite3.version
      

      【讨论】:

      • Python 2.7.2 和 sqlite3 版本 2.6.0 但 sqlite3.sqlite_version 是 3.6.21
      • 有趣。 python 2.7.2捆绑的sqlite3版本应该是2.6.0。但我想 3.6 更高,所以应该可以。我刚刚尝试使用 python 2.7.2(没有任何 pragma 技巧)在我自己的 Google Drive 中打开这两个 db 文件,它工作正常。
      • 好吧,捆绑的 sqlite3 版本是 2.6.0,但 sqlite3 模块中使用的 sqlite 版本是 3.6.21。至少这就是我认为的意思
      • 啊。没有意识到那些是不同的。我的 sqlite_version 是 3.7.4,所以也许这对我打开数据库有影响?
      • 根据 sqlite.ord,WAL 是 3.7 的新特性。但是我刚刚更新到 Python 2.7.3 看看它是否会有所帮助,但它仍然使用相同的版本。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-21
      • 1970-01-01
      • 2021-08-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多