4

I'm trying to modify the two database files used by Google Drive to redirect my sync folder via a script (snapshot.db and sync_conf.db). While I can open the files in certain sqlite browsers (not all) I cant get python to execute a query. I just get the message: sqlite3.DatabaseError: file is encrypted or is not a database

Apparently google is using a Write-Ahead-logging (WAL) configuration on the databases and it can be turned off by running PRAGMA journal_mode=DELETE; (according to sqlite.org) against the database, but I can't figure out how to run that against the database if python can't read it.

heres what I have (I tried executing the PRAGMA command and commiting and then reopening but it didnt work):

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)
Jtgrenz
  • 591
  • 1
  • 6
  • 21

2 Answers2

4

problem solved. I just downloaded the latest version of sqlite from http://www.sqlite.org/download.html and overwrote the old .dll in my python27/DLL directory. Works fine now.

What a nusance.

Jtgrenz
  • 591
  • 1
  • 6
  • 21
1

I don't think the journal_mode pragma should keep sqlite3 from being able to open the db at all. Perhaps you're using an excessively old version of the sqlite3 lib? What version of Python are you using, and what version of the sqlite3 library?

import sqlite3
print sqlite3.version
the paul
  • 8,972
  • 1
  • 36
  • 53
  • Python 2.7.2 and sqlite3 verson 2.6.0 but sqlite3.sqlite_version is 3.6.21 – Jtgrenz Jul 12 '12 at 17:05
  • 1
    Interesting. The version of sqlite3 bundled with python 2.7.2 should be 2.6.0. But I guess 3.6 is higher, so that ought to work. I just tried opening those two db files in my own Google Drive with python 2.7.2 (without any pragma tricks), and it worked ok. – the paul Jul 12 '12 at 17:16
  • well the sqlite3 version bundled is 2.6.0 but the sqlite version used in the sqlite3 module is 3.6.21. At least thats what I take that to mean – Jtgrenz Jul 12 '12 at 17:19
  • Ah. Didn't realize those were different. My sqlite_version is 3.7.4, so maybe that makes a difference in letting me open the dbs? – the paul Jul 12 '12 at 17:21
  • 1
    According to sqlite.ord, WAL is a new feature as of 3.7. But I just updated to Python 2.7.3 to see if it would help, but It still uses the same versions. – Jtgrenz Jul 12 '12 at 17:24
  • I guess the question now is, how to I update my version of sqlite – Jtgrenz Jul 12 '12 at 17:27
  • Yeah, just saw that. It should help to figure out where your actual sqlite3 lib is. If you `import _sqlite3; print _sqlite3.__file__`, it should point you to an .so file (assuming OS X or *nix). Then you can run `ldd` or `otool -L` on that .so file to see what it links with. – the paul Jul 12 '12 at 17:28
  • Thanks! Always helps to muddle through something with a second brain. – Jtgrenz Jul 12 '12 at 17:42
  • The bundled SQlite version with Python 2.7 on Windows is rather old, see http://bugs.python.org/issue19450 for a request to update it. – schlamar Nov 05 '14 at 10:08