• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps sqlite query random example

Thank you , but if I am true , this is not the way I was asking for.
I wanted sqlite variant not java.

If I understand by using this method , I need to know how much records are into database and they must be without gaps between them?!
And this query will return one row or row group?

best regards,
ronnixw
 
Upvote 0
You asked for this method in your question, and this gives you a random row. To get the row count so you dont get IndexOutOfBounds use this:
Code:
Random r = new Random();
db.query(true, DB_TABLE, new String[] { "_id" }, "_id = ?", new String[] { String.valueOf(r.nextInt(getRowCount())) }, null, null, null, null);
Code:
private int getRowCount()
{
    Cursor c = db.query(DB_TABLE, new String[] { "_id" }, null, null, null, null, null);
    int count = c.getCount();
    c.close();
    return count;
}
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones