Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limiting a SQLite query in android [closed]

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?

like image 303
Marko Cakic Avatar asked Dec 03 '12 19:12

Marko Cakic


Video Answer


1 Answers

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");
}
like image 78
martinpesevski Avatar answered Sep 30 '22 12:09

martinpesevski