我正在尝试创建一个函数来为 Salesforce 查询创建准备好的语句。要求是转义单引号;Salesforce 会转义其他字符。当我打电话
prepared_query('Select Id from Account where Id = :id and Name = :name limit 1', {:id => '00001234', :name => "John 'Smith"}
预期的输出是
"Select Id from Account where Id = '00001234' and Name = 'John \'Smith' limit 1"
我正在尝试使用gsub
它。我的功能是
def prepared_query(soql, *args)
if args[0].is_a? Hash
args[0].each do |key, val|
val.gsub!("'", %q(\\\'))
soql.gsub! ":#{key}", "'#{val}'"
end
end
end
输出是
"Select Id from Account where Id = '00001234' and Name = 'John limit 1Smith' limit 1"
是什么导致了这个问题?