public void insertUpdateNote(NotesData data) { Cursor cursor = baseDataSource .getDatabase() .query("notes_data", null, "id = ?", new String[] {data.getId()}, null, null, null); if (!cursor.moveToFirst()) { ContentValues row = new ContentValues(); row.put("title", data.getTitle()); row.put("label", data.getLabel()); row.put("note", data.getNote()); row.put("date", data.getDate()); row.put("soft_delete", "1"); baseDataSource.getDatabase().insert("notes_data", null, row); } else { ContentValues row = new ContentValues(); row.put("id", data.getId()); row.put("title", data.getTitle()); row.put("label", data.getLabel()); row.put("note", data.getNote()); row.put("date", data.getDate()); row.put("soft_delete", "1"); baseDataSource.getDatabase().update("notes_data", row, "id=?", new String[] {data.getId()}); } cursor.close(); }