GreenDao choose one column?

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

SELECT NAME FROM PERSON

How can I do this with GreenDao?

+3
source share
2 answers

Well, GreenDao provides access to the base database if you want to execute raw queries (DaoSession.getDatabase), which, in your opinion, will be more efficient in this case than the greenDao alternative, which will include getting all faces and repeating the results to retrieve the name (easily done with personDao.loadAll ()). The idea of ​​using the ORM library should be to use Person objects and access the name attribute on it. e.g. person.getName ().

0
source
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 reward, let me know that you want something else?

0
source

All Articles