0

I want to copy SQLite database from asset but it is not copying it is not throwing any Exception also

@Database(entities = [UserDetails::class, CircleMaster::class], version = 1, exportSchema = false

abstract class AppDatabase : RoomDatabase() {abstract fun getLoginDao(): LoginDao

abstract fun getRegisterDao(): RegisterDao


companion object {
    @Volatile
    private var instance: AppDatabase? = null
    private val Lock = Any()
    operator fun invoke(context: Context) = instance ?: synchronized(Lock) {
        instance ?: buildDatabase(context).also {
            instance = it
        }
    }

    private fun buildDatabase(context: Context) = Room.databaseBuilder(
        context.applicationContext,
        AppDatabase::class.java,
        "Asset.db"
    ).createFromAsset("database/Asset.db").allowMainThreadQueries().build()
}}
creativecoder
  • 1,470
  • 1
  • 14
  • 23

1 Answers1

0

Actually I got an answer from this link

Room: Database not created

when I tried to insert data that time database is copied from asset and data is inserted some people will face migration exception, I solved that by deleting room master table from the asset database.

Under the covers, by default, Room uses SQLiteOpenHelper, much as you might use it directly.

SQLiteOpenHelper does not create the database when you create the SQLiteOpenHelper instance. It will do so once you call getReadableDatabase() or getWriteableDatabase().

From a Room standpoint, that means until you perform some concrete operation, such as invoking a @Dao method that hits the database, your database will not be created.

creativecoder
  • 1,470
  • 1
  • 14
  • 23