Re: Return value of SQLRowCount with operations producing no result
Frediano Ziglio <[email protected]>
| Newsgroups | gmane.comp.db.tds.freetds |
|---|---|
| Message-ID | <[email protected]> |
Il giorno 13/gen/2012, alle ore 22:03, [email protected] ha scritto: > On Fri, Jan 13, 2012 at 03:09:10PM -0500, Jack Lloyd wrote: >> Hi, >> >> I've noticed a difference in behavior in FreeTDS between 0.82 and 0.91 >> when using it via iODBC 3.52.7. I'm using FreeTDS on Linux, talking to >> a SQL Server 2008 R2 instance. In 0.82, calling SQLRowCount when the >> statement was something that does not produce a result (for instance >> "set lock_timeout 1000", "create table ..." or "drop table ..."), the >> call returns SQL_SUCCESS, setting the output parameter to -1. This >> behavior matches that seen running on Windows using the Microsoft ODBC >> driver. In contrast in 0.91 (as well as the 0.92 snapshot I tried, >> dated 20120105), SQLRowCount will return SQL_ERROR and does not set >> the output parameter. GetDiagRec returns "Function sequence error". > > Bug. :-( > > http://msdn.microsoft.com/en-us/library/windows/desktop/ms711835%28v=vs.85%29.aspx > > The 24000 diagnostic is not a valid return code for SQLRowCount(). I don't remember why there is this if... I should check on cvs history. Have you tried unittests?? > HY010 (Function sequence error) is a DM error, and is not caused by the > situation you describe. > > Here is the code: > > SQLRETURN > _SQLRowCount(SQLHSTMT hstmt, SQLLEN FAR * pcrow) > { > TDSSOCKET *tds; > > ODBC_ENTER_HSTMT; > > tdsdump_log(TDS_DBG_FUNC, "_SQLRowCount(%p, %p)\n", > hstmt, pcrow); > > tds = stmt->dbc->tds_socket; > if (stmt->row_status == NOT_IN_ROW) { > odbc_errs_add(&stmt->errs, "24000", NULL); > ODBC_EXIT_(stmt); > } > > *pcrow = -1; > if (stmt->row_count != TDS_NO_COUNT) > *pcrow = stmt->row_count; > ODBC_EXIT_(stmt); > } > > Looking over the possible return codes for SQLRowCount(), I think the error > checking can be removed, yielding: > > SQLRETURN > _SQLRowCount(SQLHSTMT hstmt, SQLLEN FAR * pcrow) > { > ODBC_ENTER_HSTMT; > > tdsdump_log(TDS_DBG_FUNC, "_SQLRowCount(%p, %p)\n", hstmt, pcrow); > > assert(TDS_NO_COUNT == -1); > This test could be replaced by a compile test. > *pcrow = stmt->row_count; > > ODBC_EXIT_(stmt); > } > > Please try that. I'll commit it if it works and no one objects. > >> SQLNumResultCols will also fail in 0.91 in this situation > > The code that would do that is removed in CVS HEAD with "#if 0". > > --jkl Bye Frediano