0
有了这个方法返回的查询过滤转换SQLite的查询境界查询的Android
public List<table_People> getPeople(String filter)
{
List<table_People> items = new ArrayList<>();
filter = filter.trim();
filter = filter.toUpperCase();
String selectQuery = "SELECT * FROM People " +
"WHERE (UPPER(LastName || FirstName) LIKE '%" + filter + "%') " +
"OR (UPPER(FirstName || LastName) LIKE '%" + filter + "%') ";
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
table_People item = new table_People(
cursor.getInt((cursor.getColumnIndex("ID"))),
cursor.getString((cursor.getColumnIndex("FirstName"))),
cursor.getString((cursor.getColumnIndex("LastName")))
);
items.add(item);
} while (cursor.moveToNext());
}
return items;
}
我如何转换这领域查询对象的列表?
最重要的是,我有关于WHERE CLAUSE的问题。
我需要这个条款,因为我需要通过FirstName + LastName或LastName + FirstName进行搜索。
例如 John Smith
Smith John
返回总是记录。