SQLite Forum

Help needed! Database corruption on embedded system
Hello guys,

I am trying to use SQLite on an embedded system(on a PowerPC device) but I am facing a corruption error.

The VFS is created over Elm-Chan FatFS stack(used in conjunction with a USB stick) and is very similar to <https://github.com/xluoly/raw-os_sqlite/blob/master/sqlite/os_raw.c>

The following steps will always reproduce the corruption:

  *  Create a new DB
  *  Execute SQL: DROP TABLE IF EXISTS CARS;CREATE TABLE CARS ('id' int, 'value' int);
  *  Do 4011 inserts: "INSERT INTO CARS VALUES(i, 1000 - i);" , where i = [0-4010]

At the next operation on the DB the SQLite will fail with SQLITE_CORRUPT and "database disk image is corrupted" message. When doing an integrity check over the DB in DB Browser for SQLite, will result in ```"*** in database main *** On tree page 68 cell 0: invalid page number 27656608 Page 100 is never used" ```

I ported the same VFS to Windows, using equivalent file operations and the comparison between PC and embedded databases yielded some differences on 0x20E-0x3FA and 0x8492-0x87FA. The main observation is that on the embedded DB, the regions specified earlier are filled with 0.

Pictures with the diff:

Any ideas on how to debug this error? I assume it is somehow caused by the filesystem or the USB drive.

Thank you,