Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: EXPOSED-28 Update with join fails on H2 in MySql mode #1732

Merged
merged 4 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ internal object H2FunctionProvider : FunctionProvider() {
if (limit != null) {
transaction.throwUnsupportedException("H2 doesn't support LIMIT in UPDATE with join clause.")
}
if (where != null && (transaction.db.dialect as H2Dialect).h2Mode != H2Dialect.H2CompatibilityMode.Oracle) {
bog-walk marked this conversation as resolved.
Show resolved Hide resolved
transaction.throwUnsupportedException("H2 doesn't support WHERE in UPDATE with join clause.")
}
val tableToUpdate = columnsAndValues.map { it.first.table }.distinct().singleOrNull()
?: transaction.throwUnsupportedException("H2 supports a join updates with a single table columns to update.")
val joinPart = targets.joinParts.singleOrNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.jetbrains.exposed.crypt.Algorithms
import org.jetbrains.exposed.crypt.encryptedBinary
import org.jetbrains.exposed.crypt.encryptedVarchar
import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.dao.id.LongIdTable
import org.jetbrains.exposed.exceptions.UnsupportedByDialectException
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.tests.DatabaseTestsBase
Expand Down Expand Up @@ -100,6 +101,44 @@ class UpdateTests : DatabaseTestsBase() {
}
}

@Test
fun testUpdateWithJoinAndWhere() {
val tableA = object : LongIdTable("test_table_a") {
val foo = varchar("foo", 255)
}
val tableB = object : LongIdTable("test_table_b") {
val bar = varchar("bar", 255)
val tableAId = reference("table_a_id", tableA)
}

val supportWhere = TestDB.values().toList() - TestDB.allH2TestDB - TestDB.SQLITE + TestDB.H2_ORACLE

withTables(tableA, tableB) { testingDb ->
val aId = tableA.insertAndGetId { it[foo] = "foo" }
tableB.insert {
it[bar] = "zip"
it[tableAId] = aId
}

val join = tableA.innerJoin(tableB)

if (testingDb in supportWhere) {
join.update({ tableA.foo eq "foo" }) {
it[tableB.bar] = "baz"
}
join.selectAll().single().also {
assertEquals("baz", it[tableB.bar])
}
} else {
expectException<UnsupportedByDialectException> {
join.update({ tableA.foo eq "foo" }) {
it[tableB.bar] = "baz"
}
}
}
}
}

@Test
fun `test that column length checked in update `() {
val stringTable = object : IntIdTable("StringTable") {
Expand Down