ActiveRecord Sql Server中文问题2

下面代码在netbean下执行有问题,因为netbean的文件保存格式是utf-8.会报错存在多字节字符。
搞不明白。但如果直接存为ANSI即一切正常。记之
# coding : gb2312
require "rubygems"
gem 'activesupport', '=2.3.8'
require "active_record"
#require 'odbc_utf8'
require 'odbc'
require 'iconv'

conv=Iconv.new('GB2312','UTF-8')


ActiveRecord::Base.establish_connection(
    :adapter => "sqlserver",
    :mode=>"odbc",
    :dsn=>"localhost",
    :database=> "jkdb_sg",
    :username => "sa",
    :password => "123",
    :encoding=>"gb2312"
)

=begin
class MyModule < ActiveRecord::Base
 
  set_table_name "Module"
   set_primary_keys :RoadNo, :ModuleNo

end
=end


class Road < ActiveRecord::Base
  set_table_name "Road"
  set_primary_key "RoadNo"
end


Road.all().each do |r|
 #puts conv.iconv(r.RoadName)
 puts r.RoadName
end

=begin
r=Road.find(46)
r.RoadName='广珠西'
r.save
=end





puts "done"
puts "完成"












posted @ 2010-10-13 16:52  damnit  阅读(227)  评论(0编辑  收藏  举报