public ArrayList<Word> getWords() { ArrayList<Word> wordsList = new ArrayList<Word>(); String selectQuery = "SELECT * FROM " + TABLE_WORDS; SQLiteDatabase db = this.getWritableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); if (cursor.moveToFirst()) { do { Word word = new Word(); word.setId(cursor.getInt(0)); word.setWord(cursor.getString(1)); word.setTranslation(cursor.getString(2)); word.setDateCreated(cursor.getString(3)); word.setDateModified(cursor.getString(4)); word.setWordLanguage(cursor.getString(5)); word.setTranslationLanguage(cursor.getString(6)); wordsList.add(word); } while (cursor.moveToNext()); } cursor.close(); db.close(); return wordsList; }
public Word getWord(int wordId) { Word word = new Word(); String selectQuery = "SELECT * FROM " + TABLE_WORDS + " WHERE " + TABLE_WORDS_KEY_ID + "=" + wordId; SQLiteDatabase db = this.getWritableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); if (cursor.moveToFirst()) { word.setId(cursor.getInt(0)); word.setWord(cursor.getString(1)); word.setTranslation(cursor.getString(2)); word.setDateCreated(cursor.getString(3)); word.setDateModified(cursor.getString(4)); word.setWordLanguage(cursor.getString(5)); word.setTranslationLanguage(cursor.getString(6)); } cursor.close(); db.close(); return word; }