android - 带有 strftime 的 Room SQLite 选择语句不返回任何结果
问题描述
我有一个带有基于房间库的数据库的 android 应用程序。
public class Entry {
public Entry(int cat_id, Date date, float value, String comment) {
this.date = date;
this.value = value;
this.cat_id = cat_id;
this.comment = comment;
}
@PrimaryKey(autoGenerate = true)
public int entry_id;
public final Date date;
public final float value;
public final int cat_id;
public final String comment;
}
在 EntryDao 中,我有两个不起作用的 select 语句:
@Query(("SELECT sum(value) FROM Entry WHERE cat_id = :catId AND strftime('%Y', date) LIKE :year"))
float getSumByCatIdAndYear(int catId, int year);
@Query(("SELECT sum(value) FROM Entry WHERE cat_id = :catId AND strftime('%Y', date) LIKE :year AND strftime('%m', date) LIKE :month"))
float getSumByCatIdAndYearAndMonth(int catId, int year, int month);
我不知道为什么,但它总是返回 0.0 我认为我对 strftime 函数做错了,但我不确定。
解决方案
推荐阅读
- java - 如何将依赖项注入 RabbitListener
- python - 如何使用 tkinter filedialog.askopenfilename 方法避免文件选择器中的隐藏文件?
- javascript - 如何使用 puppeteer 获取 javascript 函数执行时间?
- python - ImportError:没有名为 dash 的模块
- c# - XML序列化多个具有相同名称但没有命名空间的元素
- php - PHP:使用 PDO 对象和多个准备语句会影响返回的 Statement 对象
- jquery-mobile - IBM Mobilfirst 中的应用程序崩溃
- android - Android RecyclerView 无法正常工作
- sql - 每个订单的最新状态以及何时设置为该值
- couchdb - 端口号可以在 couchDB -Hyperledger 中更改