freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
- From: "Thompson, Bill D (London)" <ThompBil AT exchange.uk.ml.com>
- To: "'FreeTDS Development Group'" <freetds AT lists.ibiblio.org>
- Subject: RE: [freetds] dblib program
- Date: Tue, 5 Aug 2003 10:45:04 +0100
OK,
I know what causes the error, but it may require some care to solve it.,
It's definitely a bug, though.
basically in the function buffer_transfer_bound_data() in dblib.c (this
being the finction which transfers data from our internal buffer to any
bound variables), we say the following:
/* FIXME use also curcol->column_bindlen,
* for CHARBIND, curcol->column_bindlen < 0 use srclen
* check limit for other bind types */
switch (curcol->column_bindtype) {
case STRINGBIND:
destlen = -2;
break;
case NTBSTRINGBIND:
destlen = -1;
break;
default:
if (curcol->column_bindlen == 0) <-- This is the problem
destlen = -1; <-- This is the
problem
else
destlen = curcol->column_bindlen;
break;
}
dbconvert(dbproc, srctype, /* srctype */
src, /* src */
srclen, /* srclen */
desttype, /* desttype */
(BYTE *) curcol->column_varaddr, /* dest */
destlen); /* destlen */
The "destlen" we set to -1 , if the bindlen passed via dbbind() was 0.
This "destlen" gets passed to dbconvert().
Unfortunately a destlen of -1 is instructing dbconvert to add a terminating
NULL to the converted data (which of course ends up overwriting some of your
program storage)
I suppose the problem really lies in our use of dbconvert() to do the work
of physically copying the data to the target variables.
dbconvert has it's external specification which we should stick to, but its
not *quite* flexible enough for our needs.
It has these two special "destlen" values -1 & -2 which specify special
behaviours. Unfortunately neither of these is quite what we need.
Some alternatives are to :
a) replace the call to dbconvert with bespoke code (most of which would be
pulled from dbconvert() ) - bad IMHO
b) add a third special "destlen" value to dbconvert - a bit of work, but too
bad a solution IMHO
Another workaround for you would be to call dbbind as follows:
dbbind(dbproc, 2, CHARBIND, (DBINT)1, (BYTE*) &family);
HTH,
Bill
> -----Original Message-----
> From: James K. Lowden [SMTP:jklowden AT schemamania.org]
> Sent: 05 August 2003 00:03
> To: FreeTDS Development Group
> Subject: Re: [freetds] dblib program
>
> On Mon, 4 Aug 2003 11:28:34 -0600 (MDT), "Steven J. Backus"
> <backus AT math.utah.edu> wrote:
> > I have reduced my dblib problem considerably and even have a
> > workaround, so if you can't replicate it, or fix it, I'm ok. Still, I
> > would like to make freetds better, so I'm sending this off with
> > great hope.
>
> Thanks for boiling it down, Steven. It may be there's a problem with
> DBCHAR binding. It deserves scrutiny; there are many opportunities in
> that code for off-by-one errors.
> --jkl
>
> >
> > First the table def:
> >
> > create table table1
> > (i1 varchar(4) null,
> > family varchar(1) null)
> > go
> >
> > Then the insert statement:
> >
> > insert into table1(i1, family) values ('I64', 'Y');
> >
> > Now the program:
> >
> > main(int argc, char** argv) {
> > DBPROCESS *dbproc;
> > LOGINREC *login;
> > DBCHAR i1[5], family;
> >
> > ...
> >
> > dbcmd(dbproc, "select i1, family from table1 ");
> > dbsqlexec(dbproc);
> > if(dbresults(dbproc) == SUCCEED) {
> > dbbind(dbproc, 1, STRINGBIND, (DBINT)0, (BYTE*) i1);
> > dbbind(dbproc, 2, CHARBIND, (DBINT)0, (BYTE*) &family);
> >
> > dbnextrow(dbproc);
> > printf("%s\n", i1);
> > }
> > }
> >
> > In its present state, the program prints nothing. However, if I
> > change family to a string:
> >
> > DBCHAR i1[5], family[2];
> >
> > and bind it thus:
> >
> > dbbind(dbproc, 2, STRINGBIND, (DBINT)0, (BYTE*) family);
> >
> > The printf works and spits out I64. Thank you one and all for your
> > time and consideration. Let me know if I can provide further
> > clues.
> >
> > Steven
> > _______________________________________________
> > 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
-
[freetds] dblib program,
Steven J. Backus, 08/04/2003
- Re: [freetds] dblib program, James K. Lowden, 08/04/2003
- <Possible follow-up(s)>
- RE: [freetds] dblib program, Thompson, Bill D (London), 08/05/2003
- RE: [freetds] dblib program, Lowden, James K, 08/05/2003
Archive powered by MHonArc 2.6.24.