in reply to Determining if SQLite db exists

I almost responded with the ubiquitous "use -f", however I thought that perhaps the OP was looking for a more dbd independent solution. The only reason you know that it is file based access is that he's using "dbi:SQLite". In other words, if the OP was using "dbi:Oracle" or "dbi:mysql" is there an answer?


"Look, Shiny Things!" is not a better business strategy than compatibility and reuse.

Replies are listed 'Best First'.
Re^2: Determining if SQLite db exists
by gellyfish (Monsignor) on Feb 28, 2005 at 16:09 UTC

    Part of the problem here is that there isn't any particular DBMS independent way of checking whether a database exists - you may be able to use the DBI data_sources method, however some database systems (such as SQLite) don't necessarily know this information, others (such as Informix and MS SQL Server) might allow you to query a table such as sysdatabases. So data_sources() might be your man but it definitely comes with some caveats.

    /J\

Re^2: Determining if SQLite db exists
by Corion (Patriarch) on Feb 28, 2005 at 15:57 UTC

    None of the other DBDs implicitly create files. You get an error with them, like Database does not exist or something to that intent.

Re^2: Determining if SQLite db exists
by jZed (Prior) on Feb 28, 2005 at 16:06 UTC
    For most DBDs, wrap the connect() in an eval and use RaiseError or check DBI->errstr since most of the others die if an attempt is made to connect to a non-existant database. (though, aside, "database" is a very vague term here, it's actually what the standard calls a schema)