private List<EventTarget> getEventTargets(EventModel event) throws SQLException { List<EventTarget> targets = new ArrayList(); EventTarget target = null; String sql = "SELECT description, mandatory, target_origin_id " + " FROM event_targets_origins, targets_origins \n" + " WHERE event_id = ? AND target_origin_id = targets_origins.id;"; Cursor cursor = this.database.rawQuery(sql, new String[] {String.valueOf(event.getId())}); while (cursor.moveToNext()) { target = new EventTarget(); target.setTarget( new TargetOrigin( cursor.getInt(cursor.getColumnIndex("target_origin_id")), cursor.getString(cursor.getColumnIndex("description")))); target.setMandatory(cursor.getInt(cursor.getColumnIndex("mandatory")) > 0); target.setEvent(event); targets.add(target); } if (!cursor.isClosed()) { cursor.close(); } return targets; }
public void insertTargets(EventModel event) throws SQLException { // String sql = "INSERT INTO event_targets_origins (event_id,target_origin_id,mandatory) " // + " VALUES (?,?,?);"; for (EventTarget target : event.getTargets()) { ContentValues values = new ContentValues(); values.put("event_id", event.getId()); values.put("target_origin_id", target.getTarget().getId()); values.put("mandatory", target.isMandatory()); // executar this.database.insertOrThrow("event_targets_origins", null, values); if (DeveloperSettings.SHOW_DAO_SQL) { Log.d( "SQL_DEBUG", "INSERT INTO event_targets_origins (event_id,target_origin_id,mandatory) " + " VALUES (" + event.getId() + "," + target.getTarget().getId() + "," + target.isMandatory() + ");"); } } }