ktorm
ktorm copied to clipboard
Query.limit() should honor 0 arguments for offset and limit
Ktorm Version: 3.5.0 Source File: org/ktorm/dsl/Query.kt Line: 398 Function definition:
public fun Query.limit(offset: Int?, limit: Int?): Query {
return this.withExpression(
when (expression) {
is SelectExpression -> expression.copy(
offset = offset?.takeIf { it > 0 } ?: expression.offset,
limit = limit?.takeIf { it > 0 } ?: expression.limit
)
is UnionExpression -> expression.copy(
offset = offset?.takeIf { it > 0 } ?: expression.offset,
limit = limit?.takeIf { it > 0 } ?: expression.limit
)
}
)
}
I think the takeIf predicates should be { it >= 0 } instead of strictly >, especially for offset. I believe it is valid (at least in MySQL) to have limit and/or offset equal to 0.
When using business logic to algorithmically build a query to be executed, I ended up calling this function with zeros, but received unexpected results.
Yes, I agree with you, but this change is incompatible, it should be made in the next major version, not 3.x.x.
Any news regarding this? Do I need to make a hack for it currently?