Skip to content

Commit

Permalink
Between function doesn't work when run against Oracle database #974
Browse files Browse the repository at this point in the history
  • Loading branch information
Tapac committed Jun 25, 2020
1 parent cd6bb93 commit 56aa7bb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Op.kt
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ class Between(
/** The expression being checked. */
val expr: Expression<*>,
/** Returns the lower limit of the range to check against. */
val from: LiteralOp<*>,
val from: Expression<*>,
/** Returns the upper limit of the range to check against. */
val to: LiteralOp<*>
val to: Expression<*>
) : Op<Boolean>(), ComplexExpression {
override fun toQueryBuilder(queryBuilder: QueryBuilder): Unit = queryBuilder { append(expr, " BETWEEN ", from, " AND ", to) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ interface ISqlExpressionBuilder {
// Comparison Predicates

/** Returns `true` if this expression is between the values [from] and [to], `false` otherwise. */
fun <T, S : T?> ExpressionWithColumnType<S>.between(from: T, to: T): Between = Between(this, asLiteral(from), asLiteral(to))
fun <T, S : T?> ExpressionWithColumnType<S>.between(from: T, to: T): Between = Between(this, wrap(from), wrap(to))

/** Returns `true` if this expression is null, `false` otherwise. */
fun <T> Expression<T>.isNull(): IsNullOp = IsNullOp(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.jetbrains.exposed.sql.tests.shared.assertEqualCollections
import org.jetbrains.exposed.sql.tests.shared.assertEqualLists
import org.jetbrains.exposed.sql.tests.shared.assertEquals
import org.jetbrains.exposed.sql.tests.shared.expectException
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.jetbrains.exposed.sql.vendors.MysqlDialect
import org.jetbrains.exposed.sql.vendors.OracleDialect
import org.jetbrains.exposed.sql.vendors.SQLServerDialect
Expand Down Expand Up @@ -277,4 +278,23 @@ class DefaultsTest : DatabaseTestsBase() {
assertEqualDateTime(nonDefaultDate, result2[foo.defaultDateTime])
}
}

@Test
fun testBetweenFunction() {
val foo = object : IntIdTable("foo") {
val dt = datetime("dateTime")
}

withTables(foo) {
val tr = TransactionManager.current()
tr.addLogger(StdOutSqlLogger)

val dt2020 = LocalDateTime.of(2020, 1, 1, 1, 1)
foo.insert { it[dt] = LocalDateTime.of(2019, 1, 1, 1, 1) }
foo.insert { it[dt] = dt2020 }
foo.insert { it[dt] = LocalDateTime.of(2021, 1, 1, 1, 1) }
val count = foo.select { foo.dt.between(dt2020.minusWeeks(1), dt2020.plusWeeks(1)) }.count()
assertEquals(1, count)
}
}
}

0 comments on commit 56aa7bb

Please sign in to comment.