【问题标题】:How to do a select all using GreenDAO?如何使用 GreenDAO 进行全选?
【发布时间】:2016-10-28 18:33:43
【问题描述】:

有谁知道如何在 greenDAO 中做一个简单的select * from table 并将其放入一个实体中?我对此进行了一些研究,但无法获得任何简单的示例。这是我到目前为止所拥有的:

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);
    }
} 

【问题讨论】:

    标签: java sqlite android-studio orm greendao


    【解决方案1】:

    GreenDAO 已经自带了一个内置的方法来完成这个任务。在你的情况下:

    List<AppTimeUsage> items = appTimeUsageDao.loadAll();
    

    这将从APP_TIME_USAGE 中选择所有记录并返回包含实体的List&lt;AppTimeUsage&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多