java - Android SQLite greater than query isn't working how I expect it to -
okay i'm missing fundamental here can't figure out is.
the problem:
i'm writing unit test database query search shifts have happened after date (the dates i'm storing in epoch milliseconds) logic dictates construct query shift start dates greater than specified date, seems simple enough yet test failing, , weirdly when flip greater lesser test passes o_o.
this query:
public cursor getautoclockedshifts(long datesince) { string sortorder = col_start_date + " desc"; string selection = col_added_manually + " = " + "?" + " , " + col_start_date + " > " + "?"; string[] selectionargs = {"0", datesince.tostring()}; cursor = database.query(false, gettablename(), null, selection, selectionargs, null, null, sortorder, null); return cursor; }
this fake data i'm using unit test:
private hashmap<string, ?> createshifthashmap(){ hashmap<string, object> values = new hashmap<>(); values.put(shiftdb.col_added_manually, 0); values.put(shiftdb.col_start_date, 1478871347000l);//human readable = 11/11/2016, 13:35:47 return values; }
and unit test i've put together:
@test public void tesgetautomaticallyaddedshifts() throws exception { long result = shiftdb.create(createshifthashmap()); cursor c = shiftdb.get(result); assertequals(1478871347000l, c.getlong(c.getcolumnindex(shiftdb.col_start_date))); asserttrue(1478871347000l > 1447421747000l); asserttrue(c.getlong(c.getcolumnindex(shiftdb.col_start_date)) > 1447421747000l); cursor c1 = shiftdb.getautoclockedshifts(1447421747000l);//human readable = 13/11/2015, 13:35:47 assertnotequals(0, c1.getcount()); }
i made sure data thought commenting out last 2 lines , verifying first 3 asserts pass (which do) last assert keeps on failing message:
java.lang.assertionerror: values should different. actual: 0
i know can't case android/java/sqlite making maths mistake, i'm @ loss whats wrong here, mentioned above test passes if flip greater lesser makes no sense start date value greater specified date.
please help.
Comments
Post a Comment