Resolving incorrect behavior in QueryInterceptorDatabase `execSQL()` function.
During the conversion of Room sources from Java to Kotlin, the `execSQL()` function logic was altered to incorrectly execute the input arguments `bindArgs` as a single element instead of the individual elements inside the `bindArgs` argument list.
Bug: 288650357
Test: QueryInterceptorTest.kt
Change-Id: Iefdc8504d34c91081d8f9c195c978737c480e01d
diff --git a/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/test/QueryInterceptorTest.kt b/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/test/QueryInterceptorTest.kt
index 82a15d5..2808373 100644
--- a/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/test/QueryInterceptorTest.kt
+++ b/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/test/QueryInterceptorTest.kt
@@ -167,6 +167,20 @@
}
@Test
+ fun testExecSQLWithBindArgs() {
+ mDatabase.openHelper.writableDatabase.execSQL(
+ "INSERT OR ABORT INTO `queryInterceptorTestDatabase` (`id`,`description`) " +
+ "VALUES (?,?)",
+ arrayOf("3", "Description")
+ )
+ assertQueryLogged(
+ "INSERT OR ABORT INTO `queryInterceptorTestDatabase` (`id`,`description`) " +
+ "VALUES (?,?)",
+ listOf("3", "Description")
+ )
+ }
+
+ @Test
fun testNullBindArgument() {
mDatabase.openHelper.writableDatabase.query(
SimpleSQLiteQuery(
diff --git a/room/room-runtime/src/main/java/androidx/room/QueryInterceptorDatabase.kt b/room/room-runtime/src/main/java/androidx/room/QueryInterceptorDatabase.kt
index d6a4107..0f1ec17 100644
--- a/room/room-runtime/src/main/java/androidx/room/QueryInterceptorDatabase.kt
+++ b/room/room-runtime/src/main/java/androidx/room/QueryInterceptorDatabase.kt
@@ -136,11 +136,10 @@
// and it can't be renamed.
@Suppress("AcronymName")
override fun execSQL(sql: String, bindArgs: Array<out Any?>) {
- val inputArguments = mutableListOf<Any>()
- inputArguments.addAll(listOf(bindArgs))
+ val inputArguments = buildList { addAll(bindArgs) }
queryCallbackExecutor.execute {
queryCallback.onQuery(sql, inputArguments)
}
- delegate.execSQL(sql, arrayOf(inputArguments))
+ delegate.execSQL(sql, inputArguments.toTypedArray())
}
}