Android SQLite - mod_mode log change

I am trying to modify journal_mode for my database using code. I tried SQLiteDatabase.execSQL ("PRAGMA journal_mode = OFF"), but it fails because the expression "PRAGMA journal_mode = OFF" returns the result (I checked it from the terminal), and therefore Android considers this to be a request, and complains, that i should use execQuery instead. But what I'm trying to accomplish is not a request.

I also tried to compile the pragma expression in SQLiteStatement and called the execute method, but the same result.

Can anyone suggest any alternatives for doing this work with code?

Thanks Ranjit

+4
source share
2 answers

Perhaps you are suffering from this problem, which is mentioned in the execSQL documentation :

When using enableWriteAheadLogging (), journal_mode is automatically controlled by this class. Therefore, do not set journal_mode with the PRAGMA journal_mode statement if your application uses enableWriteAheadLogging ()

Make sure that you do not use the recording ahead of time, and then it can work.

Update: As Ranjit said in the comments, this should work:

Cursor c1 = db.rawQuery("PRAGMA journal_mode=OFF", null); c1.close(); 
+3
source

This can be done using the following command:

 db.rawExecSQL("PRAGMA journal_mode=OFF;"); 

(No need to create a Cursor as suggested in one of Robert's answer comments)

0
source

Source: https://habr.com/ru/post/1341924/


All Articles