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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.