Skip to Content.
Sympa Menu

freetds - Re: [freetds] Two statements on one connection

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "ZIGLIO, Frediano, VF-IT" <Frediano.Ziglio AT vodafone.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] Two statements on one connection
  • Date: Fri, 2 Dec 2005 17:05:21 +0100

>
> Dear All,
>
> I am using freeTDS 0.63 and unixODBC under Redhat 7.1. Is it
> OK to use two
> statements on one connection? The below code gives me
> 'invalid cursor state'
> error while trying to do the second SQLExexDirect(). The code
> works fine for
> Oracle and MySQL drivers. What should I do if I want to
> achieve the below
> goal(e.g. fetch one table inside loopof fetching another table)?
>
>
> .......
> V_OD_erg=SQLExecDirect(V_OD_hstmt,"select
> employeeid,firstname,hiredate,
> salary,dsc FROM employees", SQL_NTS);
> SQLAllocHandle(SQL_HANDLE_STMT, V_OD_hdbc, &V_OD_hstmt2);
> SQLBindCol(V_OD_hstmt2,1,SQL_C_CHAR,&V_OD_buffer2,150,&V_OD_err);
> V_OD_erg=SQLExecDirect(V_OD_hstmt2,"select firstname from
> table2 ",
> SQL_NTS);
> V_OD_erg=SQLFetch(V_OD_hstmt);
> while(V_OD_erg != SQL_NO_DATA)
> {
> printf("row(%d) Result: [%d] [%s] [%s] [%f] [%s]\n",
> i,V_OD_id,V_OD_buffer,V_OD_date,V_OD_double,V_OD_dsc);
> V_OD_erg=SQLFetch(V_OD_hstmt2);
> printf("second Result: [%s]\n", V_OD_buffer2 );
> V_OD_erg=SQLFetch(V_OD_hstmt);
> i++;
> };
>
> Regards
>
> Yanxin
>

Short reply:
use two connections

Long reply:
mssql by default (using normal queries) do not allow two active
statement on same connection. This for TDS protocol limit. There is
however an option witch is the use of cursors. Enabling cursor would
allow you (for instance) to do a select and use results for another
query using same connection. However currectly FreeTDS odbc driver do
not provide cursors support...

freddy77




Archive powered by MHonArc 2.6.24.

Top of Page