Skip to content Skip to sidebar Skip to footer

Limiting A Sqlite Query In Android

I am using an SQLite database in my android application, and I have a function which selects the rows from a certain table: public Cursor getAllDiscounts() { // return db.query

Solution 1:

the limit clause should be "10,20" with no space between the coma and the 20.

publicCursorgetAllDiscounts() {
    return db.query(DATABASE_TABLE, newString[] { KEY_ROWID,
            KEY_PORTALNAME, KEY_TITLE, KEY_TITLESHORT, KEY_DEALURL,
            KEY_ENDDATE, KEY_COORDS, KEY_CITY, KEY_IMAGEDEAL,
            KEY_CLICKPRICE, KEY_CONVERSIONPERCENTAGE, KEY_FINALPRICE,
            KEY_ORIGINALPRICE, KEY_SALES, KEY_KATEGORIJA, KEY_POPUST },
            null, null, null, null, null, "10,20");
}

Solution 2:

Use "limit 10 offset 20" as limit clause.

publicCursorgetAllDiscounts() {
    return db.query(DATABASE_TABLE, newString[] { KEY_ROWID,
            KEY_PORTALNAME, KEY_TITLE, KEY_TITLESHORT, KEY_DEALURL,
            KEY_ENDDATE, KEY_COORDS, KEY_CITY, KEY_IMAGEDEAL,
            KEY_CLICKPRICE, KEY_CONVERSIONPERCENTAGE, KEY_FINALPRICE,
            KEY_ORIGINALPRICE, KEY_SALES, KEY_KATEGORIJA, KEY_POPUST },
            null, null, null, null, null, " limit 10 offset 20");
}

Solution 3:

Try this:

db.rawQuery("SELECT * FROM " + TABLE_NAME + " ORDER BY " + ORDER_BY + " LIMIT 0, 20", NULL);

Solution 4:

db.rawQuery("SELECT * FROM com_kkorm_data_Entity WHERE id!=0 ORDER BY id LIMIT 0,2",null);

Maybe my sql can help you understand LIMITsql

Post a Comment for "Limiting A Sqlite Query In Android"