Skip to Content.
Sympa Menu

freetds - [freetds] bcp broken

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "James K. Lowden" <jklowden AT freetds.org>
  • To: TDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: [freetds] bcp broken
  • Date: Wed, 21 Nov 2007 01:40:36 -0500

bcp is broken for NULL character data. I don't know when that happened or
if it ever worked. Our unit test is more of a smoke test; it doesn't
ensure the data make a happy round trip.

Unfortunately, things go wonky on the way in. I added a query to the unit
test that groups and counts the values for three columns. There should be
only 2 distinct values: the test data value, and NULL. Alas:

col nrows len value
---------------- ----------- ----------- ----------
nullable_char 1 NULL NULL
nullable_char 1 1 a
nullable_char 10 4
nullable_char 5 6 a char
nullable_int 11 NULL NULL
nullable_int 6 4 1234
nullable_varchar 1 NULL NULL
nullable_varchar 1 1 a
nullable_varchar 10 4
nullable_varchar 5 9 a varchar

The only NULL values in the char/varchar columns were inserted by an
INSERT statement in the test.

The 10 rows of length 4 should be NULL, just as with the integer column.

Extraction is no better, though. If you run src/dblib/unittests/bpc.c in
gdb and stop it before it drops its table, then do:

$ freebcp all_types_bcp_unittest out \
all_types_bcp_unittest.dat -c -t\\ -S [...]
and
$ sed -ne 3p all_types_bcp_unittest.dat

1\a char \a varchar\2003-12-17 15:44:00.000\2003-12-17
15:44:00.000\12.34\12.34\12.34\12.34\12.34\12.34\1234\1234\123\\\\\\\\\\\
\\

$ sed -ne 3p all_types_bcp_unittest.dat | hexdump -C
00000000 31 5c 61 20 63 68 61 72 20 20 20 20 5c 61 20 76 |1\a char
\a v|
00000010 61 72 63 68 61 72 5c 32 30 30 33 2d 31 32 2d 31
|archar\2003-12-1|
00000020 37 20 31 35 3a 34 34 3a 30 30 2e 30 30 30 5c 32 |7
15:44:00.000\2|
00000030 30 30 33 2d 31 32 2d 31 37 20 31 35 3a 34 34 3a |003-12-17
15:44:|
00000040 30 30 2e 30 30 30 5c 31 32 2e 33 34 5c 31 32 2e
|00.000\12.34\12.|
00000050 33 34 5c 31 32 2e 33 34 5c 31 32 2e 33 34 5c 31
|34\12.34\12.34\1|
00000060 32 2e 33 34 5c 31 32 2e 33 34 5c 31 32 33 34 5c
|2.34\12.34\1234\|
00000070 31 32 33 34 5c 31 32 33 5c 00 00 00 00 5c 00 00
|1234\123\....\..|
^^^^^^^^^^^
00000080 00 00 5c 5c 5c 5c 5c 5c 5c 5c 5c 5c 5c 0a
|..\\\\\\\\\\\.|

Those NULLs don't belong there. Nulls are represented by adjacent
separators.

I tried to compare my results to the output of Sybase's bcp utility, but
that's another story.

--jkl




Archive powered by MHonArc 2.6.24.

Top of Page