Where clause with DateTime doesn't work
See original GitHub issueI’m using the last version of Exposed 0.26.1 with sqlite jdbc. Where clause doesn’t seem to work properly, if some table has a DateTime column.
As an example I have a table TestDates
object TestDates : IntIdTable() {
val time: Column<DateTime> = datetime("time").defaultExpression(CurrentDateTime())
}
class TestDate(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<TestDate>(TestDates)
var time by TestDates.time
}
The table seems to be created right: CREATE TABLE TestDates (id INTEGER PRIMARY KEY AUTOINCREMENT, time NUMERIC DEFAULT (CURRENT_TIMESTAMP) NOT NULL)
Now I fill the table with test values:
for (i in 0..5) {
Thread.sleep(10_000)
transaction {
TestDate.new {
}
}
}
It looks correctly in the database browser: 1 | 2020-06-22 15:02:22 2 | 2020-06-22 15:02:32 3 | 2020-06-22 15:02:42 4 | 2020-06-22 15:02:52 5 | 2020-06-22 15:03:02 6 | 2020-06-22 15:03:12
Now I’m trying to make a simple query:
val count = transaction {
addLogger(StdOutSqlLogger)
TestDate.find { TestDates.time.greater(DateTime.parse("2020-06-22").withHourOfDay(15).withMinuteOfHour(2).withSecondOfMinute(50)) }.count()
}
and as a result I get count == 6
from Exposed
But the query in log seems to be correct:
SELECT COUNT(*) FROM TestDates WHERE TestDates.time > ‘2020-06-22 15:02:50.000000’
and if I execute it manually I get the right answer count == 3
Am I doing something wrong or is it actually a bug? Thank you in advance.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
I think I will use string representation via
SQLITE_DATE_TIME_STRING_FORMATTER
@yital9 Ah now I can reproduce it ! When I use your loop
for (i in 0..5) { Thread.sleep(10_000) ... }
to insert data I get count = 6. At the begining I inserted the values manually like below and I get count = 3 without any problem:I’m gonna make some investigation to understand the cause of this issue.