Skip to Content.
Sympa Menu

freetds - RE: dbresults...

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Castellano, Nicholas" <Nicholas_Castellano AT acml.com>
  • To: "'TDS Development Group'" <freetds AT franklin.metalab.unc.edu>
  • Subject: RE: dbresults...
  • Date: Fri, 20 Sep 2002 12:13:20 -0400


I think the /* noop */ is your problem...you're expected to call dbnextrow()
in an inner loop until it returns NO_MORE_ROWS. See the example code in the
Sybase man page you quote.

I put all the remaining processing inside a loop, and it appears to behave
fine (see below).

It's common practice (although arguably not a good idea) to do away with
these loops if you "know" in advance how many result sets you will get and
how many rows will be returned.

If the problem you're describing goes deeper than this, then please explain.
As it is, the current behavior seems fine to me.

Cheers,
--nick


while (dbresults(dbproc) != NO_MORE_RESULTS)
{

add_bread_crumb();

for (i=1;i<=dbnumcols(dbproc);i++)
{
add_bread_crumb();
printf ("col %d is %s\n",i,dbcolname(dbproc,i));
add_bread_crumb();
}

add_bread_crumb();
if (SUCCEED != dbbind(dbproc,1,INTBIND,-1,(BYTE *) &testint))
{
failed = 1;
fprintf(stderr, "Had problem with bind\n");
abort();
}
add_bread_crumb();
if (SUCCEED != dbbind(dbproc,2,STRINGBIND,-1,(BYTE *) teststr))
{
failed = 1;
fprintf(stderr, "Had problem with bind\n");
abort();
}
add_bread_crumb();

add_bread_crumb();

for(i=0; i<rows_to_add; i++)
{
char expected[1024];
sprintf(expected, "row %03d", i);

add_bread_crumb();
teststr[0] = 0;
if (REG_ROW != dbnextrow(dbproc))
{
failed = 1;
fprintf(stderr, "Failed. Expected a row\n");
exit(1);
}
add_bread_crumb();
if (testint!=i)
{
failed = 1;
fprintf(stderr, "Failed. Expected i to be %d, was %d\n", i,
(int)testint);
abort();
}
if (0!= strncmp(teststr, expected, strlen(expected)))
{
failed = 1;
fprintf(stdout, "Failed. Expected s to be |%s|, was |%s|\n",
expected, teststr);
abort();
}
printf("Read a row of data -> %d %s\n", (int)testint, teststr);
}


add_bread_crumb();
if (dbnextrow(dbproc)!=NO_MORE_ROWS)
{
failed = 1;
fprintf(stderr, "Was expecting no more rows\n");
exit(1);
}
}

-----Original Message-----
From: bounce-freetds-145195 AT franklin.oit.unc.edu
[mailto:bounce-freetds-145195 AT franklin.oit.unc.edu]
Sent: Friday, September 20, 2002 9:58 AM
To: TDS Development Group
Subject: [freetds] dbresults...


Hi,

I've spotted something, whilst researching how to implement the compute
columns functionality.

In dblibrary, after a dbsqlexec() thats going to return data, if we do more
than one call to dbresults(), things go wrong.

try changing the relevant code in dblib/unittests/t0001.c to:

fprintf(stdout, "select\n");
dbcmd(dbproc,"select * from #dblib0001 order by i");
dbsqlexec(dbproc);
add_bread_crumb();


while (dbresults(dbproc) != NO_MORE_RESULTS)
{
/* noop */
}
add_bread_crumb();

for (i=1;i<=dbnumcols(dbproc);i++)
....

and see what happens (especially in the tdsdump!)

The sybase manual for dbresults says:

"To ensure that dbresults is called the correct number of times, Sybase
strongly recommends that dbresults always be called in a loop that
terminates when dbresults returns NO_MORE_RESULTS."

I've dabbled in token.c before, and will take a look at how to fix this, but
if anyone more experienced gets to the answer quicker than me (not
difficult) let me know.

Bill

---
You are currently subscribed to freetds as: [Nicholas_Castellano AT acml.com]
To unsubscribe, forward this message to
$subst('Email.Unsub')


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 for certain accounts we do not accept
orders and/or instructions by e-mail, and for those accounts we will not be
responsible for carrying out such orders and/or instructions. Kindly refrain
from sending orders or instructions by e-mail unless you have confirmed that
we accept such communications for your account. Please also note that to
satisfy regulatory requirements we review the outgoing and incoming e-mail
correspondence of staff members serving certain functions.






Archive powered by MHonArc 2.6.24.

Top of Page