禁用Android Pie中的sqlite预写日志记录 [英] Disabling sqlite Write-Ahead logging in Android Pie

查看:67
本文介绍了禁用Android Pie中的sqlite预写日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android Pie中,默认启用了sqlite预写日志记录(WAL).这仅在Pie设备中导致我现有代码的错误.由于我访问数据库的方式,我无法使用 SQLiteDatabase.disableWriteAheadLogging() PRAGMA journal_mode 成功关闭WAL.我想使用名为 db_compatibility_wal_supported 的Android设置完全禁用WAL:

In Android Pie sqlite Write-Ahead logging (WAL) has been enabled by default. This is causing errors for my existing code only in Pie devices. I have been unable to turn off WAL successfully using SQLiteDatabase.disableWriteAheadLogging() or PRAGMA journal_mode due to the way I access the database. I would like to disable WAL completely with an Android setting called db_compatibility_wal_supported :

应用程序的兼容性WAL(预写日志记录)

有人知道如何配置吗?我不知道该文件是否可以在启动时以编程方式更改,或者是否可以手动更改.

Does anyone know how to configure this? I don't know if this file can be altered programmatically at startup or if it is changed manually.

我的应用程序中有一个sqlite数据库(20mb +/25万条记录).该数据库是使用我的服务器上的纯Java生成的.它包含一个食物数据库,该应用程序的用户可以添加到数据库中(并且服务器已更新).这存储在android的assets文件夹中.在首次安装过程中,将数据库从资产复制到app文件夹,以便可以使用以下有效方法将其写入:

I have a sqlite database (20mb+ / 250k records) in my app. This db is generated using plain java on my server. It contains a food database and the user of the app can add to the database (and the server is updated). This is stored in the assets folder in android. During first installation the database is copied from assets to the app folder so that it can be written to, using effectively this method :

从资产文件夹复制SQLite数据库

不幸的是,一旦我开始使用SqlDroid写入数据库,就会启用wal并且原始db中的表消失了,仅保留了所有新创建的表.但是,数据库的大小仍为20mb +.所有数据库错误均归因于缺少表.表格复制和写入方法可以在Pie之前的Android版本中完美运行.

Unfortunately, once I start writing to the database using SqlDroid wal is enabled and the tables which were in the original db have vanished and only any newly created tables remain. The size of the database however is still 20mb+. All the database errors are due to the missing tables. The table copying and writing method works perfectly in versions of Android prior to Pie.

推荐答案

我终于找到了答案.看来我收到的数据库错误与WAL没有直接关系.这是因为广泛使用的从资产复制数据库的代码中存在一个错误,即在复制操作期间数据库保持打开状态.这只是开始在Android P中引起问题.解决方案是在获取数据库文件名后关闭数据库.

I finally found the answer. It seems that the database errors I was receiving is not directly related to WAL. It is because the widely used code to copy a database from assets has a bug in it where the database is left open during the copy operation. This only started causing a problem in Android P. The solution is to close the database after you get the database file name.

SQLiteDatabase destinationDatabase = sqLiteOpenHelper.getWritableDatabase();
String dbFileName=destinationDatabase.getPath();
destinationDatabase.close();
// Now write the destinationDatabase using the dbFileName

这里有更多详细信息: Android P-'从资产复制数据库后,SQLite:无此类表错误"

This is detailed more here : Android P - 'SQLite: No Such Table Error' after copying database from assets

这篇关于禁用Android Pie中的sqlite预写日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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