Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't DBD::SQLite insert into a database through my Perl CGI script?

I am running a SQLite database within a Perl CGI script which is being accessed by DBD::SQLite. This is being run as a straight CGI on Apache.

The DBI connection works fine and selects are able to be run. However, when I attempt to do an insert I get a die with the following error:

DBD::SQLite::st execute failed: unable to open database file(1) at dbdimp.c line 402 at index.cgi line 66

I have tried changing the database file permission to 666 to try to fix this however I am still receiving the error.

Any advice?

like image 828
Todd Hunter Avatar asked Jul 14 '09 00:07

Todd Hunter


2 Answers

It looks like the directory needs write permission, the reason is:

SQLite needs to be able to create a journal file in the same directory as the DB, before any modifications can take place. The journal is used to support transaction rollback.

From: seem to need write permission on db's parent directory

like image 106
Todd Hunter Avatar answered Oct 28 '22 07:10

Todd Hunter


SQLite momentarily locks the entire file when it is doing inserts and updates (there is no record-level locking as such). Are you sure you're freeing the locks?

The SQLite literature recommends that you start a transaction, collect all of your inserts and updates du jour in that transaction, and then commit. This avoids numerous successive file locks, and improves performance.

like image 40
Robert Harvey Avatar answered Oct 28 '22 05:10

Robert Harvey