Good day, I've got a case of a corrupt file on some hardware of our own design, a linux based IO controller in a harsh environment.
It was lately discovered that 1 controller in a field test group had a corrupt db on it, so naturally we are attempting to figure out what happened. The hardware has the db on flash memory. DB Description: For the sake of documenting it, Db Size is about 370KB It is used as a status scoreboard for various system configuration information. 1 table only: CREATE TABLE config( id text PRIMARY KEY,file text,xpath text, value text, venc_switch_xpath text, apply_cmd text, cacheIsDirty integer default -1 ); Under normal operation all access is controlled by 1 program that serializes requests from the rest of the system, and executes batches of statements in a transaction. Under normal operation only SELECT and UPDATE queries are run. The db doesn't grow in number of records. There are (always at this firmware version) 1455 rows in a good db. Under upgrade, the above db management program is shut down and the upgrade script runs commands through a shell tool. Under upgrade we do use INSERT OR REPLACE as well as update. Upgrades are normally executed by creating a new db with default values (and inserting the list of known ids) and then attaching the new db to the old one and replacing records into the new db that have non-default values. Shell Tool Observations: SQLite version 3.8.4.3 2014-04-03 16:53:12 Enter ?.help? for usage hints. sqlite> pragma integrity_check; Error: database disk image is malformed sqlite> .tables sqlite> .schema Error: database disk image is malformed sqlite> select * from sqlite_master; Error: database disk image is malformed sqlite>.dump ...eventually INSERT INTO "config" VALUES('gforce_orientation','good _data','more_good_data','',NULL,NULL,0); INSERT INTO "config" VALUES('audio_input_gain','mygood_path1','alsogood_data','',NULL,'good text data',0); /**** ERROR: (11) database disk image is malformed ***/ /** ERROR: (11) database disk image is malformed *****/ COMMIT; Other hacks at it: Inspecting the file and from the above with a comparison to a known good file the headers appear ok. The table exists but our code returns this db is corrupt. Using a hex editor to manually inspect the file with a comparison to a known good one shows that there is no data that isn't "db-ish" : This is not a case of rogue data being written to the file, as far as I can see. Is there another utility I can use to help point at the problem? How is .dump working to print out almost everything when .tables returns the db is corrupt? I'd like to attempt to figure out what the last bit of data written in was. If I .dump into a text file, then open a new db and .read into it, I get 1454 records (1 fewer than the 'good db') Comparing to the good file, I know that audio_output_gain is the record that is not printed by the .dump. Does it follow that it must be the corrupt record? How would that prevent .table or .schema from getting read? >From the values of the cacheIsDirty flag, I deduce that it was in the process of an upgrade, not normal user interaction, when the corruption occurred. (This does not conclusively point to if the error happened during the upgrade, or immediately after it as the normal mode works through the records with 'dirty' cache. That said, all ~200 records of 'dirty' cache should be updated in 1 transaction, so 1 record being wrong seems to not fit. ) regards, Adam DeVita BTW: While testing this, I noticed that if I ftp the file to the device from win 7 command prompt ftp to the linux box without setting to bin (leaving in ascii mode), that will corrupt the db. That is a simple move to corrupt that isn't listed on (https://www.sqlite.org/howtocorrupt.html ). --