Skip to Content.
Sympa Menu

freetds - RE: [freetds] db-lib does not get PRINT data

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] db-lib does not get PRINT data
  • Date: Thu, 23 Dec 2004 15:14:16 -0000

James,

> dbresults() behaves that way because tds_process_result_tokens()
returns
> SUCCEED rather than NO_MORE_RESULTS after it finds the PRINT output.
> Each function blithely returns the called function's return code, and
> none is willing to say, hey buddy, there're no more results.

Actually, that didn't turn out to be the issue.
I wrote a bare-bones dblibrary program, which I could then compile using
Sybase open-client & freetds.
Here's the bare bones of the program:

result_code = dbcmd(dbproc, "select 1 print 'hi'");
printf("dbcmd result_code = %d\n", result_code);
result_code = dbsqlsend(dbproc);
printf("dbsqlsend result_code = %d\n", result_code);
result_code = dbsqlok(dbproc);
printf("dbsqlok result_code = %d\n", result_code);

while ((result_code = dbresults(dbproc)) == SUCCEED) {
printf("dbresults result_code = %d\n", result_code);
num_cols = dbnumcols(dbproc);
printf("number of columns = %d\n", num_cols);
if ( dbrows(dbproc) == SUCCEED) {
printf("there are rows to process\n");
while ((result_code = dbnextrow(dbproc)) != NO_MORE_ROWS) {
printf("dbnextrow result_code = %d\n", result_code);
}
printf("dbnextrow result_code = %d\n", result_code);
}
}
printf("dbresults result_code = %d\n", result_code);

This yielded the following output, using Sybase open-client:

dbcmd result_code = 1
dbsqlsend result_code = 1
dbsqlok result_code = 1
dbresults result_code = 1
number of columns = 1
there are rows to process
dbnextrow result_code = -1
dbnextrow result_code = -2
Msg 0, Level 0, State 1
Server 'MYSERVER', Line 1
hi
dbresults result_code = 1 <= NOTICE THIS SUCCEED return
after the "print" is processed
number of columns = 0
dbresults result_code = 2

The REAL problem was our (very) old friend of "when to free/initialise
the results structure".
Basically, we are not freeing the res_info data at the correct time. It
hangs around until another results token is read.
Fortunately the new, more "state-driven", dbresults processing allows us
to work out much more easily when it is pertinent to free the results
structures.

I've worked out a patch for this, and our dblibrary behaviour now mimics
Sybase open client.
What's more, all dblibrary unit tests still work (phew!)

I think I'll wait though until after the holidays before giving you the
patch.

Happy Holidays everyone,

Bill
--------------------------------------------------------

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