Hi all,
I was trying to update the JIS-encoded text in the databse to UTF-8
text but failed (For simplicity, I use “hello” & “world” in the test
program below). Please point me the mistake I made here. Thanks.
#using sqlite
ActiveRecord::Base::establish_connection
(:adapter=>“sqlite3”,:dbfile=>“the.db”)
#try to do the update but failed
rowid = 72 #it is the default unique ID in sqlite
Basic.find(:all , :select=>"rowid , event_name ,text ",
:conditions=>[“rowid = ?”,rowid]).each do |o|
puts "before modify"
puts o.event_name
puts o.text
o.event_name = "hello"
o.text = "world"
puts "after modify before save"
puts o.event_name
puts o.text
o.save
#o.update_attribute(:event_name,"hello")
end
#confirm
Basic.find(:all , :select=>"rowid , event_name ,text ",
:conditions=>["rowid = ?",rowid]).each
do |o|
puts “after save”
puts o.rowid
puts o.event_name
puts o.text
end
output Log :
–>before modify
|¢¸¢ó¹Þ¤ëûL1B2nrDJ0é¸?6I!A¤óÉÍ·¢!!«êÞó¿óEg!A?
B?L1B2¬Jké¹|¤óÉÍ·¢ý«êÞó¿óEgúJ6Ah,@d(:?}³ìÞÇ?>@7<TÏ@i?MòD6¹úL1B2M;OBòL;X?c<T10?M?|é¸?
I r;O a??c-DJNJ3F.rDI&?
–>after modify before save
hello
world
–>after save
72
|¢¸¢ó¹Þ¤ëûL1B2nrDJ0é¸?6I!A¤óÉÍ·¢!!«êÞó¿óEg!A?
B?L1B2¬Jké¹|¤óÉÍ·¢ý«êÞó¿óEgúJ6Ah,@d(:?}³ìÞÇ?>@7<TÏ@i?MòD6¹úL1B2M;OBòL;X?c<T10?M?|é¸?
Ir;Oa??c-DJNJ3F.rDI&?