Android会议室数据库不会导出所有数据 [英] Android room database won't export all the data

查看:127
本文介绍了Android会议室数据库不会导出所有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置Room数据库备份功能. 问题是,一旦下载,sql数据库文件在应用程序中将不包含最新的数据集.它总是会丢失一些最新记录. 是否有导出会议室数据库的正确方法? P.S.使用sqliteHelper处理我的数据库时,我没有遇到类似的问题,因此我认为它必须与Room有关.

I'm trying to setup Room database backup functionality. Problem is that sql database file doesn't contain latest set of data in the app once downloaded. It always misses some most recent records. Is there a proper way to export room database? P.S. I didn't face similar problems when handled my db with sqliteHelper, so I suppose it must have something to do with Room.

我正在做的方式:

@Throws(IOException::class)
private fun copyAppDbToDownloadFolder(address: String) {
    val backupDB = File(address, "studioDb.db") 
    val currentDB = applicationContext.getDatabasePath(StudioDatabase.DB_NAME)
    if (currentDB.exists()) {
        val src = FileInputStream(currentDB).channel
        val dst = FileOutputStream(backupDB).channel
        dst.transferFrom(src, 0, src.size())
        src.close()
        dst.close()
    }
}

推荐答案

我已经解决了.导出(保存)使用Room处理的sql数据库时,必须同时导出(和以后导入)-your_database.bd和your_database.wal文件.后来是一本杂志,阿法尤(Afaiu)保留最新记录.

I've solved it. When exporting (saving) sql database which you handle with Room, you have to export(and later import) both - your_database.bd and your_database.wal files. Later is a journal and afaiu keeps latest records.

这篇关于Android会议室数据库不会导出所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆