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

3

I'm using a Ruby script that parses an XML file and inserts the information into a MySQL database. It works perfectly fine, but it's giving me a headache now that my XML files have strings in Portuguese

Detail: I'm completely new to Ruby.

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

I've 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 crazy. For example: 'us' instead of 'no'.

Any ideas how I can approach the problem?

    
asked by anonymous 02.07.2014 / 21:22

1 answer

2

I finally solved it.

It turned out that the problem was with the driver connecting to the bank. Through this SO response I saw the recommendation to use 'mysql2' instead of 'mysql' because 2 deals with character encoding properly!

    
03.07.2014 / 04:06