code 522 SQLITE_IOERR_SHORT_READ
https://www.sqlite.org/rescode.html#ioerr_short_read,在此网站中可以看到522错误介绍:
The SQLITE_IOERR_SHORT_READ error code is an extended error code for SQLITE_IOERR indicating that a read attempt in the VFS layer was unable to obtain as many bytes as was requested. This might be due to a truncated file.
SQLITE_IOERR_SHORT_READ错误代码是一个SQLITE_IOERR扩展错误的代码,指示VFS层中的读取尝试无法获得请求的字节数。 这可能是由于文件被截断了。
本人出现这个报错的原因:在数据库数据更新后,对数据文件进行了重命名,但是没有对相应的.db-shr
和.db-wal
重命名,导致调用时报522,文件被截断错误。
解决办法:同时重命名。或者先打开一次数据库,然后正常关闭,即可合并wal日志文件。
Wal文件
Android 9.0中 SQLite 引入了一种新的日志模式 Write-Ahead Log (常简写为 WAL )。
在数据库同路径下可以看到两个后缀文件.db-shr
和.db-wal
后者就是操作的wal文件
在官网对wal有一段介绍:https://www.sqlite.org/wal.html
The only safe way to remove a WAL file is to open the database file using one of the sqlite3_open() interfaces then immediately close the database using sqlite3_close().
唯一安全的移除wal文件的方法是:通过调用数据库打开的相关接口,然后再关闭数据库。