Very simple task it would seem, trying to get a given range of records/rows in my SQLite db in Android app with the following :
String[] projection = {"_id"};
String selection = "_id between ? and ?";
String[] selectionArgs = {"1", "10"};
queryBuilder.query(db, projection, selection, selectionArgs, null, null, null);
With the above selectionArgs I'm getting just the two rows, row 1 and 10. If I change arg to anything else I'm getting the whole lot (entire set of records/rows) as if there was no condition. Been banging my head for a day why this works the way it does, perhaps there's some special thing to know about the use of "between" in SQLite ? Any comments/help much appreciated.
You can use this code.
private SQLiteDatabase productDatabase;
public Cursor get_result(){
Cursor c;
String sql = "SELECT * FROM " + tableName +"WHERE _id BETWEEN" + value1 +"AND" + value2;
c = productDatabase.rawQuery(sql, null);
}
Cursor cursor=get_result();
if(cursor.moveToNext()){
Log.d("count of product id="+cursor.getString(0));
}
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