轉載的ActiveRecord Sql Server中文問題2

來源:互聯網
上載者:User

ActiveRecord Sql Server中文問題2

1 下面代碼在netbean下執行有問題,因為netbean的檔案儲存格式是utf-8.會報錯存在多位元組字元。
view sourceprint?1 搞不明白。但如果直接存為ANSI即一切正常。記之
view sourceprint?01 # coding : gb2312 

02 require "rubygems"

03 gem 'activesupport', '=2.3.8'

04 require "active_record"

05 #require 'odbc_utf8' 

06 require 'odbc'

07 require 'iconv'

08   

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

10   

11   

12 ActiveRecord::Base.establish_connection( 

13     :adapter => "sqlserver", 

14     :mode=>"odbc", 

15     :dsn=>"localhost", 

16     :database=> "jkdb_sg", 

17     :username => "sa", 

18     :password => "123", 

19     :encoding=>"gb2312"

20 ) 

21   

22 =begin

23 class MyModule < ActiveRecord::Base 

24    

25   set_table_name "Module"

26    set_primary_keys :RoadNo, :ModuleNo 

27   

28 end

29 =end

30   

31   

32 class Road < ActiveRecord::Base 

33   set_table_name "Road"

34   set_primary_key "RoadNo"

35 end

36   

37   

38 Road.all().each do |r| 

39  #puts conv.iconv(r.RoadName) 

40  puts r.RoadName 

41 end

42   

43 =begin

44 r=Road.find(46) 

45 r.RoadName='廣珠西'

46 r.save 

47 =end

48   

49   

50   

51   

52   

53 puts "done"

54 puts "完成"

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.