Skip to Content.
Sympa Menu

freetds - [freetds] dbrpcsend and dbresults..

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Arnar Birgisson" <ArnarB AT oddi.is>
  • To: <freetds AT lists.ibiblio.org>
  • Subject: [freetds] dbrpcsend and dbresults..
  • Date: Wed, 28 May 2003 15:22:48 +0000

Hello..

I have done some testing and found the following inconsistency between
M$ dblib and freetds dblib. In my database there is a procedure,
sp_get_athugasemdir_starfsmanns, which returns four result sets. One or
more of them may be empty. For the parameter value '2704814509', the
result sets contain 0, 1, 2 and 1 lines/tuples, respectively. Here's the
program to execute the procedure:

#include <stdio.h>
#ifdef WIN32
#include <windows.h>
#endif
#include <sqlfront.h>
#include <sqldb.h>

#ifndef SQLCHAR
#define SQLCHAR SYBCHAR
#endif

int err_handler(DBPROCESS*, int, int, int, char*, char*);
int msg_handler(DBPROCESS*, DBINT, int, int, char*, char*, char*,
DBUSMALLINT);

main() {
int i = 0, j = 0;
DBPROCESS *dbproc;
LOGINREC *login;
char *kt = "2704814509";
int retval = -1;

dberrhandle(err_handler);
dbmsghandle(msg_handler);

dbinit();

login = dblogin();
DBSETLUSER(login, "stmkerfi_arnarb");
DBSETLPWD(login, "xxx");
DBSETLAPP(login, "starfsmannakerfi");

dbproc = dbopen(login, "stmdatabase");

dbrpcinit(dbproc, "sp_get_athugasemdir_starfsmanns", 0);
dbrpcparam(dbproc, "@kennitala", 0, SQLCHAR, 10, 10, kt);
dbrpcsend(dbproc);
dbsqlok(dbproc);

while (dbresults(dbproc) == SUCCEED) {
printf("Got resultset %d\n", ++i);
j = 0;
while (dbnextrow(dbproc) != NO_MORE_ROWS) {
printf(" -> line %d\n", ++j);
}
}

dbexit();
return(0);
}

int err_handler (DBPROCESS *dbproc, int severity,
int dberr, int oserr, char *dberrstr, char *oserrstr)
{
printf ("DB-Library Error %i: %s\n", dberr, dberrstr);
if (oserr != DBNOERR)
{
printf ("Operating System Error %i: %s\n",
oserr, oserrstr);
}
return (INT_CANCEL);
}

int msg_handler (DBPROCESS *dbproc, DBINT msgno, int msgstate,
int severity, char *msgtext, char *server,
char *procedure, DBUSMALLINT line)
{
printf ("SQL Server Message %ld: %s\n", msgno, msgtext);
return (0);
}

// end of program

This compiles and links both against freetds libsybdb and microsofts
ntwdblib. When compiled against microsoft's dblib, the output of the
program is as follows:

SQL Server Message 5701: Changed database context to
'starfsmannakerfi'.
Got resultset 1
Got resultset 2
-> line 1
Got resultset 3
-> line 1
-> line 2
Got resultset 4
-> line 1

which is the correct result. However, when the same program is compiled
with freetds' libsybdb, the output is like this:

SQL Server Message 5701: Changed database context to
'starfsmannakerfi'.
SQL Server Message 5703: Changed language setting to us_english.
Got resultset 1
-> line 1
Got resultset 2
-> line 1
-> line 2
Got resultset 3
-> line 1

thus, the empty resultset is simply ignored in the call to dbresults.

Attached is the tdsdump logfile for one run of the test program.

Any help on this is greatly appreciated, since my project depends on
this and I don't want to move to running php on Windows and IIS :oP

Arnar

Attachment: tdsdump
Description: Binary data




Archive powered by MHonArc 2.6.24.

Top of Page