2014-02-27 40 views
1

選擇的是正常工作:撇號SQLite中選擇

selection: title LIKE '% Z %' OR title LIKE 'Z %' OR title LIKE '% Z' 

我的應用程序崩潰,如果分貝選擇containes撇號:

登錄:

android.database.sqlite.SQLiteException: unrecognized token: "'% ''": , 
while compiling: SELECT _id, title FROM table_name WHERE title LIKE '% ' %' 
OR title LIKE '' %' OR title LIKE '% '' 

OR:

android.database.sqlite.SQLiteException: near "ZCUU": syntax error: , 
while compiling: SELECT _id, title FROM laws WHERE title LIKE '% ZCUU' %' 
OR title LIKE 'ZCUU' %' OR title LIKE '% ZCUU'' 

誰知道如何o插入撇號以正確搜索選擇?謝謝!

回答

2

插入你的字符串雙撇號:「」

即:

SELECT _id, title FROM laws WHERE title LIKE '% ZCUU'' %' OR title LIKE 'ZCUU'' %' OR title LIKE '% ZCUU''' 
3

請求的數據庫的方式導致SQL注入風險的內容。順便說一句,你應該使用query methods來爲你管理撇號。

+0

哦,這很有用。謝謝! – Sinigami