From 627b3b865cba1f3fdd1ed44dd047ab516622a43a Mon Sep 17 00:00:00 2001 From: "Andrey.Tarashevskiy" Date: Fri, 15 Apr 2022 19:51:30 +0300 Subject: [PATCH] Incorrect inList #1490 --- .../exposed/sql/SQLExpressionBuilder.kt | 4 ++-- .../jetbrains/exposed/sql/ops/InListOps.kt | 2 +- .../sql/tests/shared/dml/SelectTests.kt | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/SQLExpressionBuilder.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/SQLExpressionBuilder.kt index f8dc707254..59a747c4f6 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/SQLExpressionBuilder.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/SQLExpressionBuilder.kt @@ -410,9 +410,9 @@ interface ISqlExpressionBuilder { /** Checks if this expression is equals to any element from [list]. */ @Suppress("UNCHECKED_CAST") @JvmName("inListIds") - infix fun > Column>.inList(list: Iterable): InListOrNotInListBaseOp> { + infix fun , ID: EntityID?> Column.inList(list: Iterable): InListOrNotInListBaseOp?> { val idTable = (columnType as EntityIDColumnType).idColumn.table as IdTable - return inList(list.map { EntityIDFunctionProvider.createEntityID(it, idTable) }) + return SingleValueInListOp(this, list.map { EntityIDFunctionProvider.createEntityID(it, idTable) }, isInList = true) } /** Checks if this expression is not equals to any element from [list]. */ diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ops/InListOps.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ops/InListOps.kt index 64d6a03710..308cfccb13 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ops/InListOps.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ops/InListOps.kt @@ -75,7 +75,7 @@ abstract class InListOrNotInListBaseOp ( } class SingleValueInListOp( - expr: ExpressionWithColumnType, + expr: ExpressionWithColumnType, list: Iterable, isInList: Boolean = true ) : InListOrNotInListBaseOp(expr, list, isInList) { diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/SelectTests.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/SelectTests.kt index 9816d917ee..7a02a8aed4 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/SelectTests.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/SelectTests.kt @@ -8,6 +8,7 @@ import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.tests.DatabaseTestsBase import org.jetbrains.exposed.sql.tests.TestDB import org.jetbrains.exposed.sql.tests.shared.assertEquals +import org.jetbrains.exposed.sql.tests.shared.entities.EntityTests import org.junit.Test import kotlin.test.assertNull @@ -157,6 +158,24 @@ class SelectTests : DatabaseTestsBase() { } } + @Test + fun testInList08() { + withTables(EntityTests.Posts) { + val board1 = EntityTests.Board.new { + this.name = "Board1" + } + + val post1 = EntityTests.Post.new { + this.board = board1 + } + + EntityTests.Post.new { } + + val result = EntityTests.Posts.select { EntityTests.Posts.board inList listOf(board1.id) }.singleOrNull()?.get(EntityTests.Posts.id) + assertEquals(post1.id, result) + } + } + @Test fun testInSubQuery01() { withCitiesAndUsers { cities, _, _ ->