转义sqlite中的特殊字符 [英] Escape special characters in sqlite
问题描述
我正在尝试更新我的 Android 应用程序中的 SQLite 表.此更新的谓词围绕存储不同资源 URL 的列构建.
I am trying to update a SQLite table in my Android application. Predicate for this update is built around a column which stores different resource URLs.
这些 URL 可能包含特殊字符,例如/~?=;(甚至 &).
These URLs might contain special characters such as /~?=; (and even &).
我的查询看起来像:
update TableName where columnVal = '/some/fake/~/id?u=0&rl=url';
更新查询不起作用;它不识别满足条件的列.
The update query doesnt work; it does not identify the column satifying the condition.
如何转义这些字符?
请指教.
推荐答案
您应该使用方法 update
而不是自己生成 SQL.内置方法将为您完成所有需要的转义.
You should be using the method update
instead of generating the SQL yourself. The built-in methods will do all the needed escaping for you.
http://developer.android.com/reference/android/数据库/sqlite/SQLiteDatabase.html
这篇关于转义sqlite中的特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!