SQLiteReadOnlyDatabaseException: attempt to write a readonly database (code 1032)

前端 未结 5 928
暗喜
暗喜 2020-12-31 07:59

So in some rare instances, I\'m seeing the \"attempt to write a readonly database\" message, and I can\'t figure out where the problem lies. I\'ll start with the stacktrace

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-31 08:49

    So the root cause of this, at first glance, appears that a third party library. Unless I'm mistaken, Tagit by Mobeix is deleting the database at app startup. I added some detailed SQLite logging, including these policies:

    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
        .detectLeakedSqlLiteObjects()
        .detectLeakedClosableObjects()
        .penaltyLog()
        .penaltyDeath()
        .build());
    

    I noticed in the log that my database is being unlinked after I create and open it. More detailed logging indicates it occurs when the Mobeix library is being initialized. The offending line in question:

    01-29 13:47:49.118: W/SQLiteLog(12120): (28) file unlinked while open: /data/user/0/com.company.app/databases/MyDatabase.db
    

    So my database file is unlinked. Weird. The next call to getWritableDatabase() recreates it again and then it's fine until the app is killed and re-launched, at which point it gets deleted and recreated.

    I'll update this if I ever figure out exactly what's causing the unlink.

提交回复
热议问题