Windows, ODBC and charsets

  • Thread starter Cosimo Guglielmucci
  • Start date
C

Cosimo Guglielmucci

Hi all,
I've found very few on the net in regards of Windows and the option
available in the ODBC Driver/ODBC Driver Manager.
So the following problem still remain unsolved:

irb> require 'odbc'
irb> conn =3D ODBC::connect('giomai_db_dsn', 'sa', 'password' )
irb> query =3D conn.prepare("select * from citt=C3=A0 where idcitt=C3=A0 =
=3D 1)
irb> query.execute
ODBC::Error: 37000 (170) [Microsoft][ODBC SQL Server Driver][SQL
Server]Riga 1: sintassi non corretta in prossimit=CE=B1 di '=C3=A0'.
from (irb):xx:in `execute'
from (irb):xx
irb>

This is from Commands Prompt that use
D:\>chcp
Tabella codici attiva: 850 ----------> CP850
that doesn't include the '=CE=B1' character of the error message, and tha=
t is
the same both,
if toggle on or off the option 'convert data characters' in Driver
configuration from Windows ODBC driver manager.
Beside, in linux, I solved setting 'character code =3D UTF8' in
freeetds.conf
because the DB use CP1252, and this way it doesn't influence the entire
system.


In fact, in windows, it also results in error from rail execution:
( RadRails )
Exception occurred during reader method compilation.
Maybe IDCitt=EF=BF=BD is not a valid Ruby identifier?
compile error
c:/ruby/lib/ruby/gems/1.8/gems/composite_primary_keys-2.3.2/lib/composite=
_primary_keys/attribute_methods.rb:34:
syntax error, unexpected tSTRING_BEG, expecting ')'
def IDCitt=EF=BF=BD; missing_attribute('IDCitt=EF=BF=BD', caller) unless
@attributes.has_key?('IDCitt=EF=BF=BD'); (v=3D@attributes['IDCitt=EF=BF=BD=
']) && (v.to_i
rescue v ? 1 : 0); end
...

I don't know where to investigate,
because linux also use ruby-odbc, I think!
But using Client ODBC in windows I have good result on the same table,
maybe because the client convert the characters code for the output
window!

Can you help me?

Thanks.

-- =

Posted via http://www.ruby-forum.com/.=
 
C

Charles Calvert

I've found very few on the net in regards of Windows and the option
available in the ODBC Driver/ODBC Driver Manager.
So the following problem still remain unsolved:

irb> require 'odbc'
irb> conn = ODBC::connect('giomai_db_dsn', 'sa', 'password' )
irb> query = conn.prepare("select * from città where idcittà = 1)
irb> query.execute
ODBC::Error: 37000 (170) [Microsoft][ODBC SQL Server Driver][SQL
Server]Riga 1: sintassi non corretta in prossimit? di 'à'.
from (irb):xx:in `execute'
from (irb):xx

This is really a problem with the ODBC driver for SQL Server. You'd
be much more likely to get answers in the newsgroup for that topic.
See microsoft.public.sqlserver.odbc, which you can access via
Microsoft's "Communities" function
<http://www.microsoft.com/communitie...fault.aspx?dg=microsoft.public.sqlserver.odbc>
or Google Groups
<http://groups.google.com/group/microsoft.public.sqlserver.odbc/topics>.
 
K

KlausG

Hi all,
I've found very few on the net in regards of Windows and the option
available in the ODBC Driver/ODBC Driver Manager.
So the following problem still remain unsolved:

irb> require 'odbc'
irb> conn = ODBC::connect('giomai_db_dsn', 'sa', 'password' )
irb> query = conn.prepare("select * from città where idcittà = 1)
irb> query.execute
ODBC::Error:37000 (170) [Microsoft][ODBC SQL Server Driver][SQL
Server]Riga 1: sintassi non corretta in prossimitα di 'à'.
                  from (irb):xx:in `execute'
                  from (irb):xx
irb>
As Soon As you are using non ASCII chars for column ( or table ) names
You has to use the utf-8 charset. So you need a
require 'odbc_utf8'

And you has to convert your query strings from cp850 to utf-8 with
iconv
And you may have to convert you result from utf-8 back to cp850.
 
C

Cosimo Guglielmucci

Thank you KlausG,
I'm been able to execute read/write query on the DB
from command line following your instructions.

Using -- require 'odbc_utf8' -- I've UTF-8 result that can be converted
in iconv.

Same way, translating the string before the prepare statement it is
...the right string! :)


Now,
can I suppose that rails use -- require 'odbc_utf8' -- ?
I don't think so!

Let's go looking for this switch...
 
C

Cosimo Guglielmucci

Cosimo Guglielmucci wrote in post #957424:
Now,
can I suppose that rails use -- require 'odbc_utf8' -- ?
I don't think so!

Let's go looking for this switch...

Ok,
I've found someone with same interest here:
http://groups.google.com/group/rail...6ad573e3dd/e5e658d1a00ae89f?#e5e658d1a00ae89f
and Christan tells us in his README:
Thus, depending on the -K option of ruby one could use
that code snippet:

...
if $KCODE == "UTF8" then
require 'odbc_utf8'
else
require 'odbc'
fi

But in sqlserver_adapter.rb i can only find a line:
require_library_or_gem 'odbc' unless defined?(ODBC)

So I inserted a require "odbc_utf8" in environment.rb,

I've choosed to change sqlserver_adapter.rb instead, replacing the above
with the following line:
require_library_or_gem 'odbc_utf8' unless defined?(ODBC_UTF8)

It works!
Do you think that can result in some problems?

Thank you, again,
I've been spending a lot of time digging up for this result.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,690
Latest member
MacGyver

Latest Threads

Top