On Thu, Apr 6, 2017 at 2:07 PM, David Raymond <david.raym...@tomtom.com> wrote:
> Before opening the connection you could do something along the lines of
>
> if not os.path.isfile(fi) or not os.access(fi, os.W_OK):
>     print "File isn't there or isn't writable"
>     return 1
> with open(fi, "r") as f:
>     if f.read(16) != "SQLite format 3\x00":
>         print "Magic header isn't correct"
>         return 1

If you do something like this, be prepared for another process to have
created the database for you after your check suggested it doesn't
exist.

Might not matter in your exact use case, but if there's a chance for
two instances of your script to be running at once, you'll need to
handle this race condition.
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to