简体   繁体   中英

Android Sqlite search like %

I tried to search a record in Android SQLite whether the record exists in any other column "ITEM_NAME" or column "ITEM_CODE".

It never works.

mCursor = mDb.query(true, ITEM_TABLE_NAME, new String[] {ITEM_ID, ITEM_CODE,
                ITEM_NAME, ITEM_CPRICE, ITEM_UPRICE}, 
                ITEM_NAME + " like '%" + inputText + "%'"
                + "OR" + ITEM_NAME + " like '%" + inputText + "%'" , null,
                null, null, null, null);

But searching in one column works

mCursor = mDb.query(true, ITEM_TABLE_NAME, new String[] {ITEM_ID, ITEM_CODE,
                ITEM_NAME, ITEM_CPRICE, ITEM_UPRICE}, 
                ITEM_NAME + " like '%" + inputText + "%'"
                null, null, null, null);

Your query looks correct except the

   "OR"

Its should be

  " OR "

Make it like-

       mCursor = mDb.query(true, ITEM_TABLE_NAME, new String[] {ITEM_ID, ITEM_CODE,
            ITEM_NAME, ITEM_CPRICE, ITEM_UPRICE}, 
            ITEM_NAME + " like '%" + inputText + "%'"
            + " OR " + ITEM_NAME + " like '%" + inputText + "%'" , null,
            null, null, null, null);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM