gpt4 book ai didi

android - ORMLite 使用谓词选择一些列

转载 作者:行者123 更新时间:2023-11-29 14:18:31 25 4
gpt4 key购买 nike

我有包含某些字段的 ORMLite 数据库。我想从我从 webservice 获得的 id == id 表中选择标题。我喜欢这样:

 try {
Dao<ProcessStatus,Integer> dao = db.getStatusDao();
Log.i("status",dao.queryForAll().toString());
QueryBuilder<ProcessStatus,Integer> query = dao.queryBuilder();
Where where = query.where();
String a = null;
for(Order r:LoginActivity.orders) {
//LoginActivity.orders - array of my objects which I get from webservice
Log.i("database",query.selectRaw("select title from process_status").
where().rawComparison(ProcessStatus.STATUS_ID, "=",
r.getProcess_status().getProccessStatusId()).toString());
}
Log.i("sr",a);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

我这样试过,但我只得到了我的 id 集,没有标题。我试过这样:

Log.i("database", query.selectColumns(ProcessStatus.STATUS_TITLE).where().
eq(ProcessStatus.STATUS_ID, r.getProcess_status().getProccessStatusId())
.toString());

但我得到了相同的结果。我应该如何从数据库中获取数据?

最佳答案

要从表中选择特定字段,您可以这样做:

String result = "";
try {
GenericRawResults<String[]> rawResults = yourDAO.queryRaw("select " +
ProcessStatus.STATUS_TITLE +" from YourTable where "+
ProcessStatus.STATUS_ID + " = " +
r.getProcess_status().getProccessStatusId());
List<String[]> results = rawResults.getResults();
// This will select the first result (the first and maybe only row returned)
String[] resultArray = results.get(0);
//This will select the first field in the result which should be the ID
result = resultArray[0];
} catch (Exception e) {
e.printStackTrace();
}

希望这对您有所帮助。

关于android - ORMLite 使用谓词选择一些列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11866304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com