开发者

Android SQLite - changing journal_mode

I am trying to alter the journal_mode for my database, through code. I tried SQLiteDatabase.execSQL("PRAGMA journal_mode=OFF") but it fails because, the expression "PRAGMA journal_mode=OFF" returns a result (I verified this from the terminal), and so Android thinks this is a query and complains that I should be using execQuery instead. But what I am trying to execute isn't a query.

I also tried compiling the pragma 开发者_开发知识库expression to a SQLiteStatement and invoked the execute method, but same result.

Can someone suggest any alternatives to make this work through code?

Thanks, Ranjit


Perhaps you are suffering from this problem that the execSQL docs talk about:

When using enableWriteAheadLogging(), journal_mode is automatically managed by this class. So, do not set journal_mode using "PRAGMA journal_mode'" statement if your app is using enableWriteAheadLogging()

Check that you are not using write ahead logging and then it might work.

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

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


It can be done with the next command:

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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜