选择正常:
selection: title LIKE '% Z %' OR title LIKE 'Z %' OR title LIKE '% Z'
如果数据库选择包含撇号,我的应用程序崩溃了:
日志:
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''
谁知道如何正确插入撇号来搜索选择?谢谢!
答案 0 :(得分:3)
以这种方式请求数据库内容会导致SQL注入的风险。你应该使用query methods来管理你的撇号。
答案 1 :(得分:2)
在字符串中插入双撇号:''
即:
SELECT _id, title FROM laws WHERE title LIKE '% ZCUU'' %' OR title LIKE 'ZCUU'' %' OR title LIKE '% ZCUU'''