"attempt to write a readonly database"

247 views
Skip to first unread message

wealthychef

unread,
Apr 4, 2012, 6:21:25 PM4/4/12
to SQLCipher Users
Hello, I must be missing something obvious here and am hoping someone
can help me.
I have a database: "/collab/usr/global/tools/IMG_private/img_sqltrack/
Database.sqlite"
I created it with user rcook.

Executed the following commands:
sqlite3_open(filename.c_str(), &database)
sqlite3_key(database, key.c_str(), 7);
"CREATE TABLE a (a INTEGER, b INTEGER);"
"INSERT INTO a VALUES(1, 2);"
"INSERT INTO a VALUES(5, 4);"

I then set permissions to be 766, and confirmed that user "bashtest"
can read and write to this file:

hera553@bashtest:ls -l /collab/usr/global/tools/IMG_private/
img_sqltrack/Database.sqlite
-rwxrw-rw- 1 rcook tools 2048 Apr 4 15:07 /collab/usr/global/tools/
IMG_private/img_sqltrack/Database.sqlite

As rcook I can write to the database using the key "key" with the
following command:

rcook@rzthriller1 (img_sqltrack): /collab/usr/global/tools/IMG_private/
chaos_4_x86_64/bin/sqlite3 /collab/usr/global/tools/IMG_private/
img_sqltrack/Database.sqlite 'pragma key="key"; INSERT INTO a
VALUES(1, 2);'

But when user bashtest tries to write to the database I get a
"readonly" error:

hera553@bashtest:/collab/usr/global/tools/IMG_private/chaos_4_x86_64/
bin/sqlite3 /collab/usr/global/tools/IMG_private/img_sqltrack/
Database.sqlite 'pragma key="key"; INSERT INTO a VALUES(1, 2);'
Error: attempt to write a readonly database

What is going on here? Very mysterious. What barrier is bashtest
running into? Help! :-)
Thanks.

wealthychef

unread,
Apr 4, 2012, 6:41:55 PM4/4/12
to SQLCipher Users
Aha, never mind, I figured it out. It's a quirk of our Unix
filesystems. It looks like there's write access but the file system
is mounted read-only from the machine I'm looking at it with
bashtest.
Solved!
Sheesh.
-- R

Stephen Lombardo

unread,
Apr 4, 2012, 6:42:12 PM4/4/12
to sqlc...@googlegroups.com
Hello,

Does bashtest have write access to the enclosing directory holding the database file? If not, that is most likely the problem. Write access is required to create the transaction journal file (or WAL file).

Cheers,
Stephen

wealthychef

unread,
Apr 4, 2012, 6:51:21 PM4/4/12
to SQLCipher Users
Actually, not to quibble, but you are incorrect, at least for all the
Linux filesystems I use. What is usually needed is execute
permissions on the directory, and write on the file.
Proof:
rcook@rzthriller1 (img_sqltrack): mkdir test
rcook@rzthriller1 (img_sqltrack): touch test/file
rcook@rzthriller1 (img_sqltrack): chmod 200 test/file
rcook@rzthriller1 (img_sqltrack): ls -l test/file
--w------- 1 rcook tools 0 Apr 4 15:47 test/file
rcook@rzthriller1 (img_sqltrack): chmod 100 test
rcook@rzthriller1 (img_sqltrack): ls -ld test
d--x------ 2 rcook tools 4096 Apr 4 15:47 test
rcook@rzthriller1 (img_sqltrack): echo hello > test/file
generates no errors. File contains "hello"

wealthychef

unread,
Apr 4, 2012, 7:03:37 PM4/4/12
to SQLCipher Users
Oh. You're right! :-) I did not understand you, but SQLite
apparently needs to write to the directory containing the database. I
think this is an unwanted feature in my case but I can probably deal
with it.
Thanks for the tip, that would have been hard to find too.
Reply all
Reply to author
Forward
0 new messages