Home » Android » android – Room attaching and copying data from database-Exceptionshub

android – Room attaching and copying data from database-Exceptionshub

Posted by: admin February 26, 2020 Leave a comment

Questions:

Android database not being attached using room raw query.

Dao class:

@Dao
abstract class SincronizacionInicialDao {

    @RawQuery
    abstract fun executeQuery(query: SupportSQLiteQuery): Int
}

Usage in class:

val dao = database.sincronizacionInicialDao()

val path = contextWeakReference.get()?.getDatabasePath(dataBaseName).toString()
                    val attachQuery = "ATTACH DATABASE '$path' AS db"
dao.executeQuery(SimpleSQLiteQuery(attachQuery))

Database is provided by koin

 single {
        val migration_100_101: Migration = object : Migration(1, 2) {
            override fun migrate(database: SupportSQLiteDatabase) {
            }
        }
        Room.databaseBuilder(
                androidContext(),
                Database::class.java, "database.sqlite"
        ).addMigrations(migration_100_101)
                .build()
    }

My database is not being attached using raw query.

How to&Answers: