freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
- From: Craig Davison <cd AT securityfocus.com>
- To: freetds AT lists.ibiblio.org
- Subject: [freetds] Possible problem with ODBC
- Date: Thu, 6 Feb 2003 14:57:16 -0700
Hi again,
Is it possible to have two queries executing at once with the freetds ODBC
driver? I've made a small test program that attempts this and it does not
seem to work. (Change "user", "password" and "mydb" in main() to
appropriate values to run)
The program is attached. It creates a statement handle and selects from
the master..sysusers table. For each row returned, it performs another
query. (Note that the program doesn't do anything useful at all, but the
code should be legal).
The "inner" SQLExecDirect returns -1 and SQLGetDiagRec provides no
further details. I'm using 0.61rc1 on a RedHat 8 (x86) client, with an MS
SQL Server 2000 server. My ODBC driver manager is UnixODBC 2.2.2.
It could be that I've got some major oversight happening, as I'm still new
to ODBC, but I can't seem to figure out why this isn't working.
Thanks!
--
Craig Davison
Symantec Corporation
+1 (403) 213-3939 ext. 228
#include <stdio.h>
#include <sql.h>
#include <sqlext.h>
#include <sqltypes.h>
int CheckSQLHandle (SQLSMALLINT SQLHandleType, SQLHSTMT hStmt, long erg,
const char *pDesc)
{
SQLINTEGER SQLerr;
SQLSMALLINT SQLmsglen;
char pStatus[10], pMsg[101];
long erg2;
if (erg != SQL_SUCCESS && erg != SQL_SUCCESS_WITH_INFO)
{
fprintf(stderr, "Error %s %ld\n", pDesc, erg);
erg2 = SQLGetDiagRec(SQLHandleType, hStmt,1,
pStatus,&SQLerr,pMsg,100,&SQLmsglen);
if (erg2 == SQL_SUCCESS || erg == SQL_SUCCESS_WITH_INFO)
{
fprintf(stderr, "%s (%d)\n",pMsg,(int)SQLerr);
}
return -1;
}
return 0;
}
int TryStuff (SQLHDBC hOdbc)
{
SQLHSTMT hStmt;
SQLINTEGER SQLerr, SQLid;
long erg;
SQLAllocHandle(SQL_HANDLE_STMT, hOdbc, &hStmt);
SQLBindCol(hStmt, 1, SQL_C_SLONG, &SQLid, sizeof(SQLINTEGER),
&SQLerr);
erg = SQLExecDirect(hStmt, "SELECT uid FROM master..sysusers",
SQL_NTS);
if (CheckSQLHandle (SQL_HANDLE_STMT, hStmt, erg, "outer
SQLExecDirect"))
{
SQLFreeHandle(SQL_HANDLE_STMT, &hStmt);
return -1;
}
erg = SQLFetch(hStmt);
while(erg != SQL_NO_DATA && erg != SQL_ERROR)
{
SQLHSTMT hAddrStmt;
SQLINTEGER SQLaddress;
char pQuery[501];
long erg2;
SQLAllocHandle(SQL_HANDLE_STMT, hOdbc, &hAddrStmt);
SQLBindCol(hAddrStmt, 1, SQL_C_SLONG, &SQLaddress,
sizeof(SQLINTEGER), &SQLerr);
sprintf (pQuery, "SELECT uid FROM master..sysusers where
uid=1234");
fprintf (stderr, "%s\n", pQuery);
erg2 = SQLExecDirect(hAddrStmt, pQuery, SQL_NTS);
if (CheckSQLHandle (SQL_HANDLE_STMT, hAddrStmt, erg2, "inner
SQLExecDirect"))
{
SQLFreeHandle(SQL_HANDLE_STMT, &hAddrStmt);
return -1;
}
erg2 = SQLFetch (hAddrStmt);
while (erg2 != SQL_NO_DATA && erg2 != SQL_ERROR)
{
erg2 = SQLFetch (hAddrStmt);
}
if (erg2 == SQL_ERROR && CheckSQLHandle (SQL_HANDLE_STMT,
hAddrStmt, erg2, "inner SQLFetch"))
{
SQLFreeStmt (hAddrStmt, SQL_CLOSE);
SQLFreeHandle(SQL_HANDLE_STMT, &hAddrStmt);
return -1;
}
SQLFreeStmt (hAddrStmt, SQL_CLOSE);
erg = SQLFetch(hStmt);
}
if (erg == SQL_ERROR && CheckSQLHandle (SQL_HANDLE_STMT, hStmt, erg,
"outer SQLFetch"))
{
SQLFreeStmt (hStmt, SQL_CLOSE);
SQLFreeHandle(SQL_HANDLE_STMT, &hStmt);
return -1;
}
SQLFreeStmt(hStmt, SQL_CLOSE);
SQLFreeHandle(SQL_HANDLE_STMT, &hStmt);
return 0;
}
int main (int argc, char **argv)
{
SQLHENV hEnv;
SQLHDBC hOdbc;
long erg;
int err;
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv);
SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);
SQLAllocHandle(SQL_HANDLE_DBC, hEnv, &hOdbc);
/* connect to the database */
erg = SQLConnect(hOdbc, (SQLCHAR*) "mydb", SQL_NTS,
(SQLCHAR*) "user", SQL_NTS,
(SQLCHAR*) "password", SQL_NTS);
if (CheckSQLHandle (SQL_HANDLE_DBC, hOdbc, erg, "Database Connect"))
{
SQLFreeHandle(SQL_HANDLE_DBC, &hOdbc);
SQLFreeHandle(SQL_HANDLE_ENV, &hEnv);
return 0;
}
err = TryStuff (hOdbc);
if (err < 0)
{
SQLDisconnect(hOdbc);
SQLFreeHandle(SQL_HANDLE_DBC, &hOdbc);
SQLFreeHandle(SQL_HANDLE_ENV, &hEnv);
printf ("TryStuff returned %d\n", err);
return 0;
}
SQLDisconnect(hOdbc);
SQLFreeHandle(SQL_HANDLE_DBC, &hOdbc);
SQLFreeHandle(SQL_HANDLE_ENV, &hEnv);
return 0;
}
-
[freetds] Possible problem with ODBC,
Craig Davison, 02/06/2003
- Re: [freetds] Possible problem with ODBC, Alex Hornby, 02/07/2003
- <Possible follow-up(s)>
- RE: [freetds] Possible problem with ODBC, ZIGLIO Frediano, 02/07/2003
Archive powered by MHonArc 2.6.24.