vendredi 29 janvier 2016

Count all strings that matches a key in database

I have an SQLite database containing about 6,000 records. I want to search through the database and count how many strings match the key I'm looking for. I tried the following code, and it returns the number of rows that contains the key:

 String selectQuery = "SELECT count(*) FROM " + TABLE_NAME + " WHERE "
                + TEXT_COLUMN + " LIKE '%" + word + "%'";

c = mDb.rawQuery(selectQuery, null);
if (c != null && c.getCount() > 0) {
      c.moveToFirst();
      count = c.getInt(0);
}

But I want to count the number of strings that matches the key, even if a row contains more than one.

Is there a way to do that?

Aucun commentaire:

Enregistrer un commentaire