[freetds] bcp CHAR behavior

Michael Peppler mpeppler at peppler.org
Fri Apr 16 10:53:02 EDT 2004

On Thu, 2004-04-15 at 19:41, James K. Lowden wrote:
> src/dblib/bcp.c:1107:
> if (desttype == SYBVARCHAR) {
>     bcpcol->data_size = 
> 	_bcp_rtrim_varchar((char *) bcpcol->data, converted_data_size);
> } else {
>     bcpcol->data_size = converted_data_size;
> }
> I ran across what might be a little bug in the above code today.  I was
> loading a tab-delimited file; column two in the table was a char(2).

FYI - here's what Sybase's bcp does:

create table fts_char(c1 char(20), c2 varchar(20));

cat /tmp/fts_char.bcp
ABC             CDE

Actual data getting sent (checked via Ribo)

Raw PDU Data
  Unformatted Contents [64]:   

Note that the char(20) column is *padded* to the correct width, while
the varchar() column is trimmed. I suspect that you will have to become
a little more precise for char() columns, and either pad or truncate as
needed to match the target column's width.

I've got the full Ribo trace of the session, if you want.

Michael Peppler                              Data Migrations, Inc.
mpeppler at peppler.org                       http://www.peppler.org/
Sybase T-SQL/OpenClient/OpenServer/C/Perl developer available for short or 
long term contract positions - http://www.peppler.org/resume.html

More information about the FreeTDS mailing list