gpt4 book ai didi

android - ORMLite 为列而不是表设置别名

转载 作者:行者123 更新时间:2023-11-30 00:22:18 25 4
gpt4 key购买 nike

如何在选择列时添加别名(AS)?我想实现这样的目标:

SELECT `foo` AS `bar` FROM `xyz` WHERE `abc` = '123' ORDER BY `bar`

我已经尝试在我的 selectColumns 之后使用 setAlias 方法,但它将别名设置为表,我认为这是有意为之的,因为它在 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

关于android - ORMLite 为列而不是表设置别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46049393/

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