Farhad
Farhad

Reputation: 2003

Android sql lite get count returns 1

this is my select code in database class I've run this code when database was empty , when it had one row and when it had more than one row But at all conditions get row return 1 ! Thanks for any help code :

public int select(String table, String column, String record)
{
    int DataCount=0;
    Cursor c = database.rawQuery("SELECT COUNT(*) FROM "+table+" WHERE "+column+"='"+record+"'  ", null);
    DataCount=c.getCount();
    return DataCount;

}

Upvotes: 1

Views: 63

Answers (1)

Scary Wombat
Scary Wombat

Reputation: 44844

The Count function along with other similar functions such as SUM and AVG only return one row.

The c.getCount() method that you are calling returns the number of rows returned, not the value of it.

If you want the value of the row then use

https://developer.android.com/reference/android/database/Cursor.html#getInt(int)

e.g.

int val = c.getInt (0);

Upvotes: 1

Related Questions