Skip to content

Commit

Permalink
Show length instead of value for exceeded column length (#1667)
Browse files Browse the repository at this point in the history
Based on solution 1 as mentioned in #1666
  • Loading branch information
simboel committed Jan 16, 2023
1 parent 1ee683a commit 4a9d718
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,9 @@ open class CharColumnType(

override fun validateValueBeforeUpdate(value: Any?) {
if (value is String) {
require(value.codePointCount(0, value.length) <= colLength) {
"Value '$value' can't be stored to database column because exceeds length ($colLength)"
val valueLength = value.codePointCount(0, value.length)
require(valueLength <= colLength) {
"Value can't be stored to database column because exceeds length ($valueLength > $colLength)"
}
}
}
Expand Down Expand Up @@ -602,8 +603,9 @@ open class VarCharColumnType(

override fun validateValueBeforeUpdate(value: Any?) {
if (value is String) {
require(value.codePointCount(0, value.length) <= colLength) {
"Value '$value' can't be stored to database column because exceeds length ($colLength)"
val valueLength = value.codePointCount(0, value.length)
require(valueLength <= colLength) {
"Value can't be stored to database column because exceeds length ($valueLength > $colLength)"
}
}
}
Expand Down Expand Up @@ -692,8 +694,9 @@ open class BinaryColumnType(

override fun validateValueBeforeUpdate(value: Any?) {
if (value is ByteArray) {
require(value.size <= length) {
"Value '$value' can't be stored to database column because exceeds length ($length)"
val valueLength = value.size
require(valueLength <= length) {
"Value can't be stored to database column because exceeds length ($valueLength > $length)"
}
}
}
Expand Down

0 comments on commit 4a9d718

Please sign in to comment.