public boolean create(UserModel user) { boolean createSuccessful = false; if (!checkIfExists(user)) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(fieldObjectFullName, user.getFullName()); values.put(fieldObjectPhone, user.getPhone()); values.put(fieldTotalQuestions, user.getTotalQuestions()); values.put(fieldNumberRightAnswers, user.getNumsRightAnswers()); values.put(fieldNumberCompletedQuestion, user.getTotalCompletedQuestions()); values.put(fieldIsCompleted, user.getIsCompleted()); createSuccessful = db.insert(tableName, null, values) > 0; if (createSuccessful) { Log.v(TAG, user.getFullName() + " created."); } db.close(); } return createSuccessful; }
public Integer updateUserInfo(UserModel user, Integer userId) { SQLiteDatabase db = this.getWritableDatabase(); Integer updateOk; Integer returnStatus; ContentValues values = new ContentValues(); values.put(fieldTotalQuestions, user.getTotalQuestions()); values.put(fieldNumberRightAnswers, user.getNumsRightAnswers()); values.put(fieldNumberCompletedQuestion, user.getTotalCompletedQuestions()); values.put(fieldIsCompleted, user.getIsCompleted()); updateOk = db.update( tableName, values, String.format("%s = ?", "id"), new String[] {userId.toString()}); if (updateOk > 0) { returnStatus = AppConstant.UPDATE_DATA_SUCCESS; } else { returnStatus = AppConstant.UPDATE_DATA_FAILED; } return returnStatus; }