문제

I need to return only a single column using GreenDao. This is the SQL query:

SELECT NAME FROM PERSON

How can I do it using GreenDao?

올바른 솔루션이 없습니다

다른 팁

Well greenDao does provide access to the underlying database if you want to perform raw queries (DaoSession.getDatabase) - which you may feel in this case would be more efficient than the greenDao alternative - which would involve getting all Persons and iterating over the results to extract the name (easily done with personDao.loadAll()). The idea in using an ORM library would be to use Person objects, and access the name attribute on it. e.g. person.getName().

public static ArrayList<ArrayList<String>> rawQuery(final String query) {
        SQLiteDatabase db = DBHelper.getDaoSession().getDatabase();
        Cursor cursor = db.rawQuery(query, null);
        retList = new ArrayList<ArrayList<String>>();
        ArrayList<String> list = new ArrayList<String>();
        if (cursor.moveToFirst()) {
            do {
                list = new ArrayList<String>();
                for (int i = 0; i < cursor.getColumnCount(); i++) {
                    list.add(cursor.getString(i));
                }
                retList.add(list);
            } while (cursor.moveToNext());
        }
        if (cursor != null && !cursor.isClosed()) {
            cursor.close();
        }

        return retList;

    }

Use this kudos let me know you want something more ?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top