At 7:53 PM -0400 8/29/04, D. Richard Hipp wrote:
Marco Bambini wrote:
It is safe to read the first N bytes in a db file and check for the
string "** This file contains an SQLite 2..." or the string "**
This file contains an SQLite 3..." to determine if the db was
created with the 2.x or 3.x version?
Is there a better method?
I think that works. Though the correct prefixes are:
Version 2.8: [** This file contains an SQLite 2.1 database **]
Version 3.0: [SQLite format 3.]
I propose that a simple validation function is added to both the 2.8
branch and the 3.0 branch of SQLite that someone can invoke like
open() except that it simply returns true or false if the target file
is a valid SQLite 2/3 file or not.
I would like a way for the SQLite library itself to tell me this in a
simple and quick way; I don't want to have to first open a dubious
file and then try to run SQL against it before I find out the file is
invalid.
This function doesn't have to be thorough; it could simply check for
both the above string and the magic number.
I think having to do such a check manually, opening a SQLite file
without using the SQLite library, smacks of bad encapsulation.
Note that, unless the behaviour of open() itself is changed to do
this, this function could be added after leaving beta stage as such
an addition is backwards compatible. But it would be nice to have
now.
One benefit of such a built-in is that I could use it from an
application function that auto-detects SQLite database instances, so
in case I just want to present the user a menu of local databases
available for opening. In Perl, this can be used to help implement
DBI's data_sources() function.
So shall I start a ticket for this?
-- Darren Duncan
P.S. Richard, thanks for posting 3.0.5. Matt, I yearn for your adaption of it.