[freetds] Question of Charset
James K. Lowden
jklowden at schemamania.org
Sun Mar 7 14:08:35 EST 2004
On Sun, 07 Mar 2004, edwardspl at ita.org.mo wrote:
> After enter chinese words though program ( Web ) to MS-SQL, then search
> the data from the DB...
> But the result of the records is not chinese words ( char ) !
> So, how to specify the client charset in freetds.conf ?
I don't speak or read Chinese, and have no experience setting up Chinese
support for FreeTDS. I'll tell you what I know.
Understand that we added UTF-8 support for FreeTDS. To use it, your
client needs UTF-8 locale settings, including UTF-8 fonts. Other
encodings *might* work; I know other Japanese encodings have been reported
to work. Which encoding are you using?
In general, first be sure libiconv is used:
$ tsql -C |grep iconv
iconv library: yes
Check your iconv's Chinese support:
$ iconv -l |grep -Ei 'chinese|big'
UCS-2BE UNICODE-1-1 UNICODEBIG CSUNICODE11
CHINESE GB_2312-80 ISO-IR-58 CSISO58GB231280
BIG-5 BIG-FIVE BIG5 BIGFIVE CN-BIG5 CSBIG5
Put the name in freetds.conf:
host = foo.bar.com
port = 1433
tds version = 7.0
client charset = UTF-8 # BIG-5 might work
That should do it, as far as FreeTDS is concerned. You can check with
jklowden at oak.schemamania.org$ export TDSDUMP=stdout
jklowden at oak.schemamania.org$ tsql -S$S -U$U -P$P |head -20
locale is "C"
locale charset is "646"
Starting log file for FreeTDS 0.63.dev.20040125
on 2004-03-07 13:53:54 with debug level 99.
names for ISO-8859-1: ISO-8859-1
names for UTF-8: UTF-8
names for UCS-2LE: UCS-2LE
names for UCS-2BE: UCS-2BE
iconv to convert client-side data to the "646" character set
13:53:54.414280 tds_iconv_info_init: converting "US-ASCII"->"UCS-2LE"
13:53:54.414314 tds_iconv_info_init: converting "ISO-8859-1"->"UCS-2LE"
(You would see your character set name instead of these.)
At this point, tsql *should* show Chinese characters resulting from a
query, as long as the data come from a nchar, ntext, or nvarchar columns.
I don't know much about PHP. Others here do, though. Good luck!
More information about the FreeTDS