Android *.db-journal

<!-- The default journal mode to use use when Write-Ahead Logging is not active.
Choices are: OFF, DELETE, TRUNCATE, PERSIST and MEMORY.
PERSIST may improve performance by reducing how often journal blocks are
reallocated (compared to truncation) resulting in better data block locality
and less churn of the storage media. -->
<string name="db_default_journal_mode">PERSIST</string>

/**
* Gets the default journal mode when WAL is not in use.
*/
public static String getDefaultJournalMode() {
return SystemProperties.get("debug.sqlite.journalmode",
Resources.getSystem().getString(
com.android.internal.R.string.db_default_journal_mode));
}

...
private void open() {
mConnectionPtr = nativeOpen(mConfiguration.path, mConfiguration.openFlags,
mConfiguration.label,
SQLiteDebug.DEBUG_SQL_STATEMENTS, SQLiteDebug.DEBUG_SQL_TIME); setPageSize();
setForeignKeyModeFromConfiguration();
setWalModeFromConfiguration();
setJournalSizeLimit();
setAutoCheckpointInterval();
setLocaleFromConfiguration(); // Register custom functions.
final int functionCount = mConfiguration.customFunctions.size();
for (int i = 0; i < functionCount; i++) {
SQLiteCustomFunction function = mConfiguration.customFunctions.get(i);
nativeRegisterCustomFunction(mConnectionPtr, function);
}
}
... private void setWalModeFromConfiguration() {
if (!mConfiguration.isInMemoryDb() && !mIsReadOnlyConnection) {
if ((mConfiguration.openFlags & SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING) != 0) {
setJournalMode("WAL");
setSyncMode(SQLiteGlobal.getWALSyncMode());
} else {
setJournalMode(SQLiteGlobal.getDefaultJournalMode());
setSyncMode(SQLiteGlobal.getDefaultSyncMode());
}
}
} ...
private void setJournalMode(String newValue) {
String value = executeForString("PRAGMA journal_mode", null, null);
if (!value.equalsIgnoreCase(newValue)) {
try {
String result = executeForString("PRAGMA journal_mode=" + newValue, null, null);
if (result.equalsIgnoreCase(newValue)) {
return;
}
// PRAGMA journal_mode silently fails and returns the original journal
// mode in some cases if the journal mode could not be changed.
} catch (SQLiteDatabaseLockedException ex) {
// This error (SQLITE_BUSY) occurs if one connection has the database
// open in WAL mode and another tries to change it to non-WAL.
}
// Because we always disable WAL mode when a database is first opened
// (even if we intend to re-enable it), we can encounter problems if
// there is another open connection to the database somewhere.
// This can happen for a variety of reasons such as an application opening
// the same database in multiple processes at the same time or if there is a
// crashing content provider service that the ActivityManager has
// removed from its registry but whose process hasn't quite died yet
// by the time it is restarted in a new process.
//
// If we don't change the journal mode, nothing really bad happens.
// In the worst case, an application that enables WAL might not actually
// get it, although it can still use connection pooling.
Log.w(TAG, "Could not change the database journal mode of '"
+ mConfiguration.label + "' from '" + value + "' to '" + newValue
+ "' because the database is locked. This usually means that "
+ "there are other open connections to the database which prevents "
+ "the database from enabling or disabling write-ahead logging mode. "
+ "Proceeding without changing the journal mode.");
}
}
...
/**
* Executes a statement that returns a single {@link String} result.
*
* @param sql The SQL statement to execute.
* @param bindArgs The arguments to bind, or null if none.
* @param cancellationSignal A signal to cancel the operation in progress, or null if none.
* @return The value of the first column in the first row of the result set
* as a <code>String</code>, or null if none.
*
* @throws SQLiteException if an error occurs, such as a syntax error
* or invalid number of bind arguments.
* @throws OperationCanceledException if the operation was canceled.
*/
public String executeForString(String sql, Object[] bindArgs,
CancellationSignal cancellationSignal) {
if (sql == null) {
throw new IllegalArgumentException("sql must not be null.");
} final int cookie = mRecentOperations.beginOperation("executeForString", sql, bindArgs);
try {
final PreparedStatement statement = acquirePreparedStatement(sql);
try {
throwIfStatementForbidden(statement);
bindArguments(statement, bindArgs);
applyBlockGuardPolicy(statement);
attachCancellationSignal(cancellationSignal);
try {
return nativeExecuteForString(mConnectionPtr, statement.mStatementPtr);
} finally {
detachCancellationSignal(cancellationSignal);
}
} finally {
releasePreparedStatement(statement);
}
} catch (RuntimeException ex) {
mRecentOperations.failOperation(cookie, ex);
throw ex;
} finally {
mRecentOperations.endOperation(cookie);
}
}
Sqlite从3.7.0版本开始引入了WAL,这是一种新的事务回滚机制。
Android第一次操作数据库时,*.db-journal文件会被自动创建,且是持久保存在磁盘中,如果没有操作异常或者不需要事务回滚时,此文件的大小为0。这种机制避免了每次生成和删除*.db-journal文件的开销。
Android *.db-journal的更多相关文章
- AndroidSQLite多出一个(db.journal文件原因)
今天在Android开发中中将sqlite的数据库创建之后,发现生成的.db文件的旁边 生成了一个大小为0的与数据库文件同名的.db-journal文件,不明白此文件的用途,于是 google了sql ...
- Android DB那些事-数据库加密
说到数据库加密,目前最好且唯一的方案就是SqlCipher对sqlite3整体加密,微信也用的它.开源,且支持很多平台. 单就Android来说,集成不算太麻烦,1个jar包,3个so库,1个zip. ...
- android db 导入 手机 系统 目录 data/data/包名/databases
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha ======== 需要权限, 权限不足. 就算root之后,把这些都改成了777权限,仍 ...
- Android DB类,支持MDB,SQLITE,SQLSERVER,支持查询、事务,对象直接插入和更新操作等
直做数据库,最近花了点时间把自己常用的东西封装在一起. DBHelper using System; using System.Collections.Generic; using System.Te ...
- [android] 获取系统的联系人信息
内容提供是实质上是个接口,后门,他给别人提供数据,系统联系人是个比较复杂的内容通过者. 找到/data/data/com.android.providers.contacts/contacts2.db ...
- android通过pc脚本执行sqlite3脚本
最近在调研市面上的一些android db框架,需要经常重复的输入一堆比如 adb shell cd /data/data/com.example.testandroiddb/databases sq ...
- Android Weekly Notes Issue #287
Android Weekly Issue #287 December 10th, 2017 Android Weekly Issue #287 圣诞节快要来了,小编也偷懒了,本期内容包括如何通过AS添 ...
- android SQLite数据库的基本操作
SQLite是Android使用的轻量级的数据库,开发Android应用是对数据库的操作自然是必不可少. Android提供了一个SQLiteOpenHelper类来可以很方便的操作数据库, 继承和扩 ...
- Android O HIDL的实现对接【转】
本文转载自:https://blog.csdn.net/gh201030460222/article/details/80551897 Android O HIDL的实现对接1. HIDL的定义1.1 ...
- Android学习笔记_9_SQLiteOpenHelper对象之数据库增删改查以及事务回滚操作
一.SQLite数据库: 在Android平台上,集成了一个嵌入式关系型数据库—SQLite,SQLite3支持 NULL.INTEGER.REAL(浮点数字).TEXT(字符串文本)和BLOB(二进 ...
随机推荐
- gulp完成javascript压缩合并,css压缩
最近需要对项目进行优化,主要是对js的压缩合并和css文件的压缩,查找相关资料之后发现gulp可以实现相关的功能,特此分享一下使用心得. 1.安装gulp gulp是基于Node.js的前端构建工具. ...
- C# gridview分頁導出excel
#region 导出Excel方法 //导出到Excel按钮 protected void btnExport_Click(object sender, EventArgs e) { Export(& ...
- Eclipse中点击小猫提示Tomcat settings should be set in Tomcat Preference Page
1.window->preference->tomcat->tomcat-version选择自己tomcat版本 tomcat home 选择tomcat安装目录,即bin的上一层 ...
- linux常用编辑器
管理员在进行系统操作的时候,不可避免地会对文本进行修改,如进行各种服务程序配置文件的改动,使程序对用户提供不同的服务效果.在本章我们向大家介绍Linux上常见的编辑器ed.vi.emacs,同时以vi ...
- 强大的Core Image框架,各种滤镜处理图像
首先介绍一下Core Image,他是一个很强大的图像处理框架,他可以让你简单的应用各种滤镜来处理图像,比如说色相,饱和度,亮度等等...他是运用GPU(CPU)实时地处理图像数据和视频的帧.而且Co ...
- IIViewDeckController的使用,左右拖拉菜单效果实现
博客园 IIViewDeckController的使用,左右拖拉菜单效果实现 很多应用里面都实现了对应的侧拉 显示隐藏的效果,看起来很符合用户体验的类似于这种 看起来很好看,今天去晚上搜下 ...
- [转]Delphi执行CMD命令
今天看到有人在问用代码执行CMD命令的问题,就总结一下用法,也算做个备忘. Delphi中,执行命令或者运行一个程序有2个函数,一个是winexec,一个是shellexecute.这两个大家应该都见 ...
- JS实现页面跳转重定向的几种方式
1.重定向 <script language="javascript"type="text/javascript"> window.locatio ...
- OPENGL 地形
用OPNEGL弄了好久,终于有个地形的样子了! 看起来还是很糟糕....
- 让一个Html元素撑满整个屏幕可以这样玩
style="width:100%; height: 100%; overflow:hidden; position:absolute; top: 0; left: 0; z-index: ...