Skip to Content.
Sympa Menu

freetds - Re: [freetds] [PATCH bcp.c:_bcp_read_hostfile] don't trim trailingspaces when all spaces

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] [PATCH bcp.c:_bcp_read_hostfile] don't trim trailingspaces when all spaces
  • Date: Tue, 20 Dec 2005 09:49:01 +0100

>
> > From: Craig A. Berry
> > Sent: Sunday, December 18, 2005 11:38 PM
> >
> > When bulking in character data, we currently trim trailing spaces,
> > which in general seems like the right thing to do with one
> exception.
> > The exception is when a field is all spaces; I don't think we should
> > trim those to nothing because then we end up inserting nulls in
> > what may or may not be nullable fields. The attached patch changes
> > behavior so that we only trim trailing spaces when one or more
> > characters is not a space.
>
> I think this can be done with a one liner. Instead of:
>
> bcpcol->bcp_column_data->datalen =
> rtrim((char *) bcpcol->bcp_column_data->data,
> bcpcol->bcp_column_data->datalen);
>
> Change the call to rtrim():
>
> if (bcpcol->bcp_column_data->datalen > 1) {
> bcpcol->bcp_column_data->datalen = 1 +
> rtrim((char *) bcpcol->bcp_column_data->data + 1,
> bcpcol->bcp_column_data->datalen - 1);
> }
>
> Doesn't that do the trick?
>

???

well, current rtrim implementation should handle correctly this case.
>From CVS

static int
rtrim(char *istr, int ilen)
{
char *t;

for (t = istr + ilen; --t > istr && *t == ' '; )
*t = '\0';
return t - istr + 1;
}

Note that test is --t > istr so t > istr -> first characters is not
considered... The only exeption is where ilen == 0 calling function but
IMO this case should be handled by lower layer.

freddy77




Archive powered by MHonArc 2.6.24.

Top of Page