Skip to Content.
Sympa Menu

freetds - [freetds] [PATCH] reorder charset handlling in tsql (Re: SQL Server version and TDS Version)

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Craig A. Berry" <craigberry AT mac.com>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: [freetds] [PATCH] reorder charset handlling in tsql (Re: SQL Server version and TDS Version)
  • Date: Fri, 30 Apr 2010 10:35:02 -0500


On Apr 29, 2010, at 11:02 PM, Craig A. Berry wrote:

I think the right fix is going to be to reorder things in tsql.c so it only puts a charset in the login structure when the user specifies one explicitly on the command line or, as a last chance, puts the charset in the connection structure if it's empty after the call to tds_read_config_info().


And that's what I've done in the attached patch. Specifically,

1.) Implement the -J command-line option (lifted directly from the Sybase documentation) to explicitly set the client charset. This is now the only case where tsql will set the charset before reading configuration info, and we know from recent experience that this trumps what's in freetds.conf.

2.) If and only if reading configuration info fails to set the client charset (which I think is unlikely since it apparently chooses its own default), tsql will set it to the charset read from locale_charset() or nl_langinfo(). If it wasn't able to get a charset from the locale, it will hardwire it to ISO-8859-1.

There is a new line of output showing the default charset actually being used, which is now somewhat less likely to be the locale charset. This output could of course be suppressed in cases where they are the same:

% ./src/apps/tsql -Usomeuser -Smyserver
Password:
locale is "C"
locale charset is "US-ASCII"
using default charset "ISO-8859-1"
1>


My assumption throughout is that the TDS library already knows how to pick a charset and the application should defer to it unless there is good reason to explicitly override it, which we now have the ability to do. Most likely the old logic using locale charset in tsql.c predates all of the advanced charset handling in src/tds/iconv.c

________________________________________
Craig A. Berry
mailto:craigberry AT mac.com

"... getting out of a sonnet is much more
difficult than getting in."
Brad Leithauser


Attachment: tsql_charset.patch
Description: Binary data





Archive powered by MHonArc 2.6.24.

Top of Page