user3600801
user3600801

Reputation:

Unable to grab all rows that Matches the id in sqlite

I have the following code where Im trying trying to grab all rows that matches the id.

public ChartData getCompliedChartCounts(int id) {
        SQLiteDatabase db = this.getReadableDatabase();

        SQLiteDatabase sqLiteDatabase = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();


        Cursor cursor = db.query(TABLE_COMPLIANCE_CHART_COUNTS, new String[]{KEY_ID,
                        KEY_FILTER_ID, KEY_YEAR, KEY_COUNTRY_ID, KEY_DOMAIN_ID, KEY_COMPLIED_COUNT, KEY_NOT_COMPLIED_COUNT, KEY_DELAYED_COUNT, KEY_INPROGRESS_COUNT}, KEY_COUNTRY_ID + "=?",
                new String[]{String.valueOf(id)}, null, null, null, null);
        if (cursor != null)
            cursor.moveToFirst();
        ChartData country = new ChartData(cursor.getInt(0), cursor.getInt(1), cursor.getInt(2), cursor.getInt(3), cursor.getInt(4), cursor.getInt(5), cursor.getInt(6), cursor.getInt(7), cursor.getInt(8));
        // return contact
        return country;
    }

When Im invoking it like getCompliedChartCounts(3) , I want it to grab all rows that contains the id 3.

But problem is that, it grabs only the first row that matches the id 3 whereas the remaining rows are not being fetched. How can I sort this out?

Upvotes: 1

Views: 50

Answers (1)

Surya Prakash Kushawah
Surya Prakash Kushawah

Reputation: 3201

Dear you are not iterate the cursor . you fetch only first row you should try

try {
    while (cursor.moveToNext()) {
        ...
    }
} finally {
    cursor.close();
}

And hold the all content and grab all content

Upvotes: 4

Related Questions