正确工作的选择:
selection: title LIKE '% Z %' OR title LIKE 'Z %' OR title LIKE '% Z'如果db选择包含撇号,我的应用程序就会崩溃:
日志:
android.database.sqlite.SQLiteException: unrecognized token: "'% ''": ,
while compiling: SELECT _id, title FROM table_name WHERE title LIKE '% ' %'
OR title LIKE '' %' OR title LIKE '% ''或:
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''谁知道如何在其中插入撇号以正确搜索选择?谢谢!
发布于 2014-02-27 16:58:30
在字符串中插入一个双撇号:“”
即:
SELECT _id, title FROM laws WHERE title LIKE '% ZCUU'' %' OR title LIKE 'ZCUU'' %' OR title LIKE '% ZCUU'''发布于 2014-02-27 17:01:16
以这种方式请求数据库内容会导致SQL注入的风险。顺便说一下,您应该使用查询方法来管理撇号。
https://stackoverflow.com/questions/22075076
复制相似问题