我查询了我的数据库。
public Cursor getCursorSearch(String id_for_listtsk_today) {
Log.d(Tag, "пытаемся получить курсор для сравнения с гуглом");
String[] columns = null;
String selection = null;
String[] selectionArgs = null;
String groupBy = null;
String having = null;
String orderBy = null;
// SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
// queryBuilder.setTables(TABLE_NAME);
// String[] asColumnsToReturn = new String[] { COLUMN_ID, COLUMN_NAME,
// COLUMN_DATA, COLUMN_STATUS };
// Cursor mCursor = queryBuilder.query(dbSqlite, asColumnsToReturn, null,
// null, null, null, "title ASC");
// Log.d(Tag, "getCursor() получили курсор с базы конец");
DBHelper dbHelper_AL = new DBHelper(this);
final SQLiteDatabase db = dbHelper_AL.getWritableDatabase();
// final SQLiteDatabase db = this.getWritableDatabase();
columns = new String[] { DBHelper.COLUMN_ID, DBHelper.COLUMN_NAME, DBHelper.COLUMN_STATUS, DBHelper.COLUMN_TASK, DBHelper.COLUMN_TIME,DBHelper.COLUMN_ACCAUNT, DBHelper.COLUMN_DATA, DBHelper.COLUMN_SELECTED };
selection = "(name || task ) like + ? and del != ? ";
//id_for_listtsk_today = "о";
selectionArgs = new String[] {"%"+id_for_listtsk_today+"%", Integer.toString(1)};
orderBy = "time_up";
Cursor c = db.query("mytable", columns, selection, selectionArgs, null, null, orderBy);
String[] jbh = MainActivity.logCursor(c);
Log.d(Tag, "getCursor() получили курсор с базы");
return c;
}
}
但是野外任务可能为空。当任务等于null时,我的光标数等于0.如何解决?
答案 0 :(得分:0)
在SQL中,使用COALESCE
选择第一个非null参数。例如:
selection = "(COALESCE(name, '') || COALESCE(task, '')) like ? and del != ? ";
(我还删除了+
附近的like
。)