Igor Tandetnik <itandet...@mvps.org> wrote:
>
> > Is there a reason that sqlite3_open() will happily "open" a
non-sqlite 
> > file, returning SQLITE_OK, instead of returning SQLITE_NOTADB, which

> > would seem a more obvious return value?
>
> SQLite doesn't actually touch the file until the first "substantive"
statement is executed on the connection. This allows one to set various
PRAGMAs that can only be set before the database is > created.

Ah, that makes sense, ok.

> > It will also happily open a
> > sqlite database that it will later say is corrupt when I try to
query 
> > some data, implying it doesn't do data integrity checks on the 
> > database on opening?
>
> Do you really want SQLite to scan a gigabytes-large file every time
it's opened?

Depends - obviously not if you need quick access to the data, however if
the gigabytes-large file is corrupt, do you really want to wait until
you execute the first "substantive" statement to discover the DB is
corrupt?  It makes coding for corrupt database more complex if you only
find out (possibly much) further down the code stream...

>
> > So... Assuming the above is how sqlite is meant to work, what would
be 
> > the best way to ascertain if a successfully opened file is ok to
use?
>
> Run "PRAGMA integrity_check" right after opening.

Ah, that's what I was looking for!  Thanks Igor, I'll try that.

Thanks,
Nick.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to