gpt4 book ai didi

ruby-on-rails - rails : Error when trying to save a special character to database when using ActiveRecord and TinyTDS

转载 作者:行者123 更新时间:2023-12-04 06:22:31 25 4
gpt4 key购买 nike

我正在尝试使用 ActiveRecord 将这个字符“É”作为字符串的一部分保存到我使用 TinyTDS 的 sql 服务器。知道我需要做什么来消除以下错误吗?

Exiting
/var/lib/gems/1.9.1/gems/activerecord-sqlserver-adapter-3.2.10/lib/active_record/connection_adapters/sqlserver/database_statements.rb:387:in `execute': TinyTds::Error: Error converting characters into server's character set. Some character(s) could not be converted

我想它出错的字符串如下:JEREMÉ

下面是我用来解析文件的代码...

csv = CSV.parse(csv_text, :headers=>false, encoding: "UTF-8")
csv.drop(2).each do |row|
person = Person.new(:lastname => row[0], :firstname => row[1])
playerstats.save
end

最佳答案

value = value.force_encoding('ISO-8859-1').encode('UTF-8')

这将使您的字符串数据库满意。

关于ruby-on-rails - rails : Error when trying to save a special character to database when using ActiveRecord and TinyTDS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16953430/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com