Activerecord SQL Server Chinese Question 2
Below 1CodeThere is a problem with the execution in netbean, because the file storage format of netbean is UTF-8. An error is reported that there are multi-byte characters.
View sourceprint? 1. I cannot understand it. However, if it is stored as ANSI, everything is normal. Note
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 = 'guang Zhu Xi'
46 R. Save
47 = end
48
49
50
51
52
53 puts "done"
54 puts "finished"