Android 查询因多个条件而失败
我有一个数据库,我已经实现了一个searchView来搜索它的数据 使用此查询: 选择:Android 查询因多个条件而失败,android,sqlite,sql-like,Android,Sqlite,Sql Like,我有一个数据库,我已经实现了一个searchView来搜索它的数据 使用此查询: 选择: //rooms.name = ? OR rooms.name LIKE ? OR rooms.name LIKE ? OR rooms.name LIKE ? private static final String roomsWithSectorsByNameSelection = DeltaContract.RoomsEntry.TABLE_NAME +
//rooms.name = ? OR rooms.name LIKE ? OR rooms.name LIKE ? OR rooms.name LIKE ?
private static final String roomsWithSectorsByNameSelection =
DeltaContract.RoomsEntry.TABLE_NAME +
"." + DeltaContract.RoomsEntry.COLUMN_NAME + " = ? OR " +
DeltaContract.RoomsEntry.TABLE_NAME +
"." + DeltaContract.RoomsEntry.COLUMN_NAME + " LIKE ? OR " +
DeltaContract.RoomsEntry.TABLE_NAME +
"." + DeltaContract.RoomsEntry.COLUMN_NAME + " LIKE ? OR " +
DeltaContract.RoomsEntry.TABLE_NAME +
"." + DeltaContract.RoomsEntry.COLUMN_NAME + " LIKE ?";
下表:
roomsWithSectorsByNameQueryBuilder.setTables(
DeltaContract.RoomsEntry.TABLE_NAME + " INNER JOIN " +
DeltaContract.SectorsEntry.TABLE_NAME +
" ON " + DeltaContract.RoomsEntry.TABLE_NAME +
"." + DeltaContract.RoomsEntry.COLUMN_SECTOR_ID + " = " +
DeltaContract.SectorsEntry.TABLE_NAME +
"." + DeltaContract.SectorsEntry._ID);
以及查询:
private Cursor getRoomsWithSectorsByName(Uri uri, String[] projection, String sortOrder) {
String name = DeltaContract.RoomsEntry.getNameFromRoomsUri(uri);
return roomsWithSectorsByNameQueryBuilder.query(deltaDbHelper.getReadableDatabase(),
projection,
roomsWithSectorsByNameSelection,
new String[]{name, (name + "%"), ("%" + name + "%"), ("%" + name)},
DeltaContract.SectorsEntry.TABLE_NAME + "." + DeltaContract.SectorsEntry.COLUMN_NAME,
null,
sortOrder
);
}
对于大多数搜索,我都尝试使用它,但对于某些行,即使键入整个单词,它也不起作用
但是
如果我将选择更改为:
//rooms.name = ?
private static final String roomsWithSectorsByNameSelection =
DeltaContract.RoomsEntry.TABLE_NAME +
"." + DeltaContract.RoomsEntry.COLUMN_NAME + " = ?";
以及对此的查询:
private Cursor getRoomsWithSectorsByName(Uri uri, String[] projection, String sortOrder) {
String name = DeltaContract.RoomsEntry.getNameFromRoomsUri(uri);
return roomsWithSectorsByNameQueryBuilder.query(deltaDbHelper.getReadableDatabase(),
projection,
roomsWithSectorsByNameSelection,
new String[]{name},
DeltaContract.SectorsEntry.TABLE_NAME + "." + DeltaContract.SectorsEntry.COLUMN_NAME,
null,
sortOrder
);
}
去掉所有喜欢的,效果很好
应该注意的是,如果我在表中使用不同的列搜索第一个查询未能找到的行,那么它会工作,并返回这些行
还应注意,行中的数据以阿拉伯语存储
有什么帮助吗?多谢各位
编辑
例如:
在使用查询和所有类似项的第一个状态中,当我搜索第一行中显示的“qiئ1610;سمسا㶍㶍㶍㶍㵵㶍㶍”时:
(图一)
按名称搜索它只会得到类似的行:
(图二)
但当我按电话号码搜索时,它会找到它:
(图三)
即使我用阿拉伯语写下电话号码:
(图四)
以下是图片(由于声誉低而受到限制,请将它们放在一个链接中)
现在,当我更改查询并删除所有喜欢的内容时,它只会找到它:
还应注意的是,问题不仅限于这一行,其他行也出现了同样的问题,这些行遵循相同的行为解决了问题
由于查询中的group by参数而出现问题,
我不知道它为什么会导致问题,但删除它就解决了问题。显示一些示例数据。@CL.无法在该站点中执行此操作,因为阿拉伯语rtl对齐混乱。这是用于搜索的联接产生的表