我正在尝试检索最近2分钟写入数据库的条目。 我使用以下查询:
@Query("SELECT * FROM Contacts where ('now()' - gatt_server_connection_timestamp) <= 120000")
List<Contact> getContactsByGattServerConnectionTimestamp();
但是我得到的结果是整个数据库。
此查询出了什么问题?
答案 0 :(得分:1)
SQLite日期时间函数为described here。
如果gatt_server_connection_timestamp
距纪元以毫秒为单位,则此查询应该有效:
@Query("SELECT * FROM Contacts where gatt_server_connection_timestamp >= (1000 * strftime('%s', datetime('now', '-2 minutes'))))
List<Contact> getContactsByGattServerConnectionTimestamp();