[freetds] dbresults() behavior different between RH7.3 and CentOS4

David Chang dchang at fsautomation.com
Fri Oct 20 17:30:49 EDT 2006


Hi,

I build a batch (e.g. 100) of stored procedure calls that simply insert (or 
update) one row of data into a table using dbfcmd().  Then, I submit this 
batch to SQL Server using dbsqlexec().  I was under the impression that 
calling dbresults() after a dbsqlexec() would iterate through one 'exec' at 
a time and tell me if that stored procedure ran OK.  Then, after the last 
one in the batch finished, dbresults() would return NO_MORE_RESULTS (2).  At 
least that's how Sybase DB-Library worked.  Instead, what I see is that the 
first call to dbresults() returns NO_MORE_RESULTS (and all 100 stored 
procedures ran OK).  If that's the case, how can I tell which stored 
procedure failed (e.g. unique constraint violation) out of the 100 that ran?

Here's a snipet of the code...

for (i=0; i<_Bcount; i++)
{
                dbcmd (_Dbproc2, "exec dbpsp_update_rating_master ");
                dbfcmd(_Dbproc2, "  %d ", _Batch[i].dbpulse_id);
                dbfcmd(_Dbproc2, ", %d ", _Batch[i].summary_level);
                dbfcmd(_Dbproc2, ", %d ", _Batch[i].db_id);
                dbfcmd(_Dbproc2, ", %.0f ", _Batch[i].good_query);
                dbfcmd(_Dbproc2, ", %.0f ", _Batch[i].total_query);
}

dbsqlexec(_Dbproc2);

r_count = 0;
while ((r = dbresults(_Dbproc2)) != NO_MORE_RESULTS)
{
                if (r != SUCCEED)
                {
                        _Batch[r_count]._status = 2;
                        e_count++;
                }
                else
                {
                        status = 0;
                        if (dbhasretstat(_Dbproc2))
                                status = dbretstatus(_Dbproc2);

                        if (status == 0)
                        {
                                _Batch[r_count]._status = 1;
                                g_count++;
                        }
                        else
                        {
                                _Batch[r_count]._status = 9;
                                e_count++;
                        }
                }

                r_count++;
}

I always get r_count = 0 and r = 2 (NO_MORE_RESULTS) when running this code.

Any help would be appreciated.

DC




More information about the FreeTDS mailing list