android - Android中的 "-journal"SQLite数据库是什么?

标签 android sqlite journal

在我的 Android 应用程序的数据库目录 (/data/data/com.me.myApp/databases) 中,对于我创建的每个 sqlite 数据库,都有一个相应的同名数据库,并在其名称后附加了“-journal”。

例如:myDatabase、myDatabase-journal、myOtherDatabase.db、myOtherDatabase.db-journal

这是什么?

和,

如果我为我的应用提供预填充的数据库(根据:http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/),我是否也需要包含这些数据库?'

最佳答案

这样的 -journal 文件不需要(并且应该)分发。

这是因为各种日志文件代表 SQLite 使用的临时数据(引用 SQLite's Use Of Temporary Disk Files)。特别是 -journal 文件是一个回滚日志

A rollback journal is a temporary file used to implement atomic commit and rollback capabilities in SQLite. (For a detailed discussion of how this works, see the separate document titled Atomic Commit In SQLite.) The rollback journal is always located in the same directory as the database file and has the same name as the database file except with the 8 characters "-journal" appended.

The rollback journal is usually created when a transaction is first started and is usually deleted when a transaction commits or rolls back. The rollback journal file is essential for implementing the atomic commit and rollback capabilities of SQLite. Without a rollback journal, SQLite would be unable to rollback an incomplete transaction, and if a crash or power loss occurred in the middle of a transaction the entire database would likely go corrupt without a rollback journal.

一般来说,这些-journal 文件应该只存在于有一个打开的SQLite 数据库——或者更确切地说,一个正在运行的事务——但是可以通过PRAGMA journal_mode 来控制。 .使用默认的编译指示设置,-journal 文件将被删除。

The DELETE journaling mode is the normal behavior. In the DELETE mode, the rollback journal is deleted at the conclusion of each transaction. Indeed, the delete operation is the action that causes the transaction to commit.

确保在数据库打开且所有日志已被 SQLite 自身删除(或清除)时复制实际的数据库文件;这意味着所有事务都已完成,并且数据库处于一致状态。

关于android - Android中的 "-journal"SQLite数据库是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26209091/

相关文章:

perl - 对 SQLite 数据库的仅内存修改

core-data - NSPersistentStoreCoordinator addPersistentStoreWithType : method error without journal_mode iOS 9

compiler-errors - Springer latex 模板SVJour3 f的问题

java - 从字符串返回

python - 避免 hdf5 或 sqlite 中的重复数据

android - 获取用户 Google 个人资料图片的完整 URL

android - 滚动带有 Spinner 的 ListView 时如何在 Spinner 中保持值(value)?

c++ - 通过读取 C++ 中的 MFT 获取目录大小(如 TreeSize)

java - 删除[反向退格]按钮

java - 如何在 Eclipse 中查看包的源代码?