Hello all,
I am writing data into an MS SQL Server, to be used by other applications (not my rails app).
The problem is I need to put Chinese and Japanese characters into the database. If I write it in using the Rails SQL Server adapter, it writes the data in UTF-8 code points, which rails can then read again and deal with fine.
Problem is, other applications see this as garbage as it is not UCS-2.
I'm trying to find a way to write in UCS-2. The following code snippet does not work:
require 'iconv'
def convert(string) Iconv.iconv('UCS-2', 'UTF-8', string) end
MsSqlModel.update_attribute(:name => convert(name))
Which is sort of expected as the SQL adapter does not N'' quote it's UTF-8 strings. So I tried the following (which also doesn't work)...
require 'iconv'
def convert(string) Iconv.iconv('UCS-2', 'UTF-8', string) end
MsSqlModel.connection.execute("UPDATE table_name SET name = N'#{convert(name)}';")
Has anyone out there had and solved this problem? Extensive googling has turned up very little.
Thanks all
Mikel