简体   繁体   English

检查数据库中的列字符串是否是sqlite中查询的子字符串

[英]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. 当前的Sqlite语法可以检查查询是否是列字符串的子字符串。 and I can do a hack to add a % behind the ? 我可以做一个黑客,以在%后面添加%。 described in https://stackoverflow.com/a/5752671/908821 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. 如果基本网址是查询的子字符串,我将尝试更新“ LastUrl”列。

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. LIKE运算符检查左侧的值是否与右侧的模式匹配。 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 || '%' ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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