Using in-memory sqlite android

前端 未结 3 1875
情话喂你
情话喂你 2020-12-15 06:14


I\'ve been reading, browsing, searching a lot on this, I\'ve criss-crossed stackoverflow back and forth many times and I managed to narrow my problem as much as I cou

相关标签:
3条回答
  • 2020-12-15 06:30

    SQLiteOpenHelper() will create an in-memory database if the name is null. Note that it will be created when you invoke getWritableDatabase().

    Then you should insert your data.

    0 讨论(0)
  • 2020-12-15 06:39

    You (or the framework) create a database using ONE of the following:

    • SQLiteDatabase.create()
    • SQLiteDatabase.openDatabase()
    • SQLiteDatabase.openOrCreateDatabase()

    The first option is the only way to create a memory-only database, the other two open or create a database file.

    Consequently, if you are using SQLiteOpenHelper() and you pass name as null, the framework calls SQLiteDatabase.create(null), so you will get a database that only lives in memory (it dies when close() is called). There is no need to also call one of the other direct methods. Instead call getReadableDatabase() or getWritableDatabase() from your helper.

    0 讨论(0)
  • 2020-12-15 06:54

    You have to be carefull wile using inmemory as your data will be lost once the db connection is lost. Make sure your db instance is not been closed

    https://www.sqlite.org/inmemorydb.html

    0 讨论(0)
提交回复
热议问题