Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-07 Thread Clemens Ladisch
Simon Slavin wrote: > On 7 Apr 2017, at 6:58am, Clemens Ladisch wrote: >> David Raymond: >>> https://docs.python.org/2/reference/datamodel.html#with-statement-context-managers >>> >>> For the sqlite3 module connection object: on a bad exit from an >>> exception it will do a

Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-07 Thread Simon Slavin
On 7 Apr 2017, at 6:58am, Clemens Ladisch wrote: > David Raymond: >> https://docs.python.org/2/reference/datamodel.html#with-statement-context-managers >> >> For the sqlite3 module connection object: on a bad exit from an >> exception it will do a rollback, on a clean exit

Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-06 Thread Clemens Ladisch
David Raymond: >https://docs.python.org/2/reference/datamodel.html#with-statement-context-managers > >For the sqlite3 module connection object: on a bad exit from an >exception it will do a rollback, on a clean exit it will do a commit, >and run .close() either way. It does not run .close().

Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-06 Thread David Raymond
Error: no such table: feb.theTableYouWereLookingFor" -Original Message- From: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] On Behalf Of Random Coder Sent: Thursday, April 06, 2017 6:07 PM To: SQLite mailing list Subject: Re: [sqlite] Testing sqlite db to see if exis

Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-06 Thread Simon Slavin
On 6 Apr 2017, at 11:55pm, David Raymond wrote: > For the sqlite3 module connection object: on a bad exit from an exception it > will do a rollback, on a clean exit it will do a commit, and run .close() > either way. Thanks for the answer about open() scope. Your

Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-06 Thread Simon Slavin
On 6 Apr 2017, at 10:07pm, David Raymond wrote: > with open(fi, "r") as f: In Python, once you fall outside the scope of "with open()" does it automatically close the file for you ? If so, that’s pretty neat. Simon. ___

Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-06 Thread Tim Streater
On 06 Apr 2017 at 19:54, Jens Alfke wrote: > PS: Tim, for some reason your mail client (iLetter) is sending replies without > an In-Reply-To header, which breaks up the threading (at least in my mail > client) making it very hard to follow. There’s probably not a way for you

Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-06 Thread David Raymond
print "Magic header isn't correct" return 1 -Original Message- From: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] On Behalf Of dave boland Sent: Thursday, April 06, 2017 3:58 PM To: Simon Slavin; SQLite mailing list Subject: Re: [sqlite] Testi

Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-06 Thread dave boland
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 wrote: > > > "unconfigured means no tables, no fields, no nothing. With SQLite, it > > is possible to have an empty

Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-06 Thread Simon Slavin
On 6 Apr 2017, at 7:38pm, dave boland 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

Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-06 Thread Jens Alfke
> On Apr 6, 2017, at 5:19 AM, Simon Slavin wrote: > > Don’t do this. Because if the file isn’t there, or if the file is there but > has zero length, SQLite will turn it into a SQLite file and then return > results which don’t let you tell whether the file was already

Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-06 Thread dave boland
"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

Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-06 Thread Tim Streater
On 06 Apr 2017 at 16:10, Simon Slavin wrote: > On 6 Apr 2017, at 4:04pm, Tim Streater wrote: > >> On 06 Apr 2017 at 15:33, Simon Slavin wrote: >> >>> After touching, try opening the file and issuing a CREATE TABLE command.

Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-06 Thread James K. Lowden
On Thu, 6 Apr 2017 13:19:38 +0100 Simon Slavin wrote: > Instead use PHP functions to check that the file exists using PHP > function "file_exists()" and then using fread() to read the first 16 > bytes from it. Those 16 bytes should be "SQLite format 3" followed > by a 0x00

Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-06 Thread Simon Slavin
On 6 Apr 2017, at 4:04pm, Tim Streater wrote: > On 06 Apr 2017 at 15:33, Simon Slavin wrote: > >> After touching, try opening the file and issuing a CREATE TABLE command. See >> whether it works or gives an error. > > The command works and the

Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-06 Thread Tim Streater
On 06 Apr 2017 at 15:33, Simon Slavin wrote: > On 6 Apr 2017, at 2:44pm, Tim Streater wrote: > >> That would appear not to be the case. Under OS X 10.9.5, I touched a >> non-existent file and then using sqlite3.app did: >> >> .schema

Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-06 Thread Simon Slavin
On 6 Apr 2017, at 2:44pm, Tim Streater wrote: > That would appear not to be the case. Under OS X 10.9.5, I touched a > non-existent file and then using sqlite3.app did: > > .schema<--- gave nothing > select version from globals; <--- gave

Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-06 Thread Tim Streater
On 06 Apr 2017 at 13:19, Simon Slavin wrote: > On 6 Apr 2017, at 12:11pm, Tim Streater wrote: > >> When my app starts, I check that the file in question actually *is* a >> database by doing some simple steps like open, selects from important tables,

Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-06 Thread Simon Slavin
On 6 Apr 2017, at 12:11pm, Tim Streater wrote: > When my app starts, I check that the file in question actually *is* a > database by doing some simple steps like open, selects from important tables, > and a read/write to a globals table in the database that contains,

Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-06 Thread Marco Bambini
Seems like a good reason to introduce a way to query the existence of a particular pragma command, something like: PRAGMA exists('user_version'); or PRAGMA exists='user_version'; -- Marco Bambini http://www.sqlabs.com http://twitter.com/sqlabs http://instagram.com/sqlabs > On 6 Apr 2017, at

Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-06 Thread Richard Hipp
On Thu, 06 Apr 2017 12:11 +0100, Tim Streater wrote: > > I keep reading that the continued > existence of any particular PRAGMA is completely un-guaranteed. > We say that. But in practice, if we were to remove a pragma it would break thousands, perhaps millions, of

Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-06 Thread Tim Streater
On 06 Apr 2017 at 11:28, Clemens Ladisch wrote: > dave boland wrote: >> Being a little paranoid, I like to insure that the db file exists > > SQLite automatically creates an empty DB if you try to open > a nonexistent file, so you do not actually need to do anything. > >>

Re: [sqlite] Testing sqlite db to see if exists & ready

2017-04-06 Thread Clemens Ladisch
dave boland wrote: > Being a little paranoid, I like to insure that the db file exists SQLite automatically creates an empty DB if you try to open a nonexistent file, so you do not actually need to do anything. > and what state it is in (unconfigured, so needs to be made > ready; or ready to

[sqlite] Testing sqlite db to see if exists & ready

2017-04-06 Thread dave boland
Being a little paranoid, I like to insure that the db file exists, which is easy, and what state it is in (unconfigured, so needs to be made ready; or ready to accept data (or be read)). How do I do that? Using Python, but would like a generalized approach. Feel free to point me to