Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re: SQLite test database file by Corion
in thread SQLite test database file by greenFox

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-16 13:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found