Skip to Content.
Sympa Menu

freetds - RE: [freetds] dblib program

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] dblib program
  • Date: Tue, 5 Aug 2003 10:55:55 -0400

> From: Thompson, Bill D (London) [mailto:ThompBil AT exchange.uk.ml.com]
> Sent: August 5, 2003 5:45 AM
>
> 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.
...
> 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

Well done, Bill.

Perhaps an elaborate form of (b). In sybdb.h:

#define DBCONVERT_OUT_BLANK_NULL = -1
#define DBCONVERT_OUT_NOBLANK_NULL = -2
#define DBCONVERT_OUT_NOBLANK_NONULL = -3

Then buffer_transfer_bound_data() becomes:

switch (curcol->column_bindtype) {
case STRINGBIND:
destlen = DBCONVERT_OUT_NOBLANK_NULL;
break;
case NTBSTRINGBIND:
destlen = DBCONVERT_OUT_BLANK_NULL;
break;
default:
if (curcol->column_bindlen == 0)
destlen = DBCONVERT_OUT_NOBLANK_NONULL;
else
destlen = curcol->column_bindlen;
break;
}

and dbconvert() of course follows suit.

This way we don't have to keep looking up what -1 means, and if Sybase
decides to use -3 for something, we can redefine
DBCONVERT_OUT_NOBLANK_NONULL. We avoid writing specialized code and make
dbconvert() slightly more flexible. It would be considerable more work to
call tds_convert() instead.

--jkl


> > > 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);
> > > }
> > > }
-----------------------------------------
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.






Archive powered by MHonArc 2.6.24.

Top of Page