Re: [sqlite] How to determine db file version?

2004-08-29 Thread Darren Duncan
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.


Re: [sqlite] How to determine db file version?

2004-08-29 Thread D. Richard Hipp
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.]
--
D. Richard Hipp -- [EMAIL PROTECTED] -- 704.948.4565


Re: [sqlite] How to determine db file version?

2004-08-29 Thread Kurt Welgehausen
> It is safe to read the first N bytes in a db file ... ?

Yes.  As far as I know, that's the only sure way to determine
the version.  Unfortunately, the form of the header changed in
version 3, but if you read the first 33 bytes, you'll have an
array that you can search for "SQLite 2" or "SQLite format 3".
(You need to add a '\0' to terminate the string if you're
using C string functions.)

Regards


[sqlite] How to determine db file version?

2004-08-29 Thread Marco Bambini
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?
Thanks.
Marco Bambini
SQLabs.net