【发布时间】:2016-08-03 11:58:13
【问题描述】:
我们在我们的应用程序中使用生产和暂存数据库。 我们的要求是在生产数据库中添加记录时将所有记录插入到临时数据库中,以使两个服务器保持一致且数据相同。
我已使用 Mysql2 客户端池连接到暂存服务器并插入添加到生产中的记录。 这是我的代码:
def create
@aperson = Person.new
@person = @aperson.save
if @person && Rails.env == "production"
#add_new_person_to_staging
client = Mysql2::Client.new(:host => dbconfig[:host], :username => dbconfig[:username], :password => dbconfig[:password], :database => dbconfig[:database])
@person_result = client.query('INSERT INTO user_types(user_name, regex, code) Values ("myname" , "\.myregex\." , "ns" );')
end
end
这里 "@person_result" 记录被插入到 mysql 表中,但 "regex" 列消除了 "\" 斜杠。
点赞:user_name = myname, regex = .myregex., code = ns
当我在 mysql 命令行中手动执行“插入”查询时,它会与 \ 斜杠一起插入。但不是通过“client.query”
为什么\ slash 被淘汰了。请在这里帮助我。
谢谢。
【问题讨论】:
标签: mysql ruby-on-rails ruby ruby-on-rails-4 mysql2