[unixODBC-support] Re: Chinese encoding issue

Yu-Hui Jin yuhui.jin at gmail.com
Wed Feb 27 22:22:02 GMT 2008


Hi, Martin,

I searched on the web and it seems the utility you are talking about is
"osql", a unicode compliant tool that has a similar interface as isql.
However, it is a Window 32 command line tool but the OS I am working on is
RedHat Enterprise Linux 3.

But then what I really need is not to run isql or osql. I ran them in hope
of finding out whether unixODBC returns me the correct encoding for the
Chinese data.  But as you pointed out, the isql utility can't do it.  So let
me go straight to what I have tested in my scripts.

I set up the unixODBC and FreeTDS, etc. according to the online guide:
http://wiki.rubyonrails.org/rails/pages/HowtoConnectToMicrosoftSQLServerFromRailsOnLinux

I then tried two ways to connect to the SQL Server 2000 in my scripts and
both succeeded connecting and retrieving data back yet  failed to read the
Chinese data in the correct encoding.  The query returned correctly the
numbers and English data, but the Chinese data encoded in GB2312 were all
garbled.  The two ways i tried are:

1. in a ruby script, i have the driver set up like:

#!/usr/local/bin/ruby
require 'dbi'

DBI.connect('DBI:ODBC:testdb', 'username', 'password') do | dbh |
  dbh.select_all('select TOP 10 * from ATABLE with(nolock)') do | row |
   row.each_with_name do |val, name|
     puts "#{name}, #{val.to_s}"
   end
   print "\n"
  end
end

Some "name" data are in Chinese, but all of them are garbled.


2. in my Rails app, I have set up sql server in the database.yml as follows
:

# Linux
development:
  adapter: sqlserver
  mode: odbc
  dsn: testcoredb
  username: sa
  password: joyo
....
....

All Chinese data retrieved are garbled.

Since runing tsql returns correct Chinese data, I'm suspecting somewhere
unixODBC messed up with the Chinese data.  But it could also be I'm not
installing unixODBC with the right configuration.

Any help or suggestions are much appreciated. Let me know if you need me to
provide more info.


Thanks,

Yuhui




On Wed, Feb 27, 2008 at 1:13 PM, Martin J. Evans <martin.evans at easysoft.com>
wrote:

> Yu-Hui Jin wrote:
> > Hi, there,
> >
> > I set up unixODBC and freetds on my Linux box to talk to MS SQL Server
> > 2000 (and 2005) hosts.   The data in those databases contain Chinese
> > texts encoded in GB2312.
> >
> > Everything seems to be working.  I can run both tsql and isql with the
> > same statement to retrieve data from one of the test SQL Server
> > databases.  Then I found tsql returns the correct Chinese characters
> > (for a column value) but isql  returns garbled data which looks like
> > "?????, ???".   So I suspect it's unixODBC messed up with the data.
> >
> > Does anyone know what should I do to fix this?
> >
> >
> > Many thanks,
> >
> > Yuhui
> isql is an ASCII app. You will need to use uisql (or whatever it is
> called - can't remember off the top of my head). Both isql and uisql are
> really demo apps although I would not be surprised if someone is using
> them for something useful.
>
> Martin
> _______________________________________________
> unixODBC-support mailing list
> unixODBC-support at easysoft.com
> http://mail.easysoft.com/mailman/listinfo/unixodbc-support
>



-- 
Regards,

-Hui
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-support/attachments/20080227/e5a2b5f7/attachment.html>


More information about the unixODBC-support mailing list