mercredi 13 juillet 2016

How to do a select all using GreenDAO?

Does anyone know how to do a simple select * from table in greenDAO and place it into an entity? I have done some research on this and I am unable to get any simple example. This is what I have so far:

public void storeAppTimeUsageData(AppTimeUsage stats) {
    List<AppTimeUsage> items = new ArrayList<>();
    //appTimeUsageDao = DeviceInsightApp.getSession(this, true).getAppTimeUsageDao();
    try {
        // master
        appTimeUsageDao.insertOrReplace(stats);
    //} catch (IOException e) {
    } catch (Exception e) {
        Log.e("Error", "Some exception occurred", e);
        Log.e("APP_TAG", "STACKTRACE");
        Log.e("APP_TAG", Log.getStackTraceString(e));
    }
    String sql = "SELECT * FROM APP_TIME_USAGE ";
    Cursor c = appTimeUsageDao.getDatabase().rawQuery(sql, null);
    int offset = 0;
    int d ;
    int cd ;
    String e = "";
    while (c.moveToNext()) {
        AppTimeUsage atu AppTimeUsage(
            c.getLong(0);
            //long b =   c.getInt(0);
            d = c.getInt(2);
            e = c.getString(3);
            break;
        );
        items.add(atu);
    }
} 

Aucun commentaire:

Enregistrer un commentaire