80,471
社区成员




private List<MediaItem> getList(){
From<MediaItem> from = SQLite.select().from(MediaItem.class);
int length = mCurrDeviceArray.length;
if (length == 0){
return from.queryList();
}
Where<MediaItem> where = from.where(MediaItem_Table.path.like(mCurrDeviceArray[0] + "%"));
for (int i = 1; i < length; i++) {
where = where.or(MediaItem_Table.path.like(mCurrDeviceArray[i] + "%"));
}
return where.queryList();
}
[/quote]
我试了下你的方法可以实现需求。上次我试了一下,发现下面这个方法也可以达到需求。
public SQLOperator getCurrPathOperator() {
if(mCurrDeviceArray.length>0){
OperatorGroup sqlOperator = OperatorGroup.clause();
for(int i=0;i<mCurrDeviceArray.length;i++){
sqlOperator = sqlOperator.or(MediaItem_Table.path.like(mCurrDeviceArray[i] + "%"));
}
return sqlOperator;
}
return null;
}
然后查询的时候拼接起来
mList = SQLite.select().from(MediaItem.class).where(getCurrPathOperator()).queryList();
private List<MediaItem> getList(){
From<MediaItem> from = SQLite.select().from(MediaItem.class);
int length = mCurrDeviceArray.length;
if (length == 0){
return from.queryList();
}
Where<MediaItem> where = from.where(MediaItem_Table.path.like(mCurrDeviceArray[0] + "%"));
for (int i = 1; i < length; i++) {
where = where.or(MediaItem_Table.path.like(mCurrDeviceArray[i] + "%"));
}
return where.queryList();
}
String[] mCurrDeviceArray;
SQLite.select().from(MediaItem.class).where(MediaItem_Table.path.like( mCurrDeviceArray).queryList();
public Property getCurrPathProperty() {
int length = mCurrDeviceArray.length;
Property ppp;
switch (length) {
case 1:
ppp = PropertyFactory.from(SQLite.select(MediaItem_Table.path).from(MediaItem.class).where(MediaItem_Table.path.like(mCurrDeviceArray[0] + "%")));
break;
case 2:
ppp = PropertyFactory.from(SQLite.select(MediaItem_Table.path).from(MediaItem.class).where(MediaItem_Table.path.like(mCurrDeviceArray[0] + "%")).or(MediaItem_Table.path.like(mCurrDeviceArray[1] + "%")));
break;
case 3:
...;
}
return ppp;
}
mListAdapter.mList = SQLite.select().from(MediaItem.class).where(MediaItem_Table.path.greaterThanOrEq(getCurrPathProperty())).queryList();
String[] mCurrDeviceArray;
SQLite.select().from(MediaItem.class).where(MediaItem_Table.path.like( mCurrDeviceArray).queryList();
SQLite.select().from(MediaItem.class).where(MediaItem_Table.path.like("/storage/8605-11F3" + "%")).queryList();
你的getCurrPathProperty方法本身并不会查询数据而是生成了条件,in需要使用数据才有结果,greaterThanOrEq是>=。
使用greaterThanOrEq生成的语句是
SELECT * FROM `media` WHERE `path`>=(SELECT `path` FROM `media` WHERE `path` LIKE '/storage/8605-11F3%')
因为 / 的ASCII大于 ( 的ASCII所以会返回所以的值。
使用in生成的语句
SELECT * FROM `media` WHERE `path` IN ((SELECT `path` FROM `media` WHERE `path` LIKE '/storage/8605-11F3%'))
因为in中的数据只有一条,所以会返回第一条匹配的。