简体   繁体   English

SQLite语句中止,数据库锁定在Android应用中

[英]SQLite statement aborts, database locked in Android app

In my app I am inserting data in my SQLite database using ORMLite. 在我的应用程序中,我正在使用ORMLite将数据插入SQLite数据库中。 On some devices I get the following error when inserting data: 在某些设备上,插入数据时出现以下错误:

02-05 09:29:56.864  22365-22441/com.app E/SQLiteLog﹕ (5) statement aborts at 2: [PRAGMA journal_mode=PERSIST]
02-05 09:29:56.864  22365-22441/com.app W/SQLiteConnection﹕ Could not change the database journal mode of '/data/data/com.app/databases/app.db' from 'wal' to 'PERSIST' 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.

I have no idea how I can fix this problem for ORMLite. 我不知道如何为ORMLite解决此问题。 Does anyone have a fix for my problem? 有人能解决我的问题吗? Only accessing one SQLOpenHelper isn't going to solve my problem since I am using ORMLite and don't use the SQLOpenHelper directly from my code. 仅访问一个SQLOpenHelper并不能解决我的问题,因为我正在使用ORMLite,并且不要直接从我的代码中使用SQLOpenHelper。

Are you using a query before this statement it seems that the executing of that threat is still executing ? 您是否正在使用此语句之前的查询,似乎仍在执行该威胁?

Maybe you need to wait for the result before starting the other query? 也许您需要在开始其他查询之前等待结果? Not sure if that is the case trying to think with ya. 不知道是不是想和你一起思考。

As the error says, there in an ingoing operation. 如错误所示,正在进行操作。 Maybe some kind of operation is slower in one device that another. 一台设备中某种操作的速度可能比另一台设备慢。 Review your code keeping it in mind 回顾代码,牢记这一点

I think I got a solution. 我想我找到了解决方案。 I executed the following code from each of my DatabaseManagers: 我从每个数据库管理器中执行了以下代码:

SQLiteDatabase db = helper.getWritableDatabase();
Cursor cursor = db.rawQuery("PRAGMA journal_mode = WAL;", null);
cursor.close();

I get a lot less statement aborts errors but I am still getting a few of them. 我得到的语句减少了很多,但异常中止了错误,但是我仍然得到了一些错误。 Should I run that code after every query or is this not a good solution? 我应该在每次查询后运行该代码,还是这不是一个好的解决方案?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM