Код: Выделить всё
val tempFile = File.createTempFile("temp", ".db")
if (!tempFile.isFile) {
Timber.d("IdentifyRoomDatabase.getPartialExportFile.tempFile not there: $tempFile")
}
try {
val db = openHelper.writableDatabase
runInTransaction {
db.execSQL("ATTACH DATABASE ? AS temp_db", arrayOf(tempFile.absolutePath))
val tables: MutableList = mutableListOf()
var cursor = db.query("SELECT name FROM sqlite_master WHERE type='table'")
while (cursor.moveToNext()) {
tables.add(cursor.getString(0))
}
val internalTables = listOf("sqlite_master", "sqlite_sequence", "room_master_table", "android_metadata")
tables.removeAll(internalTables)
cursor.close()
tables.map {
db.execSQL(
"CREATE TEMP TABLE temp_$it AS SELECT * FROM 'person' WHERE id IN (${personsList.joinToString(",")})"
)
}
tables.map {
db.execSQL("CREATE TABLE IF NOT EXISTS temp_db.$it AS SELECT * FROM temp_$it")
}
tables.map {
db.execSQL("DROP TABLE temp_$it")
}
db.execSQL("DETACH DATABASE temp_db")
}
return tempFile
} catch (e: Throwable) {
tempFile.delete()
throw e
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... cked-error