日期:2014-05-16  浏览次数:20441 次

牛刀小试:Sqlite在Ubuntu平台上写入时异常[attempt to write a readonly database]
昨天接到Email,告知系统移植到Ubuntu上测试时,无法正常运行,报异常如下:
SQL error: attempt to write a readonly database

初一判断估计是Ubuntu权限问题,于是果断将数据库文件重新设置:
chmod 777 narrative.db

发觉仍然无法写入,困惑,于是进一步google,发觉问题如下:
There can be several reasons for this error message:
1. Several processes have the database open at the same time (see the FAQ).
2. There is a plugin to compress and encrypt the database. It doesn't allow to modify the DB.
3. Lastly, another FAQ says: "Make sure that the directory containing the database file is also writable to the user executing the CGI script." I think this is because the engine needs to create more files in the directory.

很明显,第三点就是造成问题的根源。对于存放数据库文件的文件夹,一直没有关注它是否有相应的写入权限。
于是顺理成章,type command 如下:
chmod 777 mydata  (mydata是放narrative.db的文件夹)

经测试,至此,系统正常运行。