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
-----Original Message-----
From: sqlite-users [mailto:[email protected]] On
Behalf Of dave boland
Sent: Thursday, April 06, 2017 3:58 PM
To: Simon Slavin; SQLite mailing list
Subject: Re: [sqlite] Testing sqlite db to see if exists & ready
I assume this will work in a similar fashion for Python?
On Thu, Apr 6, 2017, at 03:24 PM, Simon Slavin wrote:
>
> On 6 Apr 2017, at 7:38pm, dave boland <[email protected]> wrote:
>
> > "unconfigured means no tables, no fields, no nothing. With SQLite, it
> > is possible to have an empty file, a database with a table but no
> > fields, etc. The reason this concerns me is that I want to know what I
> > have before connecting to a file and creating a new database when I did
> > not intend to do that. So, what (and why) are the steps to test the
> > database file to see what state it is in?
>
> Okay. If that’s the definition of 'unconfigured' you want, do what I
> recommended in a previous post:
>
> First, use the PHP function "file_exists()" to check that the file
> exists.
>
> If the file does exist use PHP to check it’s an actual database:
>
> fopen(path, 'rb')
> fread(, 16)
> fclose().
>
> Then check those 16 bytes. They should be 'SQLite format 3\0'. The last
> character is a 0x00 byte for a string terminator. If there are less then
> 16 bytes, or if they don’t match that string then it’s not a "configured"
> (by your definition) SQLite database.
>
> Simon.
> _______________________________________________
> sqlite-users">sqlite-users mailing list
> sqlite-users">sqlite-users@mailinglists">sqlite-users">[email protected]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users">sqlite-users
--
dave boland
[email protected]
--
http://www.fastmail.com - Accessible with your email software
or over the web
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users