GreenDao operational problems using a local database, Android9.0 failed to read the database solution

First, look at this article application compatibility WAL (write-ahead logging) a presentation on Android Sqlite database

Android 9 Compatibility introduced called the WAL (Write-Ahead Logging) of SQLite database special mode, which allows the use of the database journal_mode=WAL, while maintaining a maximum retention behavior of a database for each connection.

Database applications enabled by default compatibility WAL, unless the application includes:

  1. By calling SQLiteDatabase.enableWriteAheadLogging or disableWriteAheadLogging opt-in or write-ahead logging ban
  2. By invoking SQLiteDatabase.OpenParams.setJournalMode(String mode)explicit request log mode

Author: ben3726
link: https: //www.jianshu.com/p/9cbe3839a1e2
Source: Jane books
are copyrighted by the author. Commercial reprint please contact the author authorized, non-commercial reprint please indicate the source.

The figure is a local copy of the database to the App Android9.0 the databases directory:

The figure is another Android version of the directory:

So, the problem is that after reading a copy of the database app data record incomplete -wal file, resulting in a read failure or collapse,

After check online solutions, are said to disable WAL mode,

Because the project uses greenDao-party library, here to write greenDao solution, a solution Android native database should be similar.

    private void initGreenDao() {
        mHelper = new DaoMaster.DevOpenHelper(this, DB_NAME);
        db = mHelper.getWritableDatabase();
        //在初始化greenDao的地方加上这一行
        db.disableWriteAheadLogging();

        mDaoMaster = new DaoMaster(db);
        mDaoSession = mDaoMaster.newSession();
    }

App databases compiled installation directory database as follows after the introduction

I can see that you have disabled wal mode, .wal file does not exist, open the app and there is no problem.

Last posted at how open the app catalog of Android Studio Device File Explorer tool to view real machine debugging emulator and file

Open the top navigation bar followed by the Android Studio3.5 version View -> Tool Windows ->  Device File Explorer

Over!

Published 16 original articles · won praise 14 · views 10000 +

Guess you like

Origin blog.csdn.net/i996573526/article/details/104717925