I am trying to query for a date between low and hign value:
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());
Car object looks this way:
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;
}
Unfortunaly I am getting no results. Where could be a problem?
Here's your problem: you made a cut & paste error. You set tomorrow equal to today, then inadvertently set yesterday equal to tomorrow. There are no days that are both greater than tomorrow and less than today, so you got no rows back.
Change your code to look like this:
Calendar tommorrow = Calendar.getInstance();
tomorrow.add(Calendar.DATE, 1); // change yesterday to tomorrow
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With