ORMLite 为列设置别名而不是 table
ORMLite set an alias for column instead of table
如何在选择列时添加别名 (AS)?我想实现类似的目标:
SELECT `foo` AS `bar` FROM `xyz` WHERE `abc` = '123' ORDER BY `bar`
我尝试在 selectColumns 之后使用 setAlias 方法,但它会将别名设置为 table,这我认为是有意的,因为它在 docs.
中被提及
这里是一个创建别名的例子check this
String qry = "SELECT `foo` AS `bar` FROM `xyz` WHERE `abc` = '123' ORDER BY `bar`";
GenericRawResults<Foo> rawResults =
orderDao.queryRaw(qry, new RawRowMapper<Foo>() {
public Foo mapRow(String[] columnNames, String[] resultColumns) {
// assuming 0th field is the foo
return new Foo(resultColumns[0]));
}
});
// page through the results
for (Foo foo : rawResults) {
Log.e("result data ", "::" + foo.name");
}
rawResults.close();
你也可以通过this doc
如何在选择列时添加别名 (AS)?我想实现类似的目标:
SELECT `foo` AS `bar` FROM `xyz` WHERE `abc` = '123' ORDER BY `bar`
我尝试在 selectColumns 之后使用 setAlias 方法,但它会将别名设置为 table,这我认为是有意的,因为它在 docs.
中被提及这里是一个创建别名的例子check this
String qry = "SELECT `foo` AS `bar` FROM `xyz` WHERE `abc` = '123' ORDER BY `bar`";
GenericRawResults<Foo> rawResults =
orderDao.queryRaw(qry, new RawRowMapper<Foo>() {
public Foo mapRow(String[] columnNames, String[] resultColumns) {
// assuming 0th field is the foo
return new Foo(resultColumns[0]));
}
});
// page through the results
for (Foo foo : rawResults) {
Log.e("result data ", "::" + foo.name");
}
rawResults.close();
你也可以通过this doc