How to disable Android SQLite Journal file?

I use transactions to insert multiple rows into a table. But I still see the temporary sqlite-journal file created on the SD card, along with the sqlite table.

How to disable log file creation?

thank

+5
source share
4 answers

You can save the log in memory so that the -journal file is not created:

pragma journal_mode=memory;

Please note that you need to run it every time you open the database.

I recommend that you read the following to better understand what is happening:

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

+8
source

The log is an internal SQLite file that is used when executing transactions (to ensure rollback). You cannot turn it off and you do not want to.

+5

Recall that the expression PRAGMA journal_mode=OFFor is PRAGMA journal_mode=memoryvalid for each transaction base. You must set it for each transaction.

0
source

You can delete the log file using the code below

@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 the cursor. The cursor is an interface that provides random read and write access to the result set returned by the database query. The log file will be deleted if you use the cursor.

-1
source

All Articles