Skip to Content.
Sympa Menu

freetds - [freetds] porting a windows program

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Thomas Stover <thomas AT wsinnovations.com>
  • To: freetds AT lists.ibiblio.org
  • Subject: [freetds] porting a windows program
  • Date: Tue, 17 Jul 2007 15:50:14 -0500

Hi all. I recently discovered FreeTDS, and hoped someone might be able to help me out. I'm trying to port a win32-msdblib program to linux so that I can debug an unrelated problem with the help of Valgrind. From the comments on the FreeTDS homepage about the best source of documentation being the MS/sybase docs, I figured that a simple msdblib example might be a good place to start. I'm having a few issues with the compile phase. Below is a simple windows-msdblib test program I had lying around, along with my initial efforts to get this sucker to build on Linux. The first problem is that I don't seem to be including the correct header for the PDBPROCESS structure. I looked around in the FreeTDS headers and saw DBPROCESS all over the place, so I tried a "#define PDBPROCESS DBPROCESS" to no avail. The other big thing is that I'm going from the MS doc's version of what error and message handlers should look like. Clearly that part needs some work. Anyway any help pointing me in the right direction would be much appreciate.

#include <stdio.h>
#include <sqlfront.h>
#include <sqldb.h>

int err_handler (PDBPROCESS dbproc, INT severity,
INT dberr, INT oserr, LPCSTR dberrstr, LPCSTR oserrstr)
{
fprintf(stderr, "DB-Library Error %i: %\ns", dberr, dberrstr);
if (oserr != DBNOERR)
fprintf(stderr, "Operating System Error %i: %s\n", oserr, oserrstr);

return INT_CANCEL;
}

int msg_handler (PDBPROCESS dbproc, DBINT msgno, INT msgstate,
INT severity, LPCSTR msgtext, LPCSTR server,
LPCSTR procedure, DBUSMALLINT line)
{
fprintf(stderr, "SQL Server Message %ld: %s\n" , msgno, msgtext);

return 0;
}

int main(void)
{
PDBPROCESS dbproc;
PLOGINREC login;
int ncols, x;
char temp[512];

dberrhandle(err_handler);
dbmsghandle(msg_handler);

dbinit();
login = dblogin();
DBSETLSECURE(login);
DBSETLAPP(login, "dblib experiment program");
dbproc = dbopen(login, "192.168.9.143");

dbcmd(dbproc, "SELECT TOP 1 * From [TestDB] .. TestTable"); dbsqlexec(dbproc);
if(dbresults(dbproc) == SUCCEED)
{
ncols = dbnumcols(dbproc);
dbbind(dbproc, 1, NTBSTRINGBIND, 0, temp);

printf("Colum names:\n");
for(x = 1; x < ncols; x++)
{
printf("%s\t", dbcolname(dbproc, x));
}
printf("\n");

}

dbfreebuf(dbproc);
dbfreelogin(login);
dbexit();
return 0;
}







Archive powered by MHonArc 2.6.24.

Top of Page