[SOLVED] Can I open sqlite datbase in read-only mode?
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
Doesn't work for me:
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'"
Error: unable to open database "/mnt/tmp/Users/hcarr.HPRS.000/AppData/Roaming/Thunderbird/Profiles/8sbpxrwj.default/calendar-data/local.sqlite?mode=ro": unable to open database file
Your documentation link is for a C programming API. Are you sure this would work on the command line?
and I got an sqlite> prompt but I didn't do any db commands after that (dont' know how)
I did a .tables on the open db and there weren't any I guess. Back to the sqlite3> prompt.
Hmmm, that would probably work, but the DB file is 5.6GB and I have multiple of these to do. The lock conflict doesn't happen often enough to justify copying all these DB every 10 minutes (which is how often I run the job). Rather odd that the command doesn't have a r/o mode.
I'll post something to the sqlite mailing list and see what they say.
Hmmm, that would probably work, but the DB file is 5.6GB and I have multiple of these to do. The lock conflict doesn't happen often enough to justify copying all these DB every 10 minutes (which is how often I run the job). Rather odd that the command doesn't have a r/o mode.
weibullguy was close, but apparently, adding the 'mode' parameter only works if the database is specified in URI format:
Quote:
"The advantage of using a URI filename is that query parameters on the URI can be used to control details of the newly created database connection. For example, an alternative VFS can be specified using a "vfs=" query parameter. Or the database can be opened read-only by using "mode=ro" as a query parameter."
For URI format, the "file:" prefix is required. Specified that way, the read-only mode works.
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!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.