Exception Invalid Limit Clauses - Android
These are the parameters of the query() method:
Cursor c = _Db.query( TABLE_NAME, // table new String[] {"max(ID)"}, // columns null, // selection null, // selectionArgs null, // groupBy null, // having COMMAND, // orderBy param_str); // limit
The orderBy
and limit
parameters do not make sense. To find the largest ID in the entire table, these parameters must be null
.
Anyway, there is a helper function that makes it reasier to read a single number from the database without having to muck around with a cursor:
long lastID = DatabaseUtils.longForQuery(_Db, "SELECT max(ID) FROM "+TABLE_NAME, null);
And if you had declared the ID
column as INTEGER PRIMARY KEY
, it would be autoincremented, and you would not have to set it manually.