private int getTemporaryId() throws SQLException {QueryBuilder<MyClass, Integer> builder = this.queryBuilder();
int result = -1;
builder.selectRaw("min(" + MyClass.ID + ")").prepare();
String[] qryResult = builder.queryRawFirst();
if (qryResult[0] != null && Integer.parseInt(qryResult[0]) <= 0) {result = Integer.parseInt(qryResult[0]) - 1;}return result;}
and this:
private int getTemporaryId() throws SQLException {QueryBuilder<MyClass, Integer> builder = this.queryBuilder();}
int result = -1;
builder.orderBy(MyClass.ID, true);
MyClass myObject = queryForFirst(builder.prepare());
if(myObject
!= null) {result =}myObject
.getId()-1;
return result;
with the very same result: In the first case, I get the value "0" and in the second one, I get an object with its ID equals to "0". The thing is that if I run this sql sentence directly in a copy of the
local database:
select min(_id) from myTable;
then I get the expected negative value. So, my question is. Is there any way to select those negative values using OrmLite? Am I doing anything wrong?
Nothing to do with the Ormlite framework. I was doing something wrong in another part of the code. |