Skip to content

Commit

Permalink
prevent call to Expression.toString() when constructing Expression wi…
Browse files Browse the repository at this point in the history
…th `eq` method (JetBrains#1417)
  • Loading branch information
Tapac committed Jan 22, 2022
1 parent eb6e68a commit 3070d05
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract class Op<T> : Expression<T>() {
/** Builds a new operator using provided [op]. */
inline fun <T> build(op: SqlExpressionBuilder.() -> Op<T>): Op<T> = SqlExpressionBuilder.op()

fun <T> nullOp() : Op<T> = NULL as Op<T>
fun <T> nullOp(): Op<T> = NULL as Op<T>
}

internal interface OpBoolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ interface ISqlExpressionBuilder {
infix fun <T> ExpressionWithColumnType<T>.neq(other: T): Op<Boolean> = if (other == null) isNotNull() else NeqOp(this, wrap(other))

/** Checks if this expression is not equals to some [other] expression. */
infix fun <T, S1 : T?, S2 : T?> Expression<in S1>.neq(other: Expression<in S2>): Op<Boolean> = when {
other.equals(Op.NULL) -> isNotNull()
infix fun <T, S1 : T?, S2 : T?> Expression<in S1>.neq(other: Expression<in S2>): Op<Boolean> = when (other as Expression<*>) {
is Op.NULL -> isNotNull()
else -> NeqOp(this, other)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class UpdateBuilder<out T>(type: StatementType, targets: List<Table>) :
}

open operator fun <S> set(column: Column<S>, 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"
}

Expand All @@ -43,7 +43,7 @@ abstract class UpdateBuilder<out T>(type: StatementType, targets: List<Table>) :

@JvmName("setWithEntityIdExpression")
operator fun <S : Any?, ID : EntityID<S>, E : Expression<S>> set(column: Column<ID>, 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)
Expand Down

0 comments on commit 3070d05

Please sign in to comment.