in reply to Re: DBD::SQLite "file is encrypted or is not a database" in running application (repro code)
in thread [SOLVED]: DBD::SQLite "file is encrypted or is not a database" in running application
See the POD for DBD::SQLite which states:
Your sample code seems to be doing exactly what the POD suggests shouldn't be done; sharing a database handle across forked children.
SQLite's locking relies on the operating system's flock. Sharing a database handle probably shares the underlying filehandles, and at least on my Linux systems calling for an exclusive flock on the same filehandle twice is perfectly OK.
The manpage for GNU/Linux flock indicates that calling flock more than one time on a file descriptor is ok, and an already locked file will convert an existing lock to the new lock mode. In the case of your sample script this could be even worse, because your forked children are still alive while you enter the 2nd while(1) loop. Inside your 2nd while(1) you are doing SELECT's, which may be converting the database handle's LOCK_EX to a LOCK_SH. ...probably doesn't matter though; each child reusing the same handle is able to quietly obtain a lock, so the previous lock state is irrelevant -- they all stomp on each other without warning.
Instantiate a new database handle in each child, and the problem should go away.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: DBD::SQLite "file is encrypted or is not a database" in running application (repro code)
by stevieb (Canon) on Oct 10, 2016 at 15:31 UTC | |
|
Re^3: DBD::SQLite "file is encrypted or is not a database" in running application (repro code)
by stevieb (Canon) on Oct 10, 2016 at 15:26 UTC | |
|
Re^3: DBD::SQLite "file is encrypted or is not a database" in running application (repro code)
by stevieb (Canon) on Oct 11, 2016 at 13:35 UTC |