我的sqlite数据库列定义如下:
@DatabaseField(canBeNull = true)
public Date dateFound;
当我打开sqlite broswer时,我发现它的定义如下:
'dateFound' TIMESTAMP
现在我创建QueryBuilder:
DateTime time=new DateTime();
DateTime minusDays = time.minusDays(4);
QueryBuilder<Record, Long> queryBuilder = DatabaseHelper.get().getRecordDao().queryBuilder();
Where<Record, Long> where = queryBuilder.where();
where.ne("amount",0);
where.or();
where.ge("dateFound",minusDays.toDate());
System.out.println(queryBuilder.prepareStatementString());
输出是:
SELECT * FROM `record` WHERE (`amount` <> 0 OR `dateFound` >= ? )
哪个不正确,我甚至尝试使用new Timestamp(minusDays.toDate().getTime())
,结果查询相同..
答案 0 :(得分:0)
我通过施放日期来解决它,这可能不是最好的方法,但它的工作:
DateTime time=new DateTime();
DateTime minusDays = time.minusDays(4);
QueryBuilder<Record, Long> queryBuilder = DatabaseHelper.get().getRecordDao().queryBuilder();
Where<Record, Long> where = queryBuilder.where();
where.ne("amount",0);
where.or();
where.raw("cast(`dateFound` as INTEGER)>= "+minusDays.toDate().getTime());