我正在尝试检索在过去2分钟内写入数据库的条目。我使用以下查询:
@Query("SELECT * FROM Contacts where ('now()' - gatt_server_connection_timestamp) <= 120000")
List<Contact> getContactsByGattServerConnectionTimestamp();
然而,我得到的结果是整个数据库。
这个查询有什么问题?
SQLite日期-时间函数在这里进行了描述。
如果gatt_server_connection_timestamp
自epoch以来以毫秒为单位,则此查询应该有效:
@Query("SELECT * FROM Contacts where gatt_server_connection_timestamp >= (1000 * strftime('%s', datetime('now', '-2 minutes'))))
List<Contact> getContactsByGattServerConnectionTimestamp();