有人知道如何在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);
}
}
greendao已经配备了用于完成此任务的内置方法。在您的情况下:
List<AppTimeUsage> items = appTimeUsageDao.loadAll();
这将从APP_TIME_USAGE
选择所有记录,然后返回包含实体的List<AppTimeUsage>
。