我正在使用 QueryBuilder 构建内部 SQL,稍后在原始 SQL 中使用该内部 SQL,以避免手动转义无效字符。
SelectArg friendsIN = new SelectArg(friendsUsernames);
QueryBuilder<MyObject, Integer> qb = myObjectDao.queryBuilder();
qb.selectRaw("username", "MAX(time) AS latestTime").groupBy("username").where()
.in("username", friendsIN);
String innerSelect = pq.getStatement();
friendsUsernames
定义为ArrayList<String>
。
然后我使用innerSelect
来构建外部选择:
String select = "SELECT w.id FROM (" + innerSelect +") AS x INNER JOIN myObject AS w on w.username = x.username AND w.time = x.latestTime";
GenericRawResults<String[]> results = myObjectDao.queryRaw(select);
但是,正如预期的那样,innerString
当'?'
我打电话时queryRaw
,myObjectDao
我没有得到任何结果。我试图将friendsUsername 作为数组提供给queryRaw:
GenericRawResults<String[]> results =
myObjectrDao.queryRaw(select,
friendsUsernames.toArray(new String[friendsUsernames.size()]));
但我收到以下错误:
android.database.sqlite.SQLiteBindOrColumnIndexOutOfRangeException:
bind or column index out of range: handle 0x17a22e8
有关如何使用 OrmLite 完成此类查询的任何建议?