如何逃脱在OData的查询中使用单引号? [英] How to escape a single quote to be used in an OData query?

查看:365
本文介绍了如何逃脱在OData的查询中使用单引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的OData查询我的数据库。下面的代码行正常工作时,adapterName只包含文本。

I am using OData to query my database. The following line of code works fine when "adapterName" just contains text.

ds.query('/DataAdapters?$filter=Name eq \'' + adapterName + '\'', ifmgr_CreateAdapter_Step1, onGenericFailure, '');

如果adapterName载失败一个单引号。我尝试用下面的代码逃逸单引号:

If "adapterName" contains a single quote it fails. I tried escaping the single quote by using the following code:

adapterName = adapterName.replace(/\'/g, '\\\'');



虽然这个正确逃脱用户定义的文本功能仍然失败。谁能告诉我什么是正确的格式是在查询文本?

Although this correctly escapes the user defined text the function still fails. Can anyone tell me what the correct format is for text in the query?

推荐答案

其实27%是不是一个解决方案。逃生的正确方法是将两个单引号放入字符串,而不是之一。
在例如点钟

Actually %27 is not a solution. The correct way to escape is to place two single quotes into the string instead one. In example "o''clock"

这篇关于如何逃脱在OData的查询中使用单引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆