什么是“新闻"? Android中的SQLite数据库? [英] What is the "-journal" SQLite database in Android?

查看:120
本文介绍了什么是“新闻"? Android中的SQLite数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

e.g: myDatabase, myDatabase-journal, myOtherDatabase.db, myOtherDatabase.db-journal

这是什么?

如果我正在为我的应用程序提供预填充的数据库(按照:

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?'

推荐答案

不需要分发此类-journal文件(并且应分发 not ).

Such -journal files do not need to (and should not) be distributed.

这是因为各种日记文件表示临时数据(请参阅 SQLite的使用SQLite使用的临时磁盘文件).特别是-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中的Atomic Commit的单独文档.)回滚日志始终与数据库文件位于同一目录中,并且与数据库文件具有相同的名称,但带有8个字符的"; -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.

回滚日志通常在首次启动事务时创建,并且通常在事务提交或回滚时被删除.回滚日志文件对于实现SQLite的原子提交和回滚功能至关重要.没有回滚日志,SQLite将无法回滚不完整的事务,并且如果在事务中间发生崩溃或断电,那么如果没有回滚日志,整个数据库可能会损坏.

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数据库(或者更确切地说是正在运行的事务)时存在,但可以通过

In general these -journal files should only exist when there 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.

DELETE日记记录模式是正常行为.在DELETE模式下,回滚日志在每个事务结束时被删除.实际上,删除操作是导致事务提交的操作.

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本身删除(或清除)时,请确保仅复制 实际的数据库文件;这意味着所有事务都已完成,并且数据库处于一致状态.

Make sure to only copy the actual database files when the database is not opened 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.

这篇关于什么是“新闻"? Android中的SQLite数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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