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
返回總是記錄。