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: Support Short type for BigDecimal conversion functions #1746

Merged
merged 3 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -490,6 +490,7 @@ class DecimalColumnType(
}
is Long -> value.toBigDecimal()
is Int -> value.toBigDecimal()
is Short -> value.toLong().toBigDecimal()
else -> error("Unexpected value of type Decimal: $value of ${value::class.qualifiedName}")
}.setScale(scale, RoundingMode.HALF_EVEN)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,29 @@ class H2Tests : DatabaseTestsBase() {
}
}

@Test
fun testH2V1WithBigDecimalFunctionThatReturnsShort() {
val testTable = object : Table("test_table") {
val number = short("number")
}

withDb(TestDB.allH2TestDB) {
try {
SchemaUtils.create(testTable)

testTable.batchInsert(listOf<Short>(2, 4, 6, 8, 10)) { n ->
this[testTable.number] = n
}

val average = testTable.number.avg()
val result = testTable.select(average).single()[average]
assertEquals("6.00".toBigDecimal(), result)
} finally {
SchemaUtils.drop(testTable)
}
}
}

class WrappedTransactionManager(val transactionManager: TransactionManager) :
TransactionManager by transactionManager

Expand Down
Loading