rake 和 rake 之间的 Rails 字符编码不同安慰
我有一个 rake 任务,从 MS SQL 数据库中提取一些数据,最近我注意到一些特殊字符被编码为问号“?”。在尝试深入研究这个问题时,我意识到我只能将其重新存储为 rake 任务,而不能从控制台重新存储。
下面是代码的一个片段:
require 'dbi'
namespace :db do
task :test => :environment do
db2 = DBI.connect("DBI:ODBC:DRIVER=FreeTDS;SERVER=x.x.x.x;PORT=1433;DATABASE=MyDB;TDS_VERSION=8.0;UID=user_id;PWD=pass")
rows = db2.execute('select * from Topic where id = 123')
rows.each { |r| puts r['name'] }
rows.finish
end
end
当我运行它时:
rake RAILS_ENV=production db:test
它会产生:
The Devil?s Tail
但是当我使用以下命令运行完全相同的命令时:
/> script/console production
我得到
The Devil`s Tail
注意后面的勾号?任何人都知道为什么会导致这种情况?我仔细检查了 ENV 变量,它们都有 LANG: en_US.UTF-8
编辑
忘记提及我正在使用 ruby 1.8.7p72 和 Rails 2.3.4
I have a rake task that pulls some data from a MS SQL db, and recently I noticed that some special characters get encoded as a question mark '?'. While trying to dig into this issue, I realized that I could only repo it as a rake task, but not from the console.
Here is a snippet of what the code looks like:
require 'dbi'
namespace :db do
task :test => :environment do
db2 = DBI.connect("DBI:ODBC:DRIVER=FreeTDS;SERVER=x.x.x.x;PORT=1433;DATABASE=MyDB;TDS_VERSION=8.0;UID=user_id;PWD=pass")
rows = db2.execute('select * from Topic where id = 123')
rows.each { |r| puts r['name'] }
rows.finish
end
end
when I run this as:
rake RAILS_ENV=production db:test
it produces:
The Devil?s Tail
But when I run the exact same commands using:
/> script/console production
I get
The Devil`s Tail
Notice the back tick? Anyone have any idea why may be causing this? I double checked the ENV variables, and they both have LANG: en_US.UTF-8
EDIT
Forgot to mention I am using ruby 1.8.7p72 and Rails 2.3.4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论