查询因多个条件而失败
Query fails with multiple conditions
我有一个数据库,我已经实现了一个 searchView 来搜索它的数据
使用此查询:
选择:
//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 ?";
table:
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
);
}
删除所有的赞,效果很好,
应该注意的是,如果我使用不同的列搜索第一个查询找不到的行,它会起作用并返回行
还需要注意的是,行中的数据是以阿拉伯语存储的
所以有什么帮助吗?谢谢
编辑
例如:
在第一个状态下,当我搜索第一行中显示的“رئيس مولس الإدار⑩”时,使用所有喜欢的查询:
(第一张图)
按名称搜索只会得到相似的行:
(第二张图片)
但是当我按 phone 号码搜索时,它找到了它:
(图片编号三)
即使我用阿拉伯语写 phone 数字:
(图片编号四)
这是图片(由于声誉低下造成的限制,将它们放在一张 link 中)
现在,当我更改查询并删除所有喜欢的内容时,它只会找到它:
还应注意,问题不仅限于此行,其他行也有同样的行为
解决了,
问题是由于查询时的group by参数引起的,
我不知道为什么它会导致问题,但删除它就解决了。
我有一个数据库,我已经实现了一个 searchView 来搜索它的数据 使用此查询:
选择:
//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 ?";
table:
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
);
}
删除所有的赞,效果很好,
应该注意的是,如果我使用不同的列搜索第一个查询找不到的行,它会起作用并返回行
还需要注意的是,行中的数据是以阿拉伯语存储的
所以有什么帮助吗?谢谢
编辑
例如: 在第一个状态下,当我搜索第一行中显示的“رئيس مولس الإدار⑩”时,使用所有喜欢的查询:
(第一张图)
按名称搜索只会得到相似的行:
(第二张图片)
但是当我按 phone 号码搜索时,它找到了它:
(图片编号三)
即使我用阿拉伯语写 phone 数字:
(图片编号四)
这是图片(由于声誉低下造成的限制,将它们放在一张 link 中)
现在,当我更改查询并删除所有喜欢的内容时,它只会找到它:
还应注意,问题不仅限于此行,其他行也有同样的行为
解决了,
问题是由于查询时的group by参数引起的, 我不知道为什么它会导致问题,但删除它就解决了。