I was using Sqlite for the first time and kept getting the error "unable to open database file(1) at dbdimp.c line 398". I knew the permissions on the db file where correct. It had to be writeable by the user accessing the file. Which in is this case was a webserver so whatever the webserver was running as. I could execute the code on the command line and there was no problem. So I knew it was not the code. It had to be a permissions problem. But where? Well, Sqlite creates temporary file for tables and indices in /var/tmp. Thing is /var/tmp had the correct permissions (with the sticky bit) for users to create files temp files. So that was not it. After more searching I found the answer. Sqlite also keeps a journal file when a transaction is started. This is called file is called "dbfilename-journal". I figured if it creates it's journal file in the /var/tmp dir then what's the problem? Problem is it does not try to create this temporary file in /var/tmp. If it did I would not have wasted all this damn time. The software devs decided to create this temporary file in the same dir the database file is kept in. So now the user that wants to write to that database has to have write permissions on the directory the database is in. After chowning that dir to the user opening the db it worked great.
The error message this gives is just horrible. It's way to vague. It makes you think your permissons are wrong on the database file itself. It could also lead you to think of 100 other reasons why it can't open the db file. You keep thinking there is something wrong with the db file itself when it's a temp file creation problem. If the code knows the error is in trying to create a temporary file then say that in the error! You can get a return value that would tell you this after trying to create it. I really like sqlite and thank them for giving it away, but they need a little more detail in the error messages.