UTF-8: reading and inserting into Mysql via Ruby 1.8

Asked

Viewed 80 times

3

I am using a script written in Ruby that parses some XML files and inserts the information in a Mysql group. It works perfectly well, but it’s giving me a headache now that my XML files have strings.

Detail: I’m completely new to Ruby.

For some reasons I’m stuck with Ruby 1.8 and I’ve been reading that this version has peculiarities to deal with Strings. I have already confirmed that both the XML file and the Mysql collation and tables are UTF-8.

I have also tried, unsuccessfully, to encode the string before sending it to the bank using a hint found in this post as follows:

@text = ::Iconv.conv('UTF-8//IGNORE', 'UTF-8', attributes['Text'] + ' ')[0..-2]

After inserting the eye data via Phpmyadmin the strings are hacked. For example: 'nâ³s' instead of 'no'.

Any idea how I can address the problem?

  • And what would it be, your collation of your table? Why often the collation of the bank and table are different... Just confirm that..

  • Thanks @Brunocasali - to be specific: utf8_general_ci

  • Um, beauty, you tried let’s say serialize in another xml file, txt or write to another database or simply show on screen without the database ?

  • Opa @Brunocasali. I had not tried and I could only see now. When printing on the screen I think the output system itself handles the character encoding because in the terminal the string comes out correct. =/

1 answer

2


I finally resolved.

It turns out that the problem was the driver connection to the bank. Through of this OS response vi the recommendation to use mysql2 instead of mysql because 2 treats character encoding correctly!

  • Ball show!! D

  • Cool, just mark your answer as correct to assist users who are seeking this information.

  • Beauty @Andrey. I’m just waiting for the time required by the system. I can only book tomorrow. Hug.

  • @Nigini can only schedule tomorrow? Did not know this restriction.

  • If I’m not mistaken it’s to promote diversity. If I ask, answer and resolve, the rest of the community will have less interest in answering. =/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.