1

在我的一些应用程序中,我确实提供了 Android 数据库的应用程序内备份和恢复。数据库文件的名称在 SQLiteOpenHelper 中设置。

现在我听说可能会有其他文件取决于 Android 版本和/或制造商(例如 HTC)。

所有这些文件的名称是什么?

4

1 回答 1

0

It depends.

Standard Android SQLite installations create just one single database file for each database. This file is located in "/data/data//databases" and is named as you instructed to do so for example in the "name" parameter in this constructor:

SQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version)

So a database file is called for example:

/data/data/<packagename>/databases/mydatabase.db

SQLite itself has a new feature called Write-Ahead-Logging (WAL). This WAL uses a different logging mechanism than those from traditional database makers. With WAL new commited data will be stored in an additional file that has "-wal" attached to your original filename. For example:

/data/data/<packagename>/databases/mydatabase.db-wal

This data is missing in the traditional database file until a configurable threadhold is reached - or the app developer instructs the database to move this data over.

However, a WAL-enabled database is not valid with the "*.db" file alone. All additional files are required to form the database. This means a WAL-enabled database will not work on an Android device with an SQLite version that does not support WAL. So a database backup from a WAL-enabled database will not work on older Android systems.

However, only few devices (from HTC for example) and some custom-ROMs enable WAL. Standard Android does not enable WAL.

于 2012-09-14T09:28:55.723 回答