我试图用地图函数中的变量创建查询,但存储在这些字段之一中的内容确实包含'
(引号,如Barney's)。所以每当它破裂,因为'
将打破这种说法。我怎样才能解决它? 我试图使用.split
函数,但没有成功。 不用担心SQL注入,因为我只是从API加载数据到我的数据库。在地图变量中避免引号
代码:
query_values = activities.map do |activity|
'(' +
"#{activity['id']},
""'#{activity['type']}""'" #using ""' just to fill the column when empty cells are raised
+')'
end
query = "INSERT INTO pd_activities VALUES #{query_values.join(', ')}"
在此先感谢。
盲目插入的东西简直是疯了。 **即使您认为您的数据没问题,也不要这样做。当你认为你遇到麻烦时。 – tadman