mardi 11 août 2015

Why am I only getting one row from SQLite query?

I'm trying to get the entire column of a SQlite database, but I am only getting one row. What is wrong with my query?

public ArrayList<String> getGroupNames() {
    ArrayList<String> groupNames = new ArrayList<>();

    SQLiteDatabase db = this.getReadableDatabase();
    String selectQuery = "SELECT " + KEY_GROUP + " FROM " + TABLE_LOGIN;

    Cursor cursor = db.rawQuery(selectQuery, null);
    System.out.println("The cursor had this many rows: " + cursor.getCount());

    if (cursor != null && cursor.getCount() != 0) {
        System.out.println("Putting all group names into arraylist");
        cursor.moveToFirst();
        int i = 0;
        while(!cursor.isAfterLast()) {
            System.out.println("hi" + i);
            System.out.println(cursor.getString(i));
            groupNames.add(cursor.getString(i));
            cursor.moveToNext();
            i++;
        }
    }
    System.out.println(groupNames);
    return groupNames;
}

Aucun commentaire:

Enregistrer un commentaire