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 void deleteWord(Word word) { if (word == null) { return; } SQLiteDatabase db = this.getWritableDatabase(); db.delete(TABLE_WORDS, TABLE_WORDS_KEY_ID + " = " + word.getId(), null); db.close(); }
public void updateWord(Word word) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(TABLE_WORDS_KEY_WORD, word.getWord()); values.put(TABLE_WORDS_KEY_TRANSLATION, word.getTranslation()); values.put(TABLE_WORDS_KEY_DATE_ADDED, word.getDateCreated()); values.put(TABLE_WORDS_KEY_DATE_MODIFIED, word.getDateModified()); values.put(TABLE_WORDS_KEY_WORD_LANGUAGE, word.getWordLanguage()); values.put(TABLE_WORDS_KEY_TRANSLATION_LANGUAGE, word.getTranslationLanguage()); db.update(TABLE_WORDS, values, TABLE_WORDS_KEY_ID + "=" + word.getId(), null); db.close(); }
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; }