android-room - 根据房间数据库中的时间戳值检索数据
问题描述
我正在尝试检索在最后 2 分钟内写入数据库的条目。我使用以下查询:
@Query("SELECT * FROM Contacts where ('now()' - gatt_server_connection_timestamp) <= 120000")
List<Contact> getContactsByGattServerConnectionTimestamp();
但是我得到的结果是整个数据库。
这个查询有什么问题?
解决方案
SQLite 日期时间函数在此处描述。
如果gatt_server_connection_timestamp
自纪元以来以毫秒为单位,则此查询应该有效:
@Query("SELECT * FROM Contacts where gatt_server_connection_timestamp >= (1000 * strftime('%s', datetime('now', '-2 minutes'))))
List<Contact> getContactsByGattServerConnectionTimestamp();
推荐阅读
- doctrine-orm - 如何使用 Doctrine 2 DQL ON 覆盖默认的 JOIN 条件
- php - Woocommerce 设置客户提供的注释也返回 html 标签
- c# - 如何将 Excel 表格数据迭代到 DataGridView?
- c# - 使用依赖于记录器的选项验证器创建依赖于选项的自定义记录器时出现循环依赖异常
- c# - 有没有办法缩短重复数学
- php - 我正在使用 PHPExcel 将颜色混合到 excels 单元中,将颜色变化反映到开放式办公室,但不反映到 microsoft-office o
- html - 通过 bulma 文件上传重用来自 fileInput 的闪亮进度条
- javascript - 从模板中的父组件触发子函数
- r - 在 R 中合并 SpatialPoints 和 SpatialPolygons 数据框
- angular - Angular 10:如何在延迟加载的功能模块中重置 RouterConfig