[freetds] freebcp out from MS SQL Server drops spaces [C1]

James K. Lowden jklowden at freetds.org
Mon Jul 6 22:33:46 EDT 2009


Cedric ROUVRAIS wrote:
> 
> 
> We have several views that we use to format files that have to be sent
> to external applications and we have an issue that we have been unable
> to resolve. The Free BCP command drop trailing spaces (or inserts tabs)
> which mucks up the file.
> 
> Usually what we do (with Sybase and MS SQL bcp it works just fine), is
> 
>       bcp dbInstance.dbUser.dbView out formattedFile.dat -c -t"" ...

freebcp as a report writer?  Learn something new every day!  ;-)

You could modify bcp.c::_bcp_exec_out (line 728).  Change the fwrite to
pad character columns with spaces.  

bsqldb *almost* does what you want.  It puts two spaces between columns,
though.  If you use any other delimiter, it doesn't pad character data.  

I think what you want is sqsh.  The -s option lets you set the column
separator.  

You bring up an interesting philosophical point: are trailing spaces data?
 IMO, no, they're not, and freebcp is correct not to pad character data. 
Evidently the authors of bcp thought otherwise, hence the tiny
incompatibility.  

HTH.  

--jkl


More information about the FreeTDS mailing list