rails & sqlserver collation problems

9 views
Skip to first unread message

Edu Mariano

unread,
Feb 23, 2011, 11:54:47 AM2/23/11
to Ruby on Rails: Talk
Boa tarde pessoal.

Estou utilizando o intant rails com ruby v.1.8.6 e rails 2.0.2 com um
servidor sqlserver2000, minha base de dados usa o collation
SQL_latin1_general_CP1_CI_AS, quando tragos strings com acentuação e
cedilha não consigo visualizar os carateres corretos, sei que para
exibir corretamente o texto no ruby tenho que usar UTF-8. Como posso
fazer pra mudar o collation da minha base ou converter as string para
UTF-8 na hora de exibir?

Desde já agradeço
Eduardo

Bryan Crossland

unread,
Feb 23, 2011, 1:04:02 PM2/23/11
to rubyonra...@googlegroups.com
Peço desculpas pelo meu Português. Estou usando o Google Translate. :-)

Você precisa informar o arquivo database.yml que pretende conversar
com o banco de dados em UTF-8. Para fazer isso adicione encoding: utf8
para o seu banco de dados no database.yml. Deixe-me saber como isso
vai.

Obrigado,
B.

2011/2/23 Edu Mariano <eduma...@bol.com.br>:

> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

Michael Pavling

unread,
Feb 23, 2011, 2:21:29 PM2/23/11
to rubyonra...@googlegroups.com
2011/2/23 Bryan Crossland <bacro...@gmail.com>:

> Peço desculpas pelo meu Português. Estou usando o Google Translate. :-)

Por favor, pare top postagem

Bryan Crossland

unread,
Feb 23, 2011, 5:42:44 PM2/23/11
to rubyonra...@googlegroups.com, Michael Pavling


On Wed, Feb 23, 2011 at 1:21 PM, Michael Pavling <pav...@gmail.com> wrote:
> Por favor, pare top postagem

http://en.wikipedia.org/wiki/Posting_style

"The traditional style was for a long time to post the answer below as much of the quoted original as was necessary to understand the reply (bottom or inline). Many years later, when email became widespread in business communication, it however became a widespread policy to reply above the entire original and leave it untouched (and without any prefixes at the beginning of each line) below the reply."

Michael Pavling

unread,
Feb 23, 2011, 5:50:46 PM2/23/11
to rubyonra...@googlegroups.com
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?


On 23 February 2011 22:42, Bryan Crossland <bacro...@gmail.com> wrote:
> On Wed, Feb 23, 2011 at 1:21 PM, Michael Pavling <pav...@gmail.com> wrote:
>> Por favor, pare top postagem
>

> "The traditional style was for a long time to post the answer below as much
> of the quoted original as was necessary to understand the reply (bottom or
> inline). Many years later, when email became widespread in business
> communication, it however became a widespread policy to reply above the
> entire original and leave it untouched (and without any prefixes at the
> beginning of each line) below the reply."

This list isn't a business communication - it's a reference resource,
and that "policy" was imposed because one company's email software
that just "did it that way" - irregardless of any user preference.

>http://en.wikipedia.org/wiki/Posting_style

Read the whole of that article... especially the section on "Choosing
the proper posting style". If after that you still insist on
top-posting, so be it :-/
*shrug*

Bryan Crossland

unread,
Feb 23, 2011, 6:07:26 PM2/23/11
to rubyonra...@googlegroups.com, Michael Pavling
I reply to the email that I receive which uses the standard method of top posting. Why? Because if you bottom-posted all the time or unnecessarily inline quoted it would make this thread: http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/6c25db52c2d743aa and others like it unreadable.

I'm done discussing posting styles. Let's return to helping each other out which is the main reason for this group.

Michael Pavling

unread,
Feb 23, 2011, 6:20:38 PM2/23/11
to rubyonra...@googlegroups.com
On 23 February 2011 23:07, Bryan Crossland <bacro...@gmail.com> wrote:
> I reply to the email that I receive which uses the standard method of top
> posting.

What "standard"? Which RFC says that there is any "standard"?

> if you .... unnecessarily


> inline quoted it would make this thread:
> http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/6c25db52c2d743aa
> and others like it unreadable.

no... top-posting makes it impossible to maintain a coherent
conversation, and introduces confusion about what replies refer to,
because there's no context.

> I'm done discussing posting styles.

So I guess you *didn't* bother reading the rest of the article you
waved as defence of your position? ... hence my *shrug*

PS You've got a frightfully annoying email client too, which sends
*to* the person, and CCs the group - so further replies go to you, not
the group... :-/

Edu Mariano

unread,
Feb 24, 2011, 7:49:01 AM2/24/11
to Ruby on Rails: Talk
Eu tentei usar o encoding: utf8 no database.yml, mas para o sql server
não funciona. tentei então um helper para a classe string com o
seguinte código

-----------------------------------------------------------code starts
here-----------------------------------------------------------------------

class String
# Returns a valid DateTime object if the object can be converted
according to +format+, nil otherwise.
# FIXME: Corrigir o erro de validação em colunas contendo data +
hora.

gem 'chardet'
require 'UniversalDetector'

def parse_date(format =
ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS[:default])
begin
DateTime.strptime(self, format)
rescue ArgumentError
end
end

def to_utf8
@encode_type = UniversalDetector::chardet(self)["encoding"]
#detects the str encoding
Iconv.iconv("UTF-8", @encode_type, self).to_s #converts the
current encoding to UTF-8 of the present string
end

end

-----------------------------------------------------------code ends
here-----------------------------------------------------------------------

O chardet é uma gem que pode retornar o tipo de codificação utilizada
na string, o tipo de codificação retornado para o
SQL_latin1_genreal_CP1_CI_AS é o ISO-8859-5 e o iconv consegue passar
a string para utf8, porém os resultados ainda não são satisfatórios
pois os caracteres acentuados e as cedilhas não são exibidos
corretamente. Veja abaixo:

O que deveria exibir:

Fundação Ecumênica de Proteção ao Excepcional - PARANC

está exibindo:

Fundaчуo Ecumъnica de Proteчуo ao Excepcional - PARANС

Sinto que estou chegando perto, alguém sabe como prosseguir deste
ponto?

Desde já agradeço
Edu
Reply all
Reply to author
Forward
0 new messages