6

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.

Bart Bergmans
  • 4,061
  • 3
  • 28
  • 56

3 Answers3

1

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?

Bart Bergmans
  • 4,061
  • 3
  • 28
  • 56
  • how to add this in room? val db: SupportSQLiteDatabase? = roomDb.openHelper.writableDatabase; val cursor: Cursor = db!!.query("PRAGMA journal_mode = WAL;", null); cursor.close() ??? – A_rmas May 20 '20 at 19:21
0

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.

Stefan van de Laarschot
  • 2,154
  • 6
  • 30
  • 50
0

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

webo80
  • 3,365
  • 5
  • 35
  • 52
  • How can I see what operation is running? I waited a while before running a new query and I still get the error. On other devices I don't have this problem. – Bart Bergmans Feb 05 '16 at 08:48