简体   繁体   中英

Restoring Room database with same method, but with different DAO’s

Have 5 room database with different entities and Dao's each. I use the same methods for backup and restore using the code bellow. All of them work perfectly except for one that throws me the following error after 'restoreSQL' method:

E/SQLiteLog: (26) file is encrypted or is not a database

Please HELP.

private void backupSQL(String sdb, File tDB){
    File sDB  = getDatabasePath(sdb);
    P.closeDB(sdb); 
    try {
        FileUtils.copyFile(sDB, tDB);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

private void restoreSQL(File tDB, String sdb){
    File sDB  = getDatabasePath(sdb);
    P.closeDB(sdb); 
    try {
        FileUtils.copyFile(tDB, sDB);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Update: Obviously the first question that I will ask is what is the difference between the DAO or the identity of that database of the others. The answer is that they are all identical and that is what has driven me crazy.

Update 2: I found out what the problem was with that particular room database. I wast closing that articular database before the BACKUP, so skipping the -SHM and -WAL ref.

(SOLVED) I found out what the problem was with that particular room database. I wasnt closing the database before the BACKUP, skipping the ref. files -SHM and -WAL ref. Thats why i was obtaining "E/SQLiteLog: (26) file is encrypted or is not a database" during RESTORE.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM