Skip to Content.
Sympa Menu

freetds - [freetds] bp with empty char/varchar column broken

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Craig A. Berry" <craigberry AT mac.com>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: [freetds] bp with empty char/varchar column broken
  • Date: Thu, 20 Nov 2014 13:53:40 -0600

The following worked in 0.91 but is broken as of branch-0_92-839-gd788046.
If we bulk out a table with an empty (but not NULL) char or varchar column
that is less than 256 bytes long, 256 spaces get written to the output file
for that column. Which then causes an overflow error if you try to bulk it
back in.

I think it was e30a807 that broke it because in src/dblib/bcp.c:_bcp_exec_out
we now pass a minimum of 256 as the destlen argument to dbconvert. We used
to pass -2, instructing dbconvert to null terminate without copying anything.

I'm not sure what the correct fix is. We could possibly pass the lesser of
source length and destination length to dbconvert in _bcp_exec_out.

Here's a reproducer:

$ ./fisql/fisql -Smyserver -Utest
Password:
Changed database context to 'master'.
Changed language setting to us_english.
1>> use tempdb
2>> go
Changed database context to 'tempdb'.
1>> create table testbcp (tmpval varchar(10))
2>> go
1>> insert into testbcp values ('abc')
2>> go
(1 rows affected)
1>> insert into testbcp values ('')
2>> go
(1 rows affected)
1>> exit
$ ./freebcp tempdb.dbo.testbcp out tmp.bcp -Smyserver -Utest -P***** -c

Starting copy...
2 rows copied.
$ perl -nle 'print length($_);' < tmp.bcp
3
256
$ ./freebcp tempdb.dbo.testbcp in tmp.bcp -Smyserver -Utest -P***** -c

Starting copy...
Msg 20049, Level 4
Data conversion resulted in overflow

1 rows copied.

________________________________________
Craig A. Berry
mailto:craigberry AT mac.com

"... getting out of a sonnet is much more
difficult than getting in."
Brad Leithauser





Archive powered by MHonArc 2.6.24.

Top of Page