Merge "Resolving issue where `attachedDbs` was not returning the full list of attached databases." into snap-temp-L60900000959093030
diff --git a/sqlite/sqlite-framework/src/androidTest/java/androidx/sqlite/db/framework/FrameworkSQLiteDatabaseTest.kt b/sqlite/sqlite-framework/src/androidTest/java/androidx/sqlite/db/framework/FrameworkSQLiteDatabaseTest.kt
index c807e23..f419abd 100644
--- a/sqlite/sqlite-framework/src/androidTest/java/androidx/sqlite/db/framework/FrameworkSQLiteDatabaseTest.kt
+++ b/sqlite/sqlite-framework/src/androidTest/java/androidx/sqlite/db/framework/FrameworkSQLiteDatabaseTest.kt
@@ -79,4 +79,33 @@
val cursor2 = db.query("select * from user where idk=1")
assertThat(cursor2.count).isEqualTo(0)
}
+
+ @Test
+ fun testFrameWorkSQLiteDatabase_attachDbWorks() {
+ val openHelper2 = FrameworkSQLiteOpenHelper(
+ context,
+ "test2.db",
+ OpenHelperRecoveryTest.EmptyCallback(),
+ useNoBackupDirectory = false,
+ allowDataLossOnRecovery = false
+ )
+ val db1 = openHelper.writableDatabase
+ val db2 = openHelper2.writableDatabase
+
+ db1.execSQL(
+ "ATTACH DATABASE '${db2.path}' AS database2"
+ )
+
+ val cursor = db1.query("pragma database_list")
+ val expected = buildList<Pair<String, String>> {
+ while (cursor.moveToNext()) {
+ add(cursor.getString(1) to cursor.getString(2))
+ }
+ }
+ cursor.close()
+ openHelper2.close()
+
+ val actual = db1.attachedDbs?.map { it.first to it.second }
+ assertThat(expected).isEqualTo(actual)
+ }
}
\ No newline at end of file
diff --git a/sqlite/sqlite-framework/src/main/java/androidx/sqlite/db/framework/FrameworkSQLiteDatabase.kt b/sqlite/sqlite-framework/src/main/java/androidx/sqlite/db/framework/FrameworkSQLiteDatabase.kt
index 00257a1..b9aeb34 100644
--- a/sqlite/sqlite-framework/src/main/java/androidx/sqlite/db/framework/FrameworkSQLiteDatabase.kt
+++ b/sqlite/sqlite-framework/src/main/java/androidx/sqlite/db/framework/FrameworkSQLiteDatabase.kt
@@ -290,7 +290,8 @@
override val isWriteAheadLoggingEnabled: Boolean
get() = SupportSQLiteCompat.Api16Impl.isWriteAheadLoggingEnabled(delegate)
- override val attachedDbs: List<Pair<String, String>>? = delegate.attachedDbs
+ override val attachedDbs: List<Pair<String, String>>?
+ get() = delegate.attachedDbs
override val isDatabaseIntegrityOk: Boolean
get() = delegate.isDatabaseIntegrityOk