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: "ZIGLIO, Frediano, VF-IT" <Frediano.Ziglio AT vodafone.com>
  • 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 08:15:09 +0200

>
> ZIGLIO, Frediano, VF-IT wrote:
> > tds_put_string should work too but it expect client
> encoding... another
> > solution is to separate code to handle iso -> ucs2
> conversion. It seems
> > that iso2server_metadata conversion is used only to do this
> conversion,
> > perhaps a tds_iso2ucs2le would eliminate the need for this
> conversion
> > too
>
> 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. Perhaps tds_put_string instead of tds_put_n_as_UCS2
would suite.

> > perhaps a define like
> >
> > #define TDS_PUT_AS_UCS2(tds, s) do { \
> > char buffer[sizeof(s)*2-2]; \
> > tds_put_n(tds, buffer, tds_iso2ucs2le(buffer, s)); \
> > } while(0)
>
> 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];

> It looks like your solution and mine are about the same in
> terms of code
> size. I think mine's a little easier to understand. OK to commit?
>

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).

bye
freddy77




Archive powered by MHonArc 2.6.24.

Top of Page