can you please show me an example how to select random rows from database using :
db.query(table, columns, selection, selectionArgs, groupBy, having, orderBy)
Random r = new Random();
db.query(true, DB_TABLE, new String[] { "_id" }, "_id = ?", new String[] { String.valueOf(r.nextInt(100)) }, null, null, null, null);
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?
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;
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.