Skip to Content.
Sympa Menu

freetds - Re: [freetds] hard-coded UCS-2 strings and the C standard

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "James K. Lowden" <jklowden AT freetds.org>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] hard-coded UCS-2 strings and the C standard
  • Date: Tue, 14 Jun 2005 19:31:46 -0400

ZIGLIO, Frediano, VF-IT wrote:
>
> > The advantage of using our iconv system for iso -> ucs2 is that it's
> > independent of the stack: you can convert any size column
> > data, including
> > 2GB text.
>
> Yes, however if you try to do a grep iso2server_metadata you will see
> that this conversion is rarely used and only to convert small strings
> from ascii to ucs2le. The problem is that we always use ascii compatible
> charset so we use ascii for constant text, we add client supplied string
> and then tds_put_string to put on wire. For instance if we want to know
> columns information (in bcp) we build a string with "SET FMTONLY ON
> select * from %s SET FMTONLY OFF" (%s replaced by table name) then use
> tds_submit_query.

OK, I understand your point now.

You're saying that iso2server_metadata is highly generalized, but used
mostly to convert hard-coded ASCII strings. In those few cases where we
accept user metadata, we *assume* it's 8859-1, but that's really a bug.
That SET FMTONLY query really should call iconv 3 times: "SET FMTONLY ON
select " (iso); the "%s" output (client); "SET FMTONLY OFF" (iso).

Should we keep it? I think we should. Looking at
tds_build_params_definition(), I don't see an easier way to guarantee
correct conversion and update all your pointers/indexes correctly. If we
wrote "str_ucs2le_cat()" (catenate ASCII to target, interpolating '\0' to
build UCS2), it might be slightly quicker, but no simpler to use.

> Perhaps tds_put_string instead of tds_put_n_as_UCS2 would suite.

No, we can't do that. Well, we could, but that would be wrong.

tds_put_string() converts from client encoding. Eventually, perhaps,
we'll support UCS-2 clients. Although today we support only client
encodings that are a superset of 8859-1, we shouldn't build mis-wired
connections. Using tds_put_string() to convert from ASCII relies on a
constraint we don't intend to keep.

> Ok, personally I would change tds_put_n_as_UCS2 name to
> tds_put_as_ucs2le (we never used upper case, even for acronym like iso).

OK, I think I'll use tds_put_as_ucs2(). English speakers tend to see
"a2b" as "a to b", and "ucs2" is clear enough in this context.

> > I think that's not portable. ISTR compilers that don't like
> > arrays based
> > on sizeof(). Didn't Bill have one?
>
> Do not confuse strlen with sizeof. Dynamic-size automatic variable are
> not portable however sizeof is a compile time constant. Think at
>
> char buffer[sizeof("test")*2-2];
>
> this is just like
>
> char buffer[8];

I know. I might not remember the incident correctly. Still, I don't like
function calls that work with

char name[] = "name";
but not
char *name = "name";

I think that's laying a trap for a debugging session.

Thanks, Freddy. Your comments made me look more closely at the issues.

Regards,

--jkl




Archive powered by MHonArc 2.6.24.

Top of Page