How to disable Android SQLite Journal file?

穿精又带淫゛_ 提交于 2019-11-28 01:11:49

问题


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


回答1:


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




回答2:


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.




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/10046596/how-to-disable-android-sqlite-journal-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!