【发布时间】:2012-05-26 09:54:52
【问题描述】:
public GenericRawResults<Object[]> getCountByStatus(Date date,int status){
Log.info("CallDayPlanningDao",date.toString());
GenericRawResults<Object[]> rawResults=null;
Dao callDayPlanningDao = getDao(CallDayPlanning.class);
QueryBuilder query = callDayPlanningDao.queryBuilder();
int year = date.getYear();
int month = date.getMonth();
Date date1 = new Date(year, month,1);
Date date2 = new Date(year, month+1,1);
Date startDate = new Date(date1.getTime()-5);
Date endDate = new Date(date2.getTime()-5);
try {
**query.where().between("calldate", startDate, endDate);**//This line is not working
if(status==Constant.cnStatus){
query.where().in("callstatus", status,Constant.ccStatus);
}else{
query.where().eq("callstatus", status);
}
query.groupBy("calldate");
query.selectRaw("calldate,count(*)");
rawResults = callDayPlanningDao.queryRaw(query.prepareStatementString(), new DataType[] {
DataType.DATE_STRING, DataType.INTEGER });
// page through the results
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return rawResults;
}
好吧,我想获取对象的计数,但是日期条件无效,我从数据库中获取所有数据。有人可以帮助我吗?谢谢。
【问题讨论】:
-
这个问题可以被关闭,因为很难看到你在问什么。请编辑您的帖子以解释您遇到的问题。你有例外吗?您还应该使您的代码示例更简洁。它没有返回正确的结果吗?
date1.getTime()-5返回与其他日期相差 5 毫秒的时间。这是你想要的吗? -
我想得到这个月的数据,所以日期可以是这个月的任何一天。
date1.getTime()-5确保可以找到所有数据。而且,我的问题是,我想获取每天的数据计数,但是 query.where query.where().between("calldate", startDate, endDate); 似乎不起作用. -
代码对我来说看起来不错。我假设数据库中的所有日期都是用
new Date(year, month, 1);创建的。如果白天到处都是日期,那么groupBy()显然不会将它们分组。可以输入一些数据和输出结果吗?
标签: android ormlite query-builder