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(table, columns, selection, selectionArgs, groupBy,
// having, orderBy);
return db.query(DATABASE_TABLE, new String[] { 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, null);
}
What I want to do, is to select rows starting at a certain row and limit the result to another number. So, for instance, I want to start at the tenth row and select the following 20 rows. I tried it like this:
public Cursor getAllDiscounts() {
return db.query(DATABASE_TABLE, new String[] { 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");
}
but the application crashes. I also tried with "LIMIT 10,20" instead of "10, 20", but that doesn't work either. Anyone?
the limit clause should be "10,20" with no space between the coma and the 20.
public Cursor getAllDiscounts() {
return db.query(DATABASE_TABLE, new String[] { 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");
}
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