Trojan
Trojan

Reputation: 119

SQLite Query Issues

Hi I am new to Android SQlite and following couple of examples to learn. I am trying to create a query that will fetch the number of IDs available in the database and its returning me errors as something is wrong with my query so I need some help to fix this query:

public Cursor getIds()
{
     return database.query(false, "details", "_id", "Select", "COUNT", null, null, null, null, null)
} 

Thanks in advance.

Upvotes: 1

Views: 139

Answers (2)

Xenione
Xenione

Reputation: 2213

the query is wrong

query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy)

you should have somethin like that:

Cursor c=query("TABLE NAME",new String[]{"COLUMN_ID_NAME"},null,null,null,null);
return c.getCount();

Upvotes: 0

Yaqub Ahmad
Yaqub Ahmad

Reputation: 27659

Try this:

public Cursor getIds()
{
    String sql = "SELECT COUNT(_Id) AS CountTotal FROM details";
    return db.rawQuery(sql, null); 
}

Upvotes: 1

Related Questions