Skip to Content.
Sympa Menu

freetds - RE: [freetds] Freebcp copy into ms sql server fails if field is null

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Lowden, James K" <LowdenJK AT bernstein.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: RE: [freetds] Freebcp copy into ms sql server fails if field is null
  • Date: Wed, 17 Nov 2004 14:14:58 -0500

> From: Thomas A. Lowery
> Sent: Tuesday, November 16, 2004 3:28 PM
>
> My attempts to use freebcp to populate a database table results in
> # Msg 20073, Level 2
> # Attempt to bulk-copy a NULL value into Server column which does not
accept NULL values.
>
> There appears to be problem if any of the columns are null.
>
> Here's a script to demo the problem.

Thomas,

Oy. Thanks for the script. That was a serious bug.

Please try the attached patch, already applied to CVS HEAD.

The basic problem seemed to be in _bcp_read_hostfile:

if (data_is_null) {
bcpcol->bcp_column_data->null_column = 1;
bcpcol->bcp_column_data->datalen = 0;
} else {
+ bcpcol->bcp_column_data->null_column = 0;

The null_column flag of the column descriptor was getting set when the
data were null, but not reset when they weren't. Adding the above line
fixed the problem.

The patch does not apply to the 0.62.x release, because the problem
doesn't exist there. (I haven't tested it, but there's no 'null_column'
field to get wrong.)

We used to encode the nullness of the data in its length. That was
problematic, so now there's a separate field for nullness (although it
looks like 'null_data' might be a better name than 'null_column'). When
the field fell out of synch, your table started receiving nulls.

Regards,

--jkl

-----------------------------------------
The information contained in this transmission may contain privileged and
confidential information and is intended only for the use of the person(s)
named above. If you are not the intended recipient, or an employee or agent
responsible for delivering this message to the intended recipient, any
review, dissemination, distribution or duplication of this communication is
strictly prohibited. If you are not the intended recipient, please contact
the sender immediately by reply e-mail and destroy all copies of the original
message. Please note that we do not accept account orders and/or instructions
by e-mail, and therefore will not be responsible for carrying out such orders
and/or instructions.
If you, as the intended recipient of this message, the purpose of which is to
inform and update our clients, prospects and consultants of developments
relating to our services and products, would not like to receive further
e-mail correspondence from the sender, please "reply" to the sender
indicating your wishes. In the U.S.: 1345 Avenue of the Americas, New York,
NY 10105.

Attachment: bcp.null_fix.diff
Description: bcp.null_fix.diff




Archive powered by MHonArc 2.6.24.

Top of Page