I have exposed code along the lines of this (names...
# exposed
d
I have exposed code along the lines of this (names changed):
Copy code
private suspend fun <T> executeQuery(timeout: Duration = 3.seconds, block: suspend Transaction.() -> T): T =
	withTimeout(timeout) { newSuspendedTransaction(<http://Dispatchers.IO|Dispatchers.IO>) { block() } }

public suspend fun test1() = executeQuery(10.seconds) {
	with(SomeTable) {
		slice(id, other_id, valid_from).select {
			(status eq BigDecimal.ONE) and (someFlag eq BigDecimal.ZERO) and
			(CurrentDateTime.between(valid_from, valid_to))
		}.forEach {
			println("$it")
		}
	}
}
but I am getting
Exception in thread "main" java.lang.IllegalStateException: Unexpected value: com.example.MayDatabase$SomeTable.valid_from of org.jetbrains.exposed.sql.Column
I am not sure what I am doing wrong. Very similar code to this worked before
b
Hi, can you share your SomeTable object, probably valid_from is not defined correctly (as column)
d
Copy code
object SomeTable : Table("some_table") {
	...
	val valid_from = datetime("valid_from")
	val valid_to = datetime("valid_to")
	...
}
b
datetime imported from
Copy code
import org.jetbrains.exposed.sql.javatime.datetime
right?
d
yes
Ok, so the problem seems to be the
between
function. When I substituted it by
(valid_from less CurrentDateTime) and (valid_to greater CurrentDateTime)
it started working
So after further investigation, it seems that because that
between
function is defined as
Copy code
fun <T, S : T?> ExpressionWithColumnType<S>.between(from: T, to: T): Between = Between(this, wrap(from), wrap(to))
where it wraps those parameters into
QueryParameter<T>
unconditionally, it makes it not work correctly when you pass it`Column<T>` . I experimentally created modified version like this:
Copy code
fun <T, S : T?> ExpressionWithColumnType<S>.between(from: T, to: T): Between = 
    Between(this, if (from is Column<*>) { from } else { wrap(from) }, if (to is Column<*>) { to } else { wrap(to) })
which seems to work correctly. Do you think its worth a PR?