Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comments in format files

Is it possible to add comments to the non-XML bcp/BULK INSERT format files?

This would be very helpful in scenarios where these files are treated as declarative code--because, well, code needs comments.

Haven't tried anything yet, because I'd just be throwing random chars with possible unforeseen after-effects.

A definitive "no" would be an acceptable answer.

like image 903
Marc L. Avatar asked Nov 21 '25 22:11

Marc L.


2 Answers

I think the closest to a definitive negative answer is the fact that there is neither a single mention of comments in the documentation nor any examples. I guess there is a specification somewhere in the archives at Microsoft, but it doesn't seem to be available online.

The clearest definition of the non-xml format I've seen is this image (taken from Structure of Non-XML Format Files):

Structure of Non-XML Format Files

For me that is proof enough that comments are not a part of the format and the answer to your question is NO.

As pointed out in the comment by Katherine Elizabeth Lightsey using the newer XML-based format files might be a better, more flexible option, with the added bonus that the XML-format is pretty much self-describing.

like image 72
jpw Avatar answered Nov 23 '25 14:11

jpw


Not allowing comments in the format file is only the 47th most miserable thing about bcp.

I needed this too, and as my workflow was already using a wrapper script, a small bit of PowerShell easily filters the documented format file into a temporary one that bcp would accept:

...
Get-Content $commentedformatfile |
    Where-Object { -Not $_.StartsWith("#") } |
    Set-Content "_temp.fmt"
...
bcp ... -f _temp.fmt ...

This simple mechanism only supports comments via a # character at the start of a line, but it was entirely suitable for me.

Note that bcp barfs on even a blank line so you still have to pay attention.

like image 27
Steve Friedl Avatar answered Nov 23 '25 16:11

Steve Friedl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!