public static List<Note> FindNotesByFieldName(SQLiteDatabase database, String fieldName) { if (fieldName != null) { // Find current field List<Note> notes = new ArrayList<Note>(); String where = TableNotes.COL_FIELD_NAME + " = '" + fieldName + "' AND " + TableFields.COL_DELETED + " = 0"; ; Cursor cursor = database.query(TableNotes.TABLE_NAME, TableNotes.COLUMNS, where, null, null, null, null); while (cursor.moveToNext()) { notes.add(Note.cursorToNote(cursor)); } cursor.close(); return notes; } else { return null; } }
public static Note cursorToNote(Cursor cursor) { if (cursor != null) { Note note = new Note(); note.setId(cursor.getInt(cursor.getColumnIndex(TableNotes.COL_ID))); note.setRemote_id(cursor.getString(cursor.getColumnIndex(TableNotes.COL_REMOTE_ID))); note.setHasChanged(cursor.getInt(cursor.getColumnIndex(TableNotes.COL_HAS_CHANGED))); note.setDateChanged(cursor.getString(cursor.getColumnIndex(TableNotes.COL_DATE_CHANGED))); note.setFieldName(cursor.getString(cursor.getColumnIndex(TableNotes.COL_FIELD_NAME))); note.setComment(cursor.getString(cursor.getColumnIndex(TableNotes.COL_COMMENT))); note.setStrPolygons(cursor.getString(cursor.getColumnIndex(TableNotes.COL_POLYGONS))); // TODO lines, points note.setColor(cursor.getInt(cursor.getColumnIndex(TableNotes.COL_COLOR))); note.setVisible(cursor.getInt(cursor.getColumnIndex(TableNotes.COL_VISIBLE))); note.setDeleted(cursor.getInt(cursor.getColumnIndex(TableNotes.COL_DELETED))); return note; } else { return null; } }