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

ZIGLIO, Frediano, VF-IT Frediano.Ziglio at vodafone.com
Tue Dec 20 03:49:01 EST 2005


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


More information about the FreeTDS mailing list