diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt index 2e96cb7385..dcc71027c4 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt @@ -63,7 +63,7 @@ interface IColumnType { /** Sets the [value] at the specified [index] into the [stmt]. */ fun setParameter(stmt: PreparedStatementApi, index: Int, value: Any?) { - if (value == null || value == Op.NULL) { + if (value == null || value is Op.NULL) { stmt.setNull(index, this) } else { stmt[index] = value @@ -722,7 +722,7 @@ class BlobColumnType : ColumnType() { override fun setParameter(stmt: PreparedStatementApi, index: Int, value: Any?) { when (val toSetValue = (value as? ExposedBlob)?.bytes?.inputStream() ?: value) { is InputStream -> stmt.setInputStream(index, toSetValue) - null, Op.NULL -> stmt.setNull(index, this) + null, is Op.NULL -> stmt.setNull(index, this) else -> super.setParameter(stmt, index, toSetValue) } } diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Op.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Op.kt index e6ce637ed5..1fa7a39415 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Op.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Op.kt @@ -12,7 +12,7 @@ abstract class Op : Expression() { /** Builds a new operator using provided [op]. */ inline fun build(op: SqlExpressionBuilder.() -> Op): Op = SqlExpressionBuilder.op() - fun nullOp() : Op = NULL as Op + fun nullOp(): Op = NULL as Op } internal interface OpBoolean diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/SQLExpressionBuilder.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/SQLExpressionBuilder.kt index dbc93be5c0..eb84d714bc 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/SQLExpressionBuilder.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/SQLExpressionBuilder.kt @@ -168,8 +168,8 @@ interface ISqlExpressionBuilder { infix fun ExpressionWithColumnType.neq(other: T): Op = if (other == null) isNotNull() else NeqOp(this, wrap(other)) /** Checks if this expression is not equals to some [other] expression. */ - infix fun Expression.neq(other: Expression): Op = when { - other.equals(Op.NULL) -> isNotNull() + infix fun Expression.neq(other: Expression): Op = when (other as Expression<*>) { + is Op.NULL -> isNotNull() else -> NeqOp(this, other) } diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/UpdateBuilder.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/UpdateBuilder.kt index 00cfd3a9cb..d9c9e74562 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/UpdateBuilder.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/UpdateBuilder.kt @@ -27,7 +27,7 @@ abstract class UpdateBuilder(type: StatementType, targets: List) : } open operator fun set(column: Column, value: S) { - require(column.columnType.nullable || (value != null && value != Op.NULL)) { + require(column.columnType.nullable || (value != null && value !is Op.NULL)) { "Trying to set null to not nullable column $column" } @@ -43,7 +43,7 @@ abstract class UpdateBuilder(type: StatementType, targets: List
) : @JvmName("setWithEntityIdExpression") operator fun , E : Expression> set(column: Column, value: E) { - require(column.columnType.nullable || value != Op.NULL) { + require(column.columnType.nullable || value !is Op.NULL) { "Trying to set null to not nullable column $column" } checkThatExpressionWasNotSetInPreviousBatch(column)