Open liquidaty opened 3 months ago
That's weird that this happens only with computed columns!
The issue here is that freebcp
uses DB-library which, for compatibility, use the old settings.
bulk.c
is not the right place to change these defaults, I think a better option would be in freebcp
itself. You don't want to mess around with possible other options set by the user. To my surprise there's no option for our DB-library to say "I'm an ODBC driver" (it could sounds weird, but it's be way to have current options during the login which is the default of libTDS but turned off by DB-library).
The core issue here stems from default ANSI_NULLS and other options that are incompatible with bulk copy into tables with computed columns. Providing a means to change these from their current defaults is the only way to allow copy into a table with computed columns (see https://learn.microsoft.com/en-us/sql/t-sql/statements/set-ansi-nulls-transact-sql?view=sql-server-ver16)
To reproduce:
Create a DB table with one or more calculated columns e.g.:
Create a test file:
Attempt to BCP:
This gives the following message, including the inaccurate one about a row being copied (in reality, no rows are copied):
Solution:
This issue can be solved using free-form SET commands:
Proposed change:
Although a workaround as shown above can be used, it would be better if these settings a) were default and b) could be modified in a manner similar to the bcp_control KEEPIDENTITY option. I would be happy to contribute a pull request reflecting the above. I would be happy to submit a PR if helpful