Can I open sqlite datbase in read-only mode?
I'm running sqlite 3.7.17 on Slackware64 14.1, kernel 3.10.17. I'm open a database at the command line as `sqlite3 dbname`. Normally it works, but occasionally I get the message, "Error: database is locked", which is understandable since I'm not the only one accessing the database.
Is there a command line option to access the database in read-only mode? I didn't see anything in the man page, but seems like a obvious option. |
Per the sqlite3 documentation, I use the following syntax to open a database (sqlite3_db.db) in read-only mode
Code:
sqlite3 sqlite3_db.db?mode=ro |
Quote:
Code:
$ sqlite3 "/mnt/tmp/Users/hcarr.HPRS.000/AppData/Roaming/Thunderbird/Profiles/8sbpxrwj.default/calendar-data/local.sqlite?mode=ro" "select distinct value from cal_properties where key = 'CATEGORIES'" |
Try
Code:
cp /mnt/tmp/Users/hcarr.HPRS.000/AppData/Roaming/Thunderbird/Profiles/8sbpxrwj.default/calendar-data/local.sqlite $HOME Then try to open that copy with Code:
sqlite3 $HOME/local.sqlite Code:
sqlite3 /home/jj/.thunderbird/asdfqasdfs.default/calendar-data/local.sqlite?mode=ro I did a .tables on the open db and there weren't any I guess. Back to the sqlite3> prompt. |
Quote:
I'll post something to the sqlite mailing list and see what they say. |
Quote:
|
Found the answer on sqlite-users mailing list:
sqlite3 -cmd ".timeout 5000" "file:/pathto/mydb?mode=ro" weibullguy was close, but apparently, adding the 'mode' parameter only works if the database is specified in URI format: Quote:
But, just because the file is opened in read-only, doesn't mean there won't be a conflict with a DB writer which, apparently in the case of Thunderbird, wants to open the database exclusively. Therefore, the -cmd ".timeout <ms>" parameter is useful. This means if the DB is locked, sqlite3 will retry the specified number of milliseconds before giving up. I think together these takes care of my issue. Only time will tell! |
All times are GMT -5. The time now is 01:36 AM. |