[Dbix-class] Detecting connection errors

Peter Rabbitson rabbit+dbic at rabbit.us
Sat Oct 17 11:15:57 GMT 2015


On 10/15/2015 04:09 PM, Alberto Luaces wrote:
>
> Maybe the saner approach with sqlite could be to check first the
> existence of the database file, before trying to connect to it.
>

You could do that yourself by changing the default open flags, as 
described in 
https://metacpan.org/pod/DBD::SQLite#Database-Name-Is-A-File-Name


rabbit at Ahasver:~$ ls -l /tmp/foo
ls: cannot access /tmp/foo: No such file or directory

rabbit at Ahasver:~$ perl -MDBD::SQLite -MDBI -e 
'DBI->connect("dbi:SQLite:/tmp/foo", undef, undef, { sqlite_open_flags 
=> DBD::SQLite::OPEN_READWRITE } )'
DBI connect('/tmp/foo','',...) failed: unable to open database file at 
-e line 1.

rabbit at Ahasver:~$ perl -MDBD::SQLite -MDBI -e 
'DBI->connect("dbi:SQLite:/tmp/foo", undef, undef, {  } )'

rabbit at Ahasver:~$ ls -l /tmp/foo
-rw-r--r-- 1 rabbit rabbit 0 Oct 17 13:15 /tmp/foo

rabbit at Ahasver:~$ perl -MDBD::SQLite -MDBI -e 
'DBI->connect("dbi:SQLite:/tmp/foo", undef, undef, { sqlite_open_flags 
=> DBD::SQLite::OPEN_READWRITE } )'




More information about the DBIx-Class mailing list