简体   繁体   中英

Check if column string in database is a substring of a query in sqlite

the current Sqlite syntax can check if a query is a substring of a column string. and I can do a hack to add a % behind the ? described in https://stackoverflow.com/a/5752671/908821

final String whereClause = DbHelper.COLUMN_URL + " LIKE ? " ;  

is there a syntax where i can do the opposite? I want to check if the column string is a substring of a query.

The following code does not seem to work.

final String whereClause = "? LIKE "  +  DbHelper.COLUMN_URL ;  

The following are the rest of my codes:

String[] whereArg = {url};

ContentValues values = new ContentValues();
values.put(DbHelper.COLUMN_LAST_URL, lastUrl);

database.updateWithOnConflict(DbHelper.TABLE_BOOKMARK,
                values,
                whereClause,
                whereArg,
                SQLiteDatabase.CONFLICT_IGNORE);

I am trying to update "LastUrl" column if the base url is a subString of a query.

some examples that i like to catch

Base Url (in database)         Query
-----------------------------------------------------------------
http://example.com/path        http://example.com/path/path2
http://example.com/path?id=0   http://example.com/path?id=0&x=xx 

The LIKE operator checks whether the value on the left matches the pattern on the right. So just put the value on the left, and the pattern on the right. If the pattern needs a % that is not in the database, you have to append it:

SELECT ... WHERE ? LIKE LastUrl || '%' ...

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