-
Notifications
You must be signed in to change notification settings - Fork 697
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
Write two tests that catch a possible bug with SQLite + batchInsert #2116
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
package org.jetbrains.exposed.sql.tests.shared.dml | ||
|
||
import org.jetbrains.exposed.dao.id.EntityID | ||
import org.jetbrains.exposed.dao.id.IdTable | ||
import org.jetbrains.exposed.dao.id.IntIdTable | ||
import org.jetbrains.exposed.sql.* | ||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.times | ||
import org.jetbrains.exposed.sql.statements.ReturningStatement | ||
import org.jetbrains.exposed.sql.tests.DatabaseTestsBase | ||
import org.jetbrains.exposed.sql.tests.TestDB | ||
import org.jetbrains.exposed.sql.tests.shared.assertEqualCollections | ||
import org.jetbrains.exposed.sql.tests.shared.assertEquals | ||
import org.junit.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertFailsWith | ||
|
@@ -157,4 +160,27 @@ class ReturningTests : DatabaseTestsBase() { | |
assertTrue { result3.all { it == 0.0 } } | ||
} | ||
} | ||
|
||
object User : IdTable<String>("user") { | ||
val username = varchar("username", 128) | ||
override val primaryKey: PrimaryKey = PrimaryKey(username) | ||
override val id: Column<EntityID<String>> = username.entityId() | ||
} | ||
|
||
@Test | ||
fun testBatchInsertReturningCustomPrimaryKey() { | ||
withTables(TestDB.enabledDialects() - returningSupportedDb, User) { | ||
val result1 = User.batchInsert(listOf("batman")) { username -> | ||
this[User.username] = username | ||
}.single() | ||
assertEquals("batman", result1[User.id].value) | ||
assertEquals("batman", result1[User.username]) | ||
|
||
val result2 = User.batchInsert(listOf("superman")) { username -> | ||
this[User.username] = username | ||
}.single() | ||
assertEquals("superman", result2[User.username]) | ||
assertEquals("superman", result2[User.id].value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fails, because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Arguably should be a separate PR, because this is not related to SQLite specifically - this fails on any database There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created another https://youtrack.jetbrains.com/issue/EXPOSED-409/Custom-primary-key.-Access-to-the-primary-key-fails-with-ClassCastException issue for the second problem. It's clear why it happens, I'll try to fix it a bit later. |
||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fails, because
result1[User.id].value
is1
on SQLite