[freetds] bcp broken on TDS 5.0

Thompson, Bill D (London) bill_d_thompson at ml.com
Mon Apr 26 06:59:31 EDT 2004


I'm (on and off) testing my ct-library bcp...and I think I may have stumbled
across the problem.
I think it lies in the addition of SYBCHAR into the is_nullable_type() macro
(tds.h , revision 1.165)

For the purposes of building  the sybase bcp data , we have to distinguish
between what the server regards as "fixed" or "variable" length columns

a "fixed" length column is one that is of fixed length by definition (like
an int, float or datetime) and is also defined as NOT NULL on the database.
a "variable" length column is one that is either of variable length by
definition (like varchar), or is of fixed length by definition and defined
as NULL on the database.

In most cases the datatype returned by the server will give us enough
information to be able to distinguish between the two types.
For example a NOT NULL int column will be described to us as a SYBINT4 , and
we know that SYBINT4 is "fixed" length for our purposes.
A NULL int (or smallint or tinyint) is described to us a SYBINTN, and we
know that to be "variable" length for our purposes.
These types can safely participate in either of the is_fixed_type or
is_nullable_type macro's, as applicable.

Unfortunately, for whatever reasons, there isn't a SYBCHARN type (signifying
a NULLable char) - the servers only give us SYBCHAR.

because of this, SYBCHAR (for the purposes of making this distinction in
Sybase bcp, at least) can participate in neither macro, as we have to
examine the NULLable flag returned by the server in order to predicate the

Thus, the current code identifies a "fixed" length column by saying (my
comments prefixed) :

/* column is not of a known variable type, and is not nullable on the
database */
if (!is_nullable_type(bcpcol->db_type) && !(bcpcol->db_nullable)) 

and a variable length column by saying :

/* column is of a known variable type or is nullable on the database
if (is_nullable_type(bcpcol->db_type) || bcpcol->db_nullable) {

I don't know why SYBCHAR was added to the is_nullable_type() macro, but I
assume there was good reason.
It may be that we need to make a similar, but not identical, distinction for
other functionality in our code.

Can you shed any light on this ?


> -----Original Message-----
> From:	James K. Lowden [SMTP:jklowden at schemamania.org]
> Sent:	25 April 2004 01:51
> To:	FreeTDS Development Group
> Subject:	Re: [freetds] bcp broken on TDS 5.0
> On Fri, 23 Apr 2004, "Thompson, Bill D (London)" <bill_d_thompson at ml.com>
> wrote:
> > The bcp data sent down the wire to a Sybase server is an image of a row
> > as it is physically stored within the database
> > It may well be that Sybase have changed how row data is stored in
> > 12/12.5...and that therefore our bcp data is being misinterpreted by the
> > server.
> I just had the *brilliant* insight that it must be FreeTDS's problem.  Let
> us suppose, for a moment, that Sybase did change the TDS format for bcp'd
> rows.  Wouldn't that mean that all Sybase's old bcp utilities would be
> unable to connect and upload rows?  
> I dont' have ribo, but I do have an 11.5 system around here.  I think I'll
> see what tcpdump has to say.  
> --jkl
> _______________________________________________
> FreeTDS mailing list
> FreeTDS at lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/freetds


If you are not an intended recipient of this e-mail, please notify
the sender, delete it and do not read, act upon, print, disclose,
copy, retain or redistribute it.

Click here for important additional terms relating to this e-mail.


More information about the FreeTDS mailing list