Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SQLite "BETWEEN" not inclusive or returns all records

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.

like image 905
fissk Avatar asked Nov 14 '22 10:11

fissk


1 Answers

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));
}
like image 147
Pradeep Sharma Avatar answered Nov 16 '22 03:11

Pradeep Sharma