【发布时间】:2015-11-11 17:40:13
【问题描述】:
我想获取 11 月至 11 月的所有值。 我创建了类似的东西:
public static List<Plan> getPlanListByMonth(SQLiteDatabase db, DateTime date) {
String where = "strftime('%m', '"+"date"+"') = " +
"'"+"11"+"'";
Cursor cursor = db.query(TABLE_NAME, null, where,
null, null, null, null, null);
return getPlanList(cursor);
}
private static List<Plan> getPlanList(Cursor cursor) {
List<Plan> PlanList = null;
if (cursor != null) {
PlanList = new ArrayList<>();
if(cursor.moveToFirst()) {
do {
Object obj = getPlan(cursor);
PlanList.add((Plan) obj);
} while (cursor.moveToNext());
}
cursor.close();
}
return PlanList;
}
但是没有效果。关于如何按月获取所有值的任何想法?
【问题讨论】:
-
我复制粘贴你的字符串。这是在调试器中查看查询的方式: SQLiteQuery: SELECT * FROM trainingPlan WHERE strftime('%m', '2015-11-30') = 11
-
这是实际查询:SQLiteDirectCursorDriver: SELECT * FROM exercisePlan WHERE strftime('%m', date) = 11 且无效
-
是的!最后!十分感谢!你是我的英雄:D
-
有时最容易掉入的陷阱就在我们的眼皮底下,嗯?