Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite statement aborts, database locked in Android app

In my app I am inserting data in my SQLite database using ORMLite. 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. 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.

like image 744
Bart Bergmans Avatar asked Nov 09 '22 20:11

Bart Bergmans


1 Answers

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?

like image 118
Bart Bergmans Avatar answered Nov 15 '22 12:11

Bart Bergmans