Skip to Content.
Sympa Menu

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

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Frediano Ziglio <freddy77 AT gmail.com>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] bp with empty char/varchar column broken
  • Date: Fri, 21 Nov 2014 11:58:07 +0000

2014-11-20 19:53 GMT+00:00 Craig A. Berry <craigberry AT mac.com>:
> 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.
>

Quite strange. Why does it happen only for empty strings? Should even
happen with small ones. The function has to pad or not based on type.
Actually is not clear to me what an empty column should look like in
the text bcp file.

Frediano

> 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
>
> _______________________________________________
> FreeTDS mailing list
> FreeTDS AT lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/freetds




Archive powered by MHonArc 2.6.24.

Top of Page