tags:

views:

482

answers:

3

Hi,

I noticed my Rails app returns in place of double quotes and certain dashes, it returns a question mark character-- �

Is there a way to update the table and replace them with original characters?

Thanks!

Amie

A: 
update [table_name] set [field_name] = 
replace([field_name],'[string_to_find]','[string_to_replace]');

Should do the trick. Always run against a test database first until you know it won't break anything.

Use this statement at your own risk.

JosefAssad
Thanks for the suggestion. One issue with find and replace is that I'm not sure which string to find. From mysql console, they all show up as "?" (including those special characters and legitimate question mark characters) I was hoping there is some encoding setting I can tweak. Any suggestion is appreciated.
Grnbeagle
+1  A: 
Alan Moore
Thanks for info. As you suggested I looked up more info on windows-1252 encoding.. It seems the http response header (which is specified UTF-8) takes precedence over meta charset, so I couldn't change encoding ad-hoc. This is useful info on the topic: http://www.cs.tut.fi/~jkorpela/www/windows-chars.html
Grnbeagle
+1  A: 

Those question marks indicate an invalid byte for the encoding of the environment the result is displayed in.

These days most environments will be utf-8.

If your running the mysql console app, run the following command when you first connect to tell the MySQL server to return all results for the current connection in utf-8:

  SET NAMES utf8;

In rails, you can have this command run when ActiveRecord opens a db connection by adding "encoding: utf8" to your database.yml file. You should also to make sure your webserver (apahce/nginx/etc) is sending the utf-8 HTTP header and that your HTML files have a Content-Type meta tag.

It's possible you have corrupt bytes stored in your database and this won't help. If that's the case, you're in for a world of fun trying to clean it up :)

James Healy
Had the same problem... adding encoding: utf8 to database.yml made the � characters display correctly. Thanks, I had forgotten about that :)
foz