簡體   English   中英

檢查數據庫中的列字符串是否是sqlite中查詢的子字符串

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

當前的Sqlite語法可以檢查查詢是否是列字符串的子字符串。 我可以做一個黑客,以在%后面添加%。 https://stackoverflow.com/a/5752671/908821中描述

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

有沒有我可以做相反的語法? 我想檢查列字符串是否是查詢的子字符串。

以下代碼似乎無效。

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

以下是我的其余代碼:

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);

如果基本網址是查詢的子字符串,我將嘗試更新“ LastUrl”列。

我喜歡捕捉的一些例子

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 

LIKE運算符檢查左側的值是否與右側的模式匹配。 因此,只需將值放在左側,將模式放在右側。 如果模式需要數據庫中沒有的% ,則必須附加它:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM