Re: FreeTDS and UTF-8 support

"James K. Lowden" <[email protected]>
Newsgroups gmane.comp.db.tds.freetds
Message-ID <[email protected]>
Sebastien FLAESCH wrote:
> 
> I think FreeTDS could support all single-byte or multi-byte character
> sets if:
> 
> 1) The application (main) calls setlocale() to define the current
> charset for libc functions like mbtowc, wctomb, mblen (that would
> include UTF-8 support).

I think we are nearly already there.  We use setlocale(3) to determine the
client encoding by default, and consult the freetds.conf "client charset"
property as an override.  

Instead of the "mb" functions, we use iconv(3).  We do sometimes depend on
strlen(3), which is one of many reasons that UCS-2 is not supported (yet)
as a client encoding.  (Another reason is that the APIs sometimes assume
bytes == characters, or state that they return a pointer to a
null-terminated string.  Another reason is I'm aware of only two operating
systems that use any form of wchar_t natively, and they're both
proprietary.) 

> SQLPrepare(hp, (char *) "my SQL string in current SBCD or MBCS charset",
> SQL_NTS);
> 
> would be mapped to:
> 
> SQLPrepareW(hp, (wchar_t *) "my SQL string in UCS-2", SQL_NTS);

I don't think SQLPrepareW is necessary.  SQLPrepare could do both jobs. 

> WARNING: wchar_t on UNIX is 4 bytes while UCS-2 and wchar_t on Windonws
> is 2 bytes.

Thanks for that.  I didn't know.  

Regards, 

--jkl
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.