Android 中的“-journal”SQLite 数据库是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26209091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the "-journal" SQLite database in Android?
提问by ddouglascarr
In my andoid application's database directory (/data/data/com.me.myApp/databases), for every sqlite database I create there is a corresponding database of the same name with "-journal" appended to it's name.
在我的 andoid 应用程序的数据库目录 (/data/data/com.me.myApp/databases) 中,对于我创建的每个 sqlite 数据库,都有一个相应的同名数据库,并在其名称后附加了“-journal”。
e.g: myDatabase, myDatabase-journal, myOtherDatabase.db, myOtherDatabase.db-journal
例如:myDatabase、myDatabase-journal、myOtherDatabase.db、myOtherDatabase.db-journal
What is this?
这是什么?
and,
和,
If I'm providing pre-filled databases for my app (as per: http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/) do I need to include these as well?'
如果我为我的应用程序提供预填充的数据库(根据:http: //www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/),我需要包括这些也是?
采纳答案by user2864740
Such -journal
files do not need to (and should not) be distributed.
这些-journal
文件并不需要(也应该不)进行分配。
This is because the various journal files represent temporary data(ref. SQLite's Use Of Temporary Disk Files) used by SQLite. In particular a -journal
file is a rollback journal.
这是因为各种日志文件代表SQLite 使用的临时数据(参考SQLite 的临时磁盘文件的使用)。特别是-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.
回滚日志是一个临时文件,用于在 SQLite 中实现原子提交和回滚功能。(有关其工作原理的详细讨论,请参阅标题为 SQLite 中的原子提交的单独文档。)回滚日志始终位于与数据库文件相同的目录中,并且与数据库文件具有相同的名称,除了 8 个字符“ -journal”附加。
回滚日志通常在事务第一次启动时创建,通常在事务提交或回滚时删除。回滚日志文件对于实现 SQLite 的原子提交和回滚功能至关重要。如果没有回滚日志,SQLite 将无法回滚未完成的事务,并且如果在事务中间发生崩溃或断电,如果没有回滚日志,整个数据库可能会损坏。
In general these -journal
files should only exist whenthere is an open SQLite database - or rather, a running transaction - but can be controlled via PRAGMA journal_mode. With default pragma settings the -journal
files will be deleted.
一般来说,这些-journal
文件应该只在有一个开放的 SQLite 数据库时才存在——或者更确切地说,一个正在运行的事务——但可以通过PRAGMA journal_mode进行控制。使用默认 pragma 设置,-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.
DELETE 日志模式是正常行为。在 DELETE 模式下,回滚日志在每个事务结束时被删除。实际上,删除操作是导致事务提交的操作。
Make sure to onlycopy the actual database files when the database is notopened and all journals have been deleted (or cleared) by SQLite itself; this implies all transactions have been completed and the database is in a consistent state.
确保仅在数据库未打开且所有日志已被 SQLite 本身删除(或清除)时才复制实际的数据库文件;这意味着所有事务都已完成并且数据库处于一致状态。