[freetds] setlocale not that ok...
Craig A. Berry
craigberry at mac.com
Mon Jun 28 22:28:57 EDT 2010
On Jun 28, 2010, at 9:51 AM, Frediano Ziglio wrote:
> I think that calling setlocale in a library with locale != NULL is
> mainly a bad idea. Doing setlocale change global settings that should
> be done by the application not by a library. Setting locale changes
> subtle things like sprintf witch application should be prepared to
> I think we should remove setlocale(LC_ALL, "") in src/tds/mem.c and
> src/tds/locale.c. Applications like tsql, bsql and similars should
> call setlocale by themselves.
I think I understand the argument. The counter-argument is that there
is no other portoble way to interrogate the locale except by calling
setlocale(LC_ALL, ""). The alternative to not calling it in the
library is that any application that also does not call it will be
getting the "C" locale, which means forcing US-ASCII as the client
character set for any application that doesn't have its own
setlocale(LC_ALL, "") call.
We can control what happens in src/apps, but my impression is that
most people using FreeTDS are using language bindings or an ODBC
driver manager and wouldn't know how to set the locale (or maybe
wouldn't have a mechanism for doing so) even if they knew something a
couple of layers down needed it.
Maybe we should give up on trying to get the local character set and
just use ISO-8859-1 or UTF-8 unless explicitly overridden. That might
be less dreadful than having US-ASCII as the default. I don't
honestly know what the right thing to do is.
Craig A. Berry
mailto:craigberry at mac.com
"... getting out of a sonnet is much more
difficult than getting in."
More information about the FreeTDS