How to simulate a damaged SQLite database

Part of the startup procedure in my application validates SQLite databases using the PRAGMA integrity_check; API PRAGMA integrity_check; . I am looking for a way to legally corrupt SQLite database so that this “integrity check” fails.

I tried messing with the database file in a text editor, but it causes the type of corruption that is detected when opening the database, much earlier than my call to "integrity check".

Any ideas?

+4
source share
1 answer

PRAGMA writable_schema allows you to change the database schema behind SQLite back and thereby violate the restrictions:

 $ sqlite3 test.db > CREATE TABLE t(x); > CREATE INDEX tx ON t(x); > INSERT INTO t VALUES (1), (1); > PRAGMA writable_schema = 1; > UPDATE sqlite_master > SET sql = 'CREATE UNIQUE INDEX tx ON t(x)' > WHERE type = 'index' AND name = 'tx'; > .quit $ sqlite3 test.db # reload > PRAGMA integrity_check; non-unique entry in index tx 
+3
source

All Articles