Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2014-12-29 12:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (187 votes), past polls