/** * Update the current Pack in the database. * * @return the number of rows affected */ public int save() { DatabaseHelper dbh = DatabaseHelper.getInstance(MyApplication.getContext()); ContentValues contentValues = new ContentValues(); contentValues.put("id_language", this.language.getId()); contentValues.put("indice", this.indice); contentValues.put("timestamp_pack", this.timestampPack); contentValues.put("timestamp_last_answer", this.timestampLastAnswer); return dbh.getWritableDatabase() .update("pack", contentValues, "id = ?", new String[] {String.valueOf(this.id)}); }
/** * Find the Pack whose Language id is "idLang" and indice is "indice". * * @param idLang the Language id * @param indice the indice * @return the Pack whose Language id is "idLang" and indice is "indice" */ public static Pack findByIdLangAndIndice(int idLang, int indice) { DatabaseHelper dbh = DatabaseHelper.getInstance(MyApplication.getContext()); String query; Cursor cursor; Pack retour; query = "SELECT " + "id, " // 0 + "timestamp_pack, " // 1 + "timestamp_last_answer " // 2 + "FROM pack " + "WHERE id_language = " + idLang + " " + "AND indice = " + indice; cursor = dbh.getReadableDatabase().rawQuery(query, null); if (cursor.getCount() == 0) { retour = null; } else { cursor.moveToFirst(); retour = new Pack( cursor.getInt(0), Language.find(idLang), indice, cursor.getLong(1), cursor.getLong(2)); } cursor.close(); return retour; }