How to disable Android SQLite Journal file?
Asked Answered
B

4

6

I am using transactions to insert multiple rows into table. But, I still see temporary sqlite-journal file being created on SD Card along with sqlite table.

How do I disable creation of journal file?

Thanks

Bereft answered 6/4, 2012 at 16:56 Comment(2)
The journal file is created by the sqlite db when you use transactions to insure that if for some reason the transaction is interrupted by external means the db will not get corrupted. I would leave that alone if I were you.Jacksnipe
@Mr.Will So why, on Android, is the journal being kept around when nothing is touching the database, when this is not the default behavior on other systems?Speechmaker
Q
9

You can elect to keep the journal in memory so that no -journal file is created:

pragma journal_mode=memory;

Note that you need to run this each time you open the database.

I recommend that you read the following to get a better idea of what is going on:

http://www.sqlite.org/pragma.html#pragma_journal_mode

Quadriga answered 6/4, 2012 at 17:15 Comment(2)
So why is this file still around after using PRAGMA journal_mode=OFF and closing the database?Speechmaker
Does not work. see: #39246868Phylissphyll
S
5

The journal is an internal SQLite file that is used when running transactions (to ensure roll back). You cannot disable it, and you don't want to.

Stanislas answered 6/4, 2012 at 17:14 Comment(3)
Actually you can disable it :-) with PRAGMA journal_mode=OFFQuadriga
I tried the following: Cursor c1=db.rawQuery("PRAGMA journal_mode=OFF",null); c1.close(). Seems to have no effect. I still see journal file being createdBereft
Yes as I mentioned in my answer, the pragma doesn't persist so you need to run it each time you open the DB.Quadriga
C
1

Please remind, the statement PRAGMA journal_mode=OFF or PRAGMA journal_mode=memory is valid per transaction base. You need to set it for every transaction.

Camisole answered 8/1, 2018 at 3:43 Comment(0)
G
-1

You can delete journal file using below code

@Override
public void onOpen(SQLiteDatabase db) {         
    Cursor cc = db.rawQuery("PRAGMA journal_mode=DELETE",null);
    Log.i(TAG,"--- cursor count " + cc.getCount());     
    super.onOpen(db);        
}

You need to use cursor. Cursor is a interface provides random read-write access to the result set returned by a database query. The journal file will get delete if you use cursor.

Grovel answered 23/2, 2015 at 6:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.