Merge "Update SqlParser to correctly detect top level star projection with a prefix." into androidx-main
diff --git a/room/room-compiler/src/main/kotlin/androidx/room/parser/SqlParser.kt b/room/room-compiler/src/main/kotlin/androidx/room/parser/SqlParser.kt
index b398f12..7b9df5e 100644
--- a/room/room-compiler/src/main/kotlin/androidx/room/parser/SqlParser.kt
+++ b/room/room-compiler/src/main/kotlin/androidx/room/parser/SqlParser.kt
@@ -84,7 +84,7 @@
}
override fun visitResult_column(ctx: SQLiteParser.Result_columnContext): Void? {
- if (ctx.parent.isCoreSelect && ctx.text == "*") {
+ if (ctx.parent.isCoreSelect && ctx.text == "*" || ctx.text.endsWith(".*")) {
foundTopLevelStarProjection = true
}
return super.visitResult_column(ctx)
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/parser/SqlParserTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/parser/SqlParserTest.kt
index 43835ef8..9428963 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/parser/SqlParserTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/parser/SqlParserTest.kt
@@ -15,6 +15,7 @@
*/
package androidx.room.parser
+import com.google.common.truth.Truth
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.CoreMatchers.not
import org.hamcrest.MatcherAssert.assertThat
@@ -274,6 +275,37 @@
}
@Test
+ fun hasTopStarProjection() {
+ SqlParser.parse("SELECT * FROM Foo").let {
+ Truth.assertThat(it.hasTopStarProjection).isTrue()
+ }
+ SqlParser.parse("SELECT Foo.* FROM Foo").let {
+ Truth.assertThat(it.hasTopStarProjection).isTrue()
+ }
+ SqlParser.parse("SELECT 0 as new, Foo.* FROM Foo").let {
+ Truth.assertThat(it.hasTopStarProjection).isTrue()
+ }
+ SqlParser.parse("SELECT f.* FROM Foo f").let {
+ Truth.assertThat(it.hasTopStarProjection).isTrue()
+ }
+ SqlParser.parse("SELECT id FROM Foo").let {
+ Truth.assertThat(it.hasTopStarProjection).isFalse()
+ }
+ SqlParser.parse("SELECT id FROM (SELECT * FROM Foo)").let {
+ Truth.assertThat(it.hasTopStarProjection).isFalse()
+ }
+ SqlParser.parse("SELECT COUNT(*) FROM Foo").let {
+ Truth.assertThat(it.hasTopStarProjection).isFalse()
+ }
+ SqlParser.parse("SELECT (SELECT * FROM Foo LIMIT 1) == 1 as uno FROM Foo").let {
+ Truth.assertThat(it.hasTopStarProjection).isFalse()
+ }
+ SqlParser.parse("INSERT INTO Foo VALUES (:param)").let {
+ Truth.assertThat(it.hasTopStarProjection).isNull()
+ }
+ }
+
+ @Test
fun foo() {
assertSections(
"select * from users where name like ?",