[freetds] Unicode from Linux/OS X to SQL Server nvarchar

Frediano Ziglio freddy77 at gmail.com
Sun Aug 2 10:55:33 EDT 2009


Il giorno lun, 27/07/2009 alle 23.18 -0400, James K. Lowden ha scritto:
> Ingmar Koecher wrote:
> > 
> > I found one post where it was suggested that one use UTF-8 as FreeTDS
> > doesn't support UCS-2, but I am confused as to how this would work since
> > SQL Server doesn't support UTF-8. Does FreeTDS convert it from UTF-8 to
> > UCS-2?
> 
> FreeTDS engages an iconv library to convert between server and client
> encodings.  In principle, you should be able to define any client
> encoding, bind your parameters character buffers, and call your
> procedures.  
> 
> It has worked for query processing and bcp for years.  Only more recently
> did parameter binding get attention.  
> 
> > Basically, I am curious what the recommended way is to store unicode
> > data (whether it's UTF-8 or UTF-16) in a SQL Server database nvarchar
> > field.
> 
> The last thing you want to do is somehow end up with UTF-8 data on a
> Microsoft server, since it doesn't recognize that as a valid encoding.  
> 
> The DBMS does the storing and decides the format.  NVARCHAR columns are
> UCS-2; VARCHAR some flavor of single-type "code page".  
> 
> What you want is UTF-8 on the client and NVARCHAR on the server, and
> FreeTDS in between to handle the conversion.  I'm not sure how well this
> currently works in practice, but it should.  I recommend trying a recent
> snapshot.  Definitive problem reports are almost as welcome as working
> patches.  :-)
> 
> HTH.
> 

0.82 should support SQL_WVARCHAR but no SQL_C_CHAR. CVS support both.
In other words it should be possible to use 0.82 with UTF-8 encoded and
SQL_C_CHAR/SQL_WVARCHAR configuring client for UTF-8. CVS version
support this or using SQLWCHAR encoding (either UCS-2 or UCS-4 depending
on DM) SQL_C_WCHAR and SQL_WVARCHAR.
There are exhaustive tests for this on CVS version. Not so exhaustive on
0.82.

freddy77





More information about the FreeTDS mailing list