public List<Skill> getEmployeeSkills(int employeeId) { open(); Cursor c = myDatabase.rawQuery( "SELECT * FROM " + EMPLOYEE_SKILL_TABLE + " LEFT JOIN " + SKILL_TABLE + " USING (" + SKILL_ID + ") WHERE " + EMPLOYEE_ID + " = ? ORDER BY " + SKILL_NAME + " ASC", new String[] {Integer.toString(employeeId)}); List<Skill> skills = new ArrayList<Skill>(); int rId = c.getColumnIndex(SKILL_ID); int rName = c.getColumnIndex(SKILL_NAME); int rSkillGroup = c.getColumnIndex(SKILL_GROUP_ID); if (c != null) { for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { Skill s = new Skill(); s.setId(c.getInt(rId)); s.setName(c.getString(rName)); s.setSkillGroupId(c.getInt(rSkillGroup)); skills.add(s); } } close(); return skills; }
public void removeEmployeeSkill(Employee employee, Skill skill) { open(); ContentValues cv = new ContentValues(); cv.put(EMPLOYEE_ID, employee.getId()); cv.put(SKILL_ID, skill.getId()); myDatabase.delete( EMPLOYEE_SKILL_TABLE, EMPLOYEE_ID + " =? AND " + SKILL_ID + " =?", new String[] {Integer.toString(employee.getId()), Integer.toString(skill.getId())}); close(); }
public void addEmployeeSkill(Employee employee, Skill skill) { open(); ContentValues cv = new ContentValues(); cv.put(EMPLOYEE_ID, employee.getId()); cv.put(SKILL_ID, skill.getId()); myDatabase.insert(EMPLOYEE_SKILL_TABLE, null, cv); close(); }