如何使用greenDao用where子句编写查询

时间:2016-07-14 08:49:53

标签: java android sqlite orm greendao

我正在尝试编写一个包含group by和greendao中where子句的简单查询,但是当我添加where子句时,我收到错误。是否有另一种方法来编写where子句,以便我可以使其工作

我基本上可以获得今天的部分时间并减去1,以便我可以上传前一天的数据。

 public  List<AppTimeUsage> LoadAppTimeUsageData() {

     List<AppTimeUsage> items = new ArrayList<>();
     Calendar calendar = Calendar.getInstance();
     int thisDay = calendar.get(Calendar.DAY_OF_MONTH);
     int previousDayCheck = thisDay -1 ;
     String sqlWhere;
     sqlWhere = "WHERE DAY_RECORDED = " + previousDayCheck;
     String sql = "SELECT APP_NAME , SUM(APP_TIME_SPENT) , DAY_RECORDED  FROM APP_TIME_USAGE " + sqlWhere + " GROUP BY APP_NAME ; ";

     Cursor c = appTimeUsageDao.getDatabase().rawQuery(sql, null);
     int offset = 0;
     int d;
     int cd;
     String e = "";
     while (c.moveToNext()) {
         AppTimeUsage atu = new AppTimeUsage(
                 Long.MIN_VALUE,
                 new Date(),
                 c.getInt(1),
                 c.getString(0),
                 c.getInt(2)
                 // break;
         );
         items.add(atu);
         //stats = atu;
     }
     return items;
 }

0 个答案:

没有答案