ORMLite date request

I am trying to request a date between low and high:

Car car = new Car(1, "octavia"); car.setManufactured(Calendar.getInstance().getTime()); Dao<Car, Integer> carDao = getHelper().getCarDao(); carDao.create(car); QueryBuilder<Car, Integer> carQb = carDao.queryBuilder(); Calendar yesteday = Calendar.getInstance(); yesteday.add(Calendar.DATE, -1); Calendar tommorrow = Calendar.getInstance(); yesteday.add(Calendar.DATE, 1); carQb.where().between("manufactured", yesteday.getTime(), tommorrow.getTime()); PreparedQuery<Car> query = carQb.prepare(); List<Car> cars = carDao.query(query); Log.d(TAG, cars.get(0).toString()); 

An automobile object is as follows:

 public class Car { @DatabaseField(id = true) private int id; @DatabaseField String name; @DatabaseField(foreign = true, foreignAutoRefresh = true) User user; @DatabaseField(foreign = true, foreignAutoRefresh = true) private Brand brand; @DatabaseField(columnName="manufactured") private Date manufactured; } 

Unfortunately, I am not getting any results. Where could the problem be?

+7
source share
1 answer

Here is your problem: you made a cut and paste mistake. You set tomorrow equal to today, and then inadvertently set tomorrow equal to tomorrow. There are no days that will be more than tomorrow and less than today, so you have not received the lines back.

Change your code like this:

 Calendar tommorrow = Calendar.getInstance(); tomorrow.add(Calendar.DATE, 1); // change yesterday to tomorrow 
+8
source

All Articles