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 "完成"