Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: SQLite test database file

by Corion (Pope)
on Apr 19, 2006 at 08:02 UTC ( #544282=note: print w/ replies, xml ) Need Help??

in reply to SQLite test database file

While I have no help or comment on how to deal with a corrupt SQLite file, and others are more competent to comment on how to handle the case of a missing table (I guess eval and RaiseError are a good solution), I'm not sure if your practice of expecting/selecting exactly one row from the table is sound. I would allow for more than one row in the global table or convert the existence of more than one row into an error:

If you only ever want one application to access one database file, I'd use the following SQL to check that there is no other application that is allowed to access that database:

SELECT * WHERE application <> ? -- and SELECT * WHERE application = ?

and then check that the first statement returns 0 rows and the second statement returns exactly one row.

If you want more than one application to access a table, you can then leave out the first query.

Update: A quick googling shows me this page of DBI recipes, likely by gmax, which has a routine to check for existing tables. If a file is completely missing, likely the database doesn't exist either. I'm not sure how to ask SQLite if a file is a valid SQLite database.

Second update: Changed the SQL; replaced the count(*) by * so it reflects what my text says.

Comment on Re: SQLite test database file
Select or Download Code
Replies are listed 'Best First'.
Re^2: SQLite test database file
by greenFox (Vicar) on Apr 19, 2006 at 08:10 UTC

    Good points, thanks- I am an SQL novice really :) I did try wrapping the $sth->execute() call in an eval but it didn't capture the error...

    Update: DBI recipes is indeed by gmax

    Do not seek to follow in the footsteps of the wise. Seek what they sought. -Basho

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://544282]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2015-10-07 20:09 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (200 votes), past polls