2014-02-27 39 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