Google App Engine 的 JDO:转义引号
如何转义 JDO (Google App Engine) 中的查询参数?
例如,如果变量名称可能包含单引号 (') 形式的不安全字符,如何使下一个片段安全
PersistenceManager pm = ...;
String query = "select from Person where name='"+name+"'";
List<Shortened> shortened = (List<Shortened>) pm.newQuery(query).execute();
How do I escape parameters of queries in JDO (Google App Engine)?
For example, how do I make the next snippet safe, if the variable name may contain unsafe chars as single quotes (')
PersistenceManager pm = ...;
String query = "select from Person where name='"+name+"'";
List<Shortened> shortened = (List<Shortened>) pm.newQuery(query).execute();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请改用查询参数,这比在查询本身中包含值要安全得多。以下是 GAE 文档中的示例:
Use query parameters instead, it's a much safer than including the values in the query itself. Here is an example from the GAE documentation: