Android sqlite 将 WAL 文件内容刷新到主数据库文件中 [英] Android sqlite flush WAL file contents into main database file

查看:71
本文介绍了Android sqlite 将 WAL 文件内容刷新到主数据库文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的应用程序数据库内容创建备份,对于大多数设备,它运行良好,但有一些设备默认启用了 wal 模式,这会导致问题.从我读过的所有内容中,调用pragma wal_checkpoint"应该将 -wal 文件的内容刷新到主数据库文件中,这就是我所追求的.将内容刷新到主 db 文件,然后复制 db 文件进行备份.我打电话

I'm trying to create a backup of my apps database contents and for most devices it works fine but a few have wal mode enabled by default which causes an issue. From everything I've read calling "pragma wal_checkpoint" should flush the contents of a -wal file into the main database file which is what I'm after. Flush the contents to main db file and then copy the db file for backup. I'm calling

db.rawQuery("pragma wal_checkpoint;", null);

但它似乎不起作用.有什么想法吗?

but it doesn't seem to be working. Any ideas?

推荐答案

rawQuery() 返回一个游标;直到您尝试从游标读取数据时,查询才会真正执行.

rawQuery() returns a cursor; the query is not actually executed until you try to read from the cursor.

要执行不返回游标的 SQL 语句,请使用 execSQL() 代替.

To execute an SQL statement that does not return a cursor, use execSQL() instead.

这篇关于Android sqlite 将 WAL 文件内容刷新到主数据库文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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