I am trying to do a similar sort of thing with my database. The only way I've found to fairly reliably create a corrupt database file is to pull the battery out of my laptop whilst my application is accessing the database. I haven't used the "PRAGMA integrity_check;" command, but I will try it now and see if that detects my corrupt database. At the moment, I am selecting every row from every table, but I can see this getting a bit slow when my database gets bigger.
I've just tried it, and I get a code 11 (SQLITE_CORRUPT) returned from the PRAGMA integrity_check command. Is this correct behaviour? Will I always get this error returned? The website says something about it returning "ok" but I didn't check this as I am using sqlite_exec.
I haven't managed to find anything on the website about using the journal file that is created. Can anyone point me in the right direction to using this file to re-create my database? Would I need to take a backup of the database file before every transaction to use this?
Thanks,
Liz.
----Original Message Follows---- From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: [sqlite] Effectiveness of PRAGMA integrity_check; Date: Wed, 14 Apr 2004 15:48:57 +1000
G'day,
I'm trying to write some defensive code that is able to recover from database corruption. The idea is that if a disk fails and a database becomes corrupt it can be detected and synchronised from a backup copy.
To this end, I've just been trying to write a function that returns true only when it is sure the database is ok. I use PRAGMA integrity check; and compare the returned string with "ok". When I tried this with a few random database changes, though, I had a hard time trying to get the corruption to trigger. I did the following:
CREATE TABLE foo(bar); INSERT INTO foo VALUES("bar");
I then went in with a text editor and started modifying the bar record. I changed "bar" to "car", but the change was not detected. I started modifying characters to the left and right of the "car" string, but still no corruption. I was able to get corruption to be detected when I truncated the file.
Can I take it from this behaviour that there isn't any checksum checking going on apart from headers and the BTrees themselves? Will the integrity_check at least guarantee me that I won't at some later stage get an SQLITE_CORRUPT return?
Benjamin.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
_________________________________________________________________
Tired of 56k? Get a FREE BT Broadband connection http://www.msn.co.uk/specials/btbroadband
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]