# Problem with encoding latin1/UTF8

**URL:** <https://www.ruby-forum.com/t/problem-with-encoding-latin1-utf8/124464>\
**Category:** Ruby\
**Created:** [December 28, 2007, 11:16pm UTC](https://www.ruby-forum.com/t/problem-with-encoding-latin1-utf8/124464 "2007-12-28T23:16:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![markthomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/90db22/32.png) [@markthomas](https://www.ruby-forum.com/u/markthomas)\
**Post date:** [December 28, 2007, 11:16pm UTC](https://www.ruby-forum.com/t/problem-with-encoding-latin1-utf8/124464/1 "2007-12-28T23:16:27Z")

</div>

I have a database with latin1\_swedish\_ci encoding.  
In my database.yml file there is:

development:  
adapter: mysql  
encoding: latin1

When I import data to the database it will store it correctly, but when  
IÂ´m reading it from the databse I get ï¿½ï¿½ï¿½ instead of Ã¥Ã¤Ã¶.

IÂ´m using the following code to read from the databse:

@results = Product.find(:all, :conditions =\> [ “sku LIKE ?”,  
a1+@searchstring+a2], :limit =\> 50)

Any idea? IÂ´ve tried to set the $KCODE = ‘latin1’ without success.

---

<div class="post-metadata">

**Author:** ![markthomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/90db22/32.png) [@markthomas](https://www.ruby-forum.com/u/markthomas)\
**Post date:** [January 7, 2008, 9:39am UTC](https://www.ruby-forum.com/t/problem-with-encoding-latin1-utf8/124464/2 "2008-01-07T09:39:05Z")

</div>

Hi Mark,

I’m not sure the problems are related, but I’ve had to convert data from  
an Oracle database with Win-1252 encoding to UTF-8 for generating  
OpenOffice files. For that, I used the following syntax (being new to  
Ruby/Rails, I still prefer plain SQL queries…):

```
@wrk_vpreparations = WrkVpreparation.find_by_sql(
    ["SELECT CONVERT( CODE, 'UTF8', 'WE8MSWIN1252' ) AS CODE,
             CONVERT( DESC_FR, 'UTF8', 'WE8MSWIN1252' ) AS 

```

DESCRIPTION  
FROM WRK\_VPREPARATIONS  
WHERE ID=?", params[:id]] )

Hope this helps.

Chris.
