Skip to content

Commit

Permalink
#300 Varchar doesn't validate length / Validate length only before ex…
Browse files Browse the repository at this point in the history
…ecute update
  • Loading branch information
Tapac committed Aug 9, 2018
1 parent bb113df commit 2e2f5de
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
8 changes: 0 additions & 8 deletions src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,6 @@ open class VarCharColumnType(val colLength: Int = 255, collate: String? = null)
append(" COLLATE $collate")
}
}

override fun notNullValueToDB(value: Any): Any {
val string = super.notNullValueToDB(value)
require(string is String && string.length <= colLength) {
"Value '$string' can't be stored to database column because exceeds length $colLength"
}
return string
}
}

open class TextColumnType(collate: String? = null) : StringColumnType(collate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.jetbrains.exposed.sql.statements
import org.jetbrains.exposed.sql.Column
import org.jetbrains.exposed.sql.Expression
import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.VarCharColumnType
import java.util.*

/**
Expand All @@ -19,6 +20,9 @@ abstract class UpdateBuilder<out T>(type: StatementType, targets: List<Table>):
if (!column.columnType.nullable && value == null) {
error("Trying to set null to not nullable column $column")
}
if (column.columnType is VarCharColumnType && value is String && value.length > column.columnType.colLength) {
error("Value '$value' can't be stored to database column because exceeds length $column.columnType.colLength")
}
values[column] = value
}

Expand Down

0 comments on commit 2e2f5de

Please sign in to comment.