Skip to Content.
Sympa Menu

freetds - RE: [freetds] dbbind, dbnullbind issues

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Thompson, Bill D (London)" <bill_d_thompson AT ml.com>
  • To: "'FreeTDS Development Group'" <freetds AT lists.ibiblio.org>
  • Subject: RE: [freetds] dbbind, dbnullbind issues
  • Date: Wed, 16 Jun 2004 10:02:38 +0100

Thanks for your analysis James.

> I loaded your results into a database ...

Do you ever find youself incapable of thinking about anything except in
relational terms :-) ?

Here's what my version of the code does with the same scenarios

bindtype = NTBSTRINGBIND bindlen = 12 data = >1234567890< ind = 0
bindtype = NTBSTRINGBIND bindlen = 11 data = >1234567890< ind = 0
bindtype = NTBSTRINGBIND bindlen = 10 data = >123456789< ind = 11
bindtype = NTBSTRINGBIND bindlen = 5 data = >1234< ind = 11
bindtype = NTBSTRINGBIND bindlen = 0 data = >1234567890< ind = 0
bindtype = NTBSTRINGBIND bindlen = -1 data = >1234567890< ind = 0

bindtype = STRINGBIND bindlen = 12 data = >1234567890 < ind = 0
bindtype = STRINGBIND bindlen = 11 data = >1234567890< ind = 0
bindtype = STRINGBIND bindlen = 10 data = >123456789< ind = 11
bindtype = STRINGBIND bindlen = 5 data = >1234< ind = 11
bindtype = STRINGBIND bindlen = 0 data = >1234567890< ind = 0
bindtype = STRINGBIND bindlen = -1 data = >1234567890< ind = 0

bindtype = CHARBIND bindlen = 12 data = >1234567890 @@@@@@@@< ind =
0
bindtype = CHARBIND bindlen = 11 data = >1234567890 @@@@@@@@@< ind =
0
bindtype = CHARBIND bindlen = 10 data = >1234567890@@@@@@@@@@< ind =
0
bindtype = CHARBIND bindlen = 5 data = >12345@@@@@@@@@@@@@@@< ind = 10
bindtype = CHARBIND bindlen = 0 data = >1234567890@@@@@@@@@@< ind = 0
bindtype = CHARBIND bindlen = -1 data = >1234567890@@@@@@@@@@< ind =
0

bindtype = VARYCHARBIND bindlen = 12 data = >1234567890@@@@@@@@@@< len =
10 ind = 0
bindtype = VARYCHARBIND bindlen = 11 data = >1234567890@@@@@@@@@@< len =
10 ind = 0
bindtype = VARYCHARBIND bindlen = 10 data = >1234567890@@@@@@@@@@< len =
10 ind = 0
bindtype = VARYCHARBIND bindlen = 5 data = >12345@@@@@@@@@@@@@@@< len =
5 ind = 10
bindtype = VARYCHARBIND bindlen = 0 data = >1234567890@@@@@@@@@@< len =
10 ind = 0
bindtype = VARYCHARBIND bindlen = -1 data = >1234567890@@@@@@@@@@< len =
10 ind = 0

Let me explain what I've done with NTBSTRINGBIND and STRINGBIND

NTBSTRINGBIND right trims any spaces from the character string. Both add a
NULL terminator to the data.

You are supposed to have enough bound space to hold the data and the null
terminator.

This is what makes varlen = 10 interesting (well, if you don't have a life
that is :-) )
Its fine for CHARBIND and VARYCHARBIND which don't add a null terminator.
My version of NTBSTRINGBIND and STRINGBIND report truncation because there
isn't enough space for the data + the null term.

NTBSTRINGBIND only checks for truncation AFTER the removal of the trailing
blanks.
Otherwise it might report POTENTIAL truncation when in fact no truncation
has really occurred.

Does this look good to you ?

Bill



> -----Original Message-----
> From: James K. Lowden [SMTP:jklowden AT schemamania.org]
> Sent: 16 June 2004 07:01
> To: FreeTDS Development Group
> Subject: Re: [freetds] dbbind, dbnullbind issues
>
> On Tue, 15 Jun 2004, "Thompson, Bill D (London)" <bill_d_thompson AT ml.com>
> wrote:
>
> > I think I've reached a kind of understanding of what is happening, by
> > some extensive testing.
>
> Thanks for doing this, Bill. Very thorough work.
>
> > I've got a table with a single row and a single column - char(10) -
> > with data '1234567890' in it...
>
> I mean, really, you've been working too hard or something. That's the
> most boring data imaginable.
>
> I loaded your results into a database and found this:
>
> [25] varley.FreeTDS.1> select count(*), bindlen, ind from bind_results
> group by bindlen, ind order by bindlen, ind
> [25] varley.FreeTDS.2> go
> bindlen ind
> ----------- ------- ------
> 2 -1 0
> 2 -1 10
> 3 0 0
> 1 0 10
> 4 5 10
> 4 10 0
> 4 11 0
> 4 12 0
>
> (8 rows affected)
>
> By the book, bindlen (varlen) of -1 should never work. If we don't reject
> it outright, we should treat it as 0, never mind what Sybase does. I
> note, ahem, that bsqldb uses -1. So much for setting a good example.
>
> varlen of 0 appears broken in the case of STRINGBIND:
>
> [27] varley.FreeTDS.1> select * from bind_results where bindlen = 0 order
> by len, ind, type
> [27] varley.FreeTDS.2> go
> type bindlen data len ind
> -------------------- ------- ------------------------- ------ ------
> CHARBIND 0 >1234567890@@@@@@@@@@< NULL 0
> NTBSTRINGBIND 0 >1234567890< NULL 0
> STRINGBIND 0 >1234567890< NULL 10
> VARYCHARBIND 0 >1234567890@@@@@@@@@@< 10 0
>
> The dbnullbind() indicator should be >0 only to indicate truncation.
> Because a varlen of 0 passes no information about the buffer's size,
> db-lib can't possibly know where to truncate the data, nor does it
> truncate them.
>
> IMO this is a case for "do it right and let 'em complain". Any
> application relying on STRINGBIND's broken behavior is itself broken.
>
> varlen of 5 seems fine. It puts lie to the dbnullbind() note "Detection
> of character string truncation is implemented only for CHARBIND and
> VARYCHARBIND."
>
> varlen of 10 is interesting:
>
> [28] varley.FreeTDS.1> select * from bind_results where bindlen = 10 order
> by len, ind, type
> [28] varley.FreeTDS.2> go
> type bindlen data len ind
> -------------------- ------- ------------------------- ------ ------
> CHARBIND 10 >1234567890@@@@@@@@@@< NULL 0
> NTBSTRINGBIND 10 >123456789< NULL 0
> STRINGBIND 10 >123456789< NULL 0
> VARYCHARBIND 10 >1234567890@@@@@@@@@@< 10 0
>
> CHARBIND and VARYCHARBIND *could* report truncation, but in this case no
> truncation occurs and is thus not reported.
>
> > In the light of this, I'm not going to populate the indicator variables
> > at all for NTBSTRINGBIND and STRINGBIND, as there seems to be no logic
> > to the observable behaviour.
>
> NTBSTRINGBIND and STRINGBIND should but don't report truncation (but the
> note says that's not "implemented"). Here again, ISTM we can and should
> report the truncation. There's no need to replicate Sybase's off-by-one
> error. We'll only be making this case consistent with the varlen 5 case.
>
>
> (I suppose one could argue the documentation is right even without the
> note. Truncation is reported if the binding "did not specify any data
> conversions". If tacking a NULL onto the data is "conversion", then
> truncation won't be reported.... But you won't hear *me* making that
> case.)
>
> Two questions for you, if I may:
>
> 1. Does dbnullbind() at least report NULLs correctly?
> 2. Does dbanullbind() show similar inconsistencies?
>
> Regards,
>
> --jkl
>
>
> > > -----Original Message-----
> > > From: Lowden, James K [SMTP:LowdenJK AT bernstein.com]
> > > Sent: 15 June 2004 15:13
> > > To: FreeTDS Development Group
> > > Subject: RE: [freetds] dbbind, dbnullbind issues
> > >
> > > > From: freetds-bounces AT lists.ibiblio.org
> > > > [mailto:freetds-bounces AT lists.ibiblio.org]On Behalf Of
> > > > Thompson, Bill D
> > > >
> > > > I've been wrestling with the features of dbbind and
> > > > dbnullbind
> > > ...
> > > > I could do several things:
> > > >
> > > > 1) code our dblibrary funstions so that they behave as
> > > > specified in the manual pages.
> > > > 2) attempt to reflect the actual (but inconsistent) behaviour
> > > > of the Sybase implementation
> > > > 3) code to a different, but clearer and arguably more sensible,
> > > > specification.
> > >
> > > Hi Bill,
> > >
> > > Can you cite an example where someone following the letter of the
> > > documentation would build a non-working application when linking to
> > > one of the vendors' libraries?
> > >
> > > In general, I'm sure you agree that adhering to the documents is best.
> > > Bug-for-bug compatibility is useful in two cases:
> > >
> > > 1. Following the docs doesn't actually work.
> > > 2. Binary compatibility.
> > >
> > > The first case is truly bad, and I don't know of any examples. The
> > > second is a far-off goal; we'll cross that bridge when we come to it,
> > > IMO.
> > >
> > > The other kind of not-of-the-docs behavior are things that work but
> > > aren't documented to work, things like using varlen of -1 that you
> > > found. I think it's fine to support them when it's convenient, and
> > > deny them when not. Anyone who complains can fix his code or change
> > > ours.
> > >
> > > Is that any help?
> > >
> > > --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.
> > >
> > >
> > > _______________________________________________
> > > 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.
> > <http://www.ml.com/email_terms/>
> >
> > =======================================================================
> > =======
> >
> > _______________________________________________
> > FreeTDS mailing list
> > FreeTDS AT lists.ibiblio.org
> > http://lists.ibiblio.org/mailman/listinfo/freetds
> _______________________________________________
> 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.
<http://www.ml.com/email_terms/>

==============================================================================





Archive powered by MHonArc 2.6.24.

Top of Page