Android - database disk image is malformed

前端 未结 3 662
隐瞒了意图╮
隐瞒了意图╮ 2020-12-15 21:10

In my android app I am getting \"database disk image is malformed\" What are the reasons for getting this error?

not closed db? multiple threads accessing the db? or

3条回答
  •  难免孤独
    2020-12-15 21:23

    Fixed in Version 3.5.4 (2007-12-14): Any DELETE or UPDATE operation that uses side-effects to delete additional rows of the same table that is the subject of the DELETE or UPDATE might cause database corruption. The issue was first identified by ticket #2832. But the issue is very old and effects all versions of SQLite at least back through version 3.3.13 (the earliest version that we have checked.)

    A "delete side-effect" in the previous paragraph means a deletion that occurs as a result of an OR REPLACE clause or due to a trigger. For example:

       CREATE TABLE ex1(a INTEGER PRIMARY KEY, b);
       INSERT INTO ex1 VALUES(1,2);
       INSERT INTO ex1 VALUES(2,3);
       CREATE TRIGGER ex1_tr1 AFTER UPDATE ON ex1 BEGIN
         DELETE FROM ex1 WHERE a=old.b;
       END;
       UPDATE ex1 SET b=b+1;
    

    In the example above, the first cycle of the UPDATE causes the trigger to fire and delete the second row of the ex1 table. When the second cycle of the UPDATE loop runs, it attempts to process the second row of the ex1 table. SQLite recognized that the second row had been deleted so it aborts the second cycle, but it was failing to clean up after itself properly which could lead to database corruption on subsequent cycles of the loop.

提交回复
热议问题