Android GreenDao rawQuery 之 like 浓瞪、 or懈玻、 = 拼接查詢條件

private void queryLocomotiveList() {

? ? ? ? List<Locomotive> locomotiveList = new ArrayList<>();

? ? ? ? String locomotiveModeName = tvEngineMode.getText().toString().trim();

? ? ? ? String locomotive = tvEngineNo.getText().toString().trim();

? ? ? ? try {

? ? ? ? ? ? //請求參數(shù)

? ? ? ? ? ? ArrayList<String> strParamLt = new ArrayList<String>();

? ? ? ? ? ? String queryString =

? ? ? ? ? ? ? ? ? ? "SELECT DISTINCT *? FROM " + LocomotiveDao.TABLENAME + " where 1==1 ";

? ? ? ? ? ? if (!TextUtils.isEmpty(locomotiveModeName)) {

? ? ? ? ? ? ? ? queryString = queryString + " and " + LocomotiveDao.Properties.TrainModelName.columnName + " =? ?";

? ? ? ? ? ? ? ? strParamLt.add(locomotiveModeName);

? ? ? ? ? ? }

? ? ? ? ? ? if (!TextUtils.isEmpty(locomotive)) {

? ? ? ? ? ? ? ? queryString = queryString + " and " + LocomotiveDao.Properties.TrainNo.columnName + " like '%" + locomotive + "%' ";

? ? ? ? ? ? }

? ? ? ? ? ? if (!TextUtils.isEmpty(healthy) || !TextUtils.isEmpty(attention) || !TextUtils.isEmpty(repair)){

? ? ? ? ? ? ? ? String healthyTypeStr = " and " + "(";

? ? ? ? ? ? ? ? if (!TextUtils.isEmpty(healthy)) {

? ? ? ? ? ? ? ? ? ? healthyTypeStr += LocomotiveDao.Properties.HealthAnalysisLevel.columnName + " =? ?" + " or ";

? ? ? ? ? ? ? ? ? ? strParamLt.add(healthy);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? if (!TextUtils.isEmpty(attention)) {

? ? ? ? ? ? ? ? ? ? healthyTypeStr += LocomotiveDao.Properties.HealthAnalysisLevel.columnName + " =? ?" + " or ";

? ? ? ? ? ? ? ? ? ? strParamLt.add(attention);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? if (!TextUtils.isEmpty(repair)) {

? ? ? ? ? ? ? ? ? ? healthyTypeStr += LocomotiveDao.Properties.HealthAnalysisLevel.columnName + " =? ?";

? ? ? ? ? ? ? ? ? ? strParamLt.add(repair);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? if (healthyTypeStr.endsWith("or ")){

? ? ? ? ? ? ? ? ? ? healthyTypeStr = healthyTypeStr.substring(0,healthyTypeStr.length() - 3);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? healthyTypeStr += ")";

? ? ? ? ? ? ? ? queryString = queryString + healthyTypeStr;

? ? ? ? ? ? }

? ? ? ? ? ? Log.e("queryString",queryString);

? ? ? ? ? ? Object[] objs = strParamLt.toArray();

? ? ? ? ? ? String[] strs = new String[objs.length];

? ? ? ? ? ? for (int i = 0; i < objs.length; i++) {

? ? ? ? ? ? ? ? strs[i] = objs[i].toString();

? ? ? ? ? ? }

? ? ? ? ? ? Log.e("strs",new Gson().toJson(strs));

? ? ? ? ? ? Cursor cursor = DaoManager.getInstance().getDaoSession().getDatabase().rawQuery(queryString, strs);

? ? ? ? ? ? int trainNoIndex = cursor.getColumnIndex(LocomotiveDao.Properties.TrainNo.columnName);

? ? ? ? ? ? int trainModeNameIndex = cursor.getColumnIndex(LocomotiveDao.Properties.TrainModelName.columnName);

? ? ? ? ? ? int healthIndex = cursor.getColumnIndex(LocomotiveDao.Properties.HealthAnalysisLevel.columnName);

? ? ? ? ? ? while (cursor.moveToNext()) {

? ? ? ? ? ? ? ? Locomotive bean = new Locomotive();

? ? ? ? ? ? ? ? bean.setTrainNo(cursor.getString(trainNoIndex));

? ? ? ? ? ? ? ? bean.setTrainModelName(cursor.getString(trainModeNameIndex));

? ? ? ? ? ? ? ? bean.setHealthAnalysisLevel(cursor.getString(healthIndex));

? ? ? ? ? ? ? ? locomotiveList.add(bean);

? ? ? ? ? ? }

? ? ? ? ? ? Log.e("locomotiveList",new Gson().toJson(locomotiveList));

? ? ? ? } catch (Exception e) {

? ? ? ? ? ? e.printStackTrace();

? ? ? ? }

? ? ? ? mAdapter.setNewData(locomotiveList);

? ? }

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市乾颁,隨后出現(xiàn)的幾起案子涂乌,更是在濱河造成了極大的恐慌,老刑警劉巖钮孵,帶你破解...
    沈念sama閱讀 219,270評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件骂倘,死亡現(xiàn)場離奇詭異,居然都是意外死亡巴席,警方通過查閱死者的電腦和手機历涝,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,489評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人荧库,你說我怎么就攤上這事堰塌。” “怎么了分衫?”我有些...
    開封第一講書人閱讀 165,630評論 0 356
  • 文/不壞的土叔 我叫張陵场刑,是天一觀的道長。 經(jīng)常有香客問我蚪战,道長牵现,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,906評論 1 295
  • 正文 為了忘掉前任邀桑,我火速辦了婚禮瞎疼,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘壁畸。我一直安慰自己贼急,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,928評論 6 392
  • 文/花漫 我一把揭開白布捏萍。 她就那樣靜靜地躺著太抓,像睡著了一般。 火紅的嫁衣襯著肌膚如雪令杈。 梳的紋絲不亂的頭發(fā)上走敌,一...
    開封第一講書人閱讀 51,718評論 1 305
  • 那天,我揣著相機與錄音这揣,去河邊找鬼悔常。 笑死,一個胖子當(dāng)著我的面吹牛给赞,可吹牛的內(nèi)容都是我干的机打。 我是一名探鬼主播,決...
    沈念sama閱讀 40,442評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼片迅,長吁一口氣:“原來是場噩夢啊……” “哼残邀!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起柑蛇,我...
    開封第一講書人閱讀 39,345評論 0 276
  • 序言:老撾萬榮一對情侶失蹤芥挣,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后耻台,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體空免,經(jīng)...
    沈念sama閱讀 45,802評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,984評論 3 337
  • 正文 我和宋清朗相戀三年盆耽,在試婚紗的時候發(fā)現(xiàn)自己被綠了蹋砚。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片扼菠。...
    茶點故事閱讀 40,117評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖坝咐,靈堂內(nèi)的尸體忽然破棺而出循榆,到底是詐尸還是另有隱情,我是刑警寧澤墨坚,帶...
    沈念sama閱讀 35,810評論 5 346
  • 正文 年R本政府宣布秧饮,位于F島的核電站,受9級特大地震影響泽篮,放射性物質(zhì)發(fā)生泄漏盗尸。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,462評論 3 331
  • 文/蒙蒙 一帽撑、第九天 我趴在偏房一處隱蔽的房頂上張望振劳。 院中可真熱鬧,春花似錦油狂、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,011評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至蒸苇,卻和暖如春磷蛹,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背溪烤。 一陣腳步聲響...
    開封第一講書人閱讀 33,139評論 1 272
  • 我被黑心中介騙來泰國打工味咳, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人檬嘀。 一個月前我還...
    沈念sama閱讀 48,377評論 3 373
  • 正文 我出身青樓槽驶,卻偏偏與公主長得像,于是被迫代替她去往敵國和親鸳兽。 傳聞我的和親對象是個殘疾皇子掂铐,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,060評論 2 355

推薦閱讀更多精彩內(nèi)容