Skip to Content.
Sympa Menu

freetds - Re: [freetds] SQLRowCount failing after prepare and execute

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Frediano Ziglio <freddyz77 AT tin.it>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] SQLRowCount failing after prepare and execute
  • Date: 13 Feb 2004 20:02:56 +0100

Il gio, 2004-02-12 alle 22:28, Matthew A. Davis ha scritto:
> When I send an UPDATE using SQLExecDirect(), then check the number of
> affected rows, all is fine. When I send the same command using
> SQLPrepare() and SQLExecute(), checking the number of effected rows fails
> with SQLState 24000 (Invalid Cursor).
>
> I've made my test code available on the web:
> http://www.speakeasy.org/~azami/code/
> In addition to the .cpp file, I've included tdsdump logs for the two cases.
>
> Basically, after connecting and getting a statement, I'm doing this:
>
> SQLPrepare(hstmt, (SQLCHAR *)("UPDATE SQLDEV1.OT_LastRecordID SET RecordID
> = RecordID + 1"), SQL_NTS);
> SQLExecute(hstmt);
> SQLRowCount(hstmt, &rows);
>
> In this case SQLRowCount fails. If I SQLExecDirect() the exact same
> statement:
>
> SQLExecDirect(hstmt, (SQLCHAR *)("UPDATE SQLDEV1.OT_LastRecordID SET
> RecordID = RecordID + 1"), SQL_NTS);
> SQLRowCount(hstmt, &rows);
>
> then SQLRowCount succeeds and returns the correct number.
>
> The OT_LastRecordID table has one column, RecordID, which is an integer.
> It has one record.
>
> Looking at the freeTDS source, I see that SQLRowCount() returns this error
> if stmt->dbc->current_statement != stmt. I've verified that this is what's
> happening by returning more info with the error. current_statement is NULL.
>
> _SQLExecute() sets current_statement in the middle (odbc.c line 2379), then
> if tds_process_result_tokens() returns TDS_NO_MORE_RESULTS, it resets
> current_statement to NULL (line 2441). It looks like the count is being
> invalidated when the DONEPROC result token is processed; when we call
> SQLExecDirect, a DONE token is processed instead.
>
> We are using FreeTDS 0.62.1 on Linux, against SQL Server Personal Edition
> 8.00.760 (SP3) running on Windows 2000. The database is set for
> compatibility level 80.
>
> Any idea why this is happening? Is this a bug in FreeTSD, or a problem in
> our configuration? I'm quite surprised no one else seems to have
> encountered this - at least, I wasn't able to find any posts about it
> through Google or the freetds mailing list archive.
>

Hi Matthew!
I don't know if SQLRowCount should return error or no_row_count however
you won't be able to read row counts using SQLPrepare and insert. This
behavior reflect wire protocol and it's compatible with Microsoft ODBC.

freddy77






Archive powered by MHonArc 2.6.24.

Top of Page