Skip to Content.
Sympa Menu

freetds - [freetds] (ODBC) processing multiple statements on one connectio n

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Roger Reynolds <rogerr AT softix.com>
  • To: "'FreeTDS Development Group'" <freetds AT lists.ibiblio.org>
  • Subject: [freetds] (ODBC) processing multiple statements on one connectio n
  • Date: Fri, 30 Apr 2004 17:10:50 +1000

Right off, let state that the following may likely have
more to do with ODBC in general, than freetds in particular,
but maybe somebody here can help me out (I hope).

Essentially, the problem is that I need to operate on two
statements against the same connection in parallel.
That is, as each row is fetched from one statement, to be
able to execute a second statement on that same connection.

The following code illustrates:

// assume you have a connection handle called svc
// assume you have a table called "test_table" with
// an int column "t1" and test_table has at least
// one row of data

HSTMT stmtHandle;

SQLAllocStmt(svc, &stmtHandle);

const char* s = "select t1 from test_table";

SQLPrepare(stmtHandle, (SQLCHAR*) s, SQL_NTS);

SQLExecute(stmtHandle);

int val;
long ind;
SQLBindCol(stmtHandle, 1, SQL_C_LONG, &val, sizeof(val), &ind);

while (SQLFetch(stmtHandle) == 0) {
HSTMT s2;

SQLAllocStmt(svc, &s2);

printf ("val = %d\n", val);
const char* s = "insert into t2 values(0)";
if (SQLExecDirect(s2, (SQLCHAR*)s, SQL_NTS) != SQL_SUCCESS)
printf("s2 failed!\n");
SQLFreeStmt (s2, SQL_CLOSE);
}

When I run this, I get the following error from SQLExecDirect:

Attempt to initiate a new SQL Server operation with results pending.

and an SQLSTATE of 07005, and a "native error code" of 20019

Interestingly, the description of SQLSTATE 07005 from


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/od
bcodbc_error_codes.asp

is described as

Prepared statement not a cursor-specification

and isn't claimed to be generated by SQLExecDirect.
Curious.


Anyway, please tell me if you can - there must be some attribute to set or
something
that would allow this scenario to succeed.

Right?

Thanks for your help.

roger






  • [freetds] (ODBC) processing multiple statements on one connectio n, Roger Reynolds, 04/30/2004

Archive powered by MHonArc 2.6.24.

Top of Page