简体   繁体   English

有没有办法刷新 android 中 SQLite 数据库文件中的更改?

[英]Is there a way to flush changes in SQLite database file in android?

I have created a very big app that uses much SQLite reading/writing.我创建了一个非常大的应用程序,它使用了很多 SQLite 读/写。 Since I'm not able to see database in the phone in easy manner, I have backup function in the app which uploads db file to server (which is for developing purposes my local computer).由于我无法以简单的方式在手机中查看数据库,因此我在将 db 文件上传到服务器的应用程序中备份了 function(用于开发我的本地计算机)。

For the beginning I had initial database state both on server and in a phone.一开始,我在服务器和手机上都有初始数据库 state。 Then I made some changes in the phone database (added some stuff in it).然后我在电话数据库中进行了一些更改(在其中添加了一些东西)。 When I list data, I can see new stuff listed.当我列出数据时,我可以看到列出的新内容。

Then I want to backup database - I have logged everything prior to run backup - location from where is db file taken (it is /data/user/0/APPLICATION_PACKAGE/databases/DATABASE_FILENAME).然后我想备份数据库 - 在运行备份之前我已经记录了所有内容 - 获取 db 文件的位置(它是 /data/user/0/APPLICATION_PACKAGE/databases/DATABASE_FILENAME)。 Also I have erased all files on the server.我还删除了服务器上的所有文件。 When backup is completed, I have checked newly db file on server - file size in bytes matches, but there are NO changes in the file???备份完成后,我检查了服务器上新的 db 文件 - 以字节为单位的文件大小匹配,但文件中没有更改???

I said OK, maybe, somehow, it is not flushed.我说好吧,也许,不知何故,它没有被冲走。 I have closed the app, run it again, list data to see if changes are there (and they were), run backup again, and when checked new database file on server - no changes again.我已经关闭了该应用程序,再次运行它,列出数据以查看是否存在更改(它们确实存在),再次运行备份,当检查服务器上的新数据库文件时 - 再次没有更改。

How is this possible?这怎么可能? Is there a way to flush changes into db file so I can backup it regularly?有没有办法将更改刷新到 db 文件中,以便我可以定期备份它?

Most likely wal (write-ahead logging) mode is enabled.最有可能启用 wal(预写日志记录)模式。 To disable it you need to do something like this:要禁用它,您需要执行以下操作:

public class MyDbHelper extends SQLiteOpenHelper {

    //...

    @Override
    public void onOpen(SQLiteDatabase db) {
        db.disableWriteAheadLogging();
        super.onOpen(db);
    }

    //...
}

https://www.sqlite.org/wal.html https://www.sqlite.org/wal.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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