Skip to Content.
Sympa Menu

freetds - Re: [freetds] Reading UTF-8 into C/C++ strings

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "James K. Lowden" <jklowden AT schemamania.org>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] Reading UTF-8 into C/C++ strings
  • Date: Thu, 16 Dec 2004 20:53:16 -0500

Ellen Spertus <ellen.spertus AT gmail.com> wrote:
> I need to read UTF-8 strings from Microsoft SQL Server into C (gcc
> 2.95.3). I had gotten almost all the way there when I hit a setback,
> which I'm trying to understand. I would be most grateful for any
> examples or advice.
>
> I'm using db-lib. I've been setting the charset to "UTF-8" and using
> STRINGBIND from a VARCHAR column to a char[]. For a while, I was
> (correctly) getting multi-byte sequences in place of non-ASCII
> characters (e.g., the trademark symbol). Now I'm getting the single
> byte 153 in place of the same non-ASCII character.

FreeTDS knows the server character set by what the server tells it, and
the client character set by what it finds in freetds.conf. It converts
between them transparently.

I have to think you're logged in a little differently or something else
changed, such that the freetds.conf entry for your server doesn't indicate
that UTF-8 is your client character set.

If you set TDSDUMP and look at the top of the log, you should see
something like:

$ head dump
Starting log file for FreeTDS 0.63.dev.20040628
...
iconv to convert client-side data to the "ISO-8859-1" character set

except of course you should see "UTF-8".

If you don't see what you expect, set TDSDUMPCONFIG, too. It will show
you which configuration files are being searched, and what entry was used
to connect you to the server. My bet is that entry doesn't specify UTF-8
as the client character set.

HTH.

--jkl




Archive powered by MHonArc 2.6.24.

Top of Page