[freetds] SQLExecDirect returns SQL_NO_DATA

Frediano Ziglio freddyz77 at tin.it
Sat Mar 11 06:42:32 EST 2006


Il giorno ven, 10/03/2006 alle 19.49 -0800, John Wythe (work) ha
scritto:
> I have found a problem with SQLExecDirect.  If I execute a query that is not intended to return data, I get an SQL_NO_DATA result.  This is not what the same function returns on Windows, it returns SQL_SUCCESS.   If I use ISQL to execute the query, which uses SQLPrepare, and SQLExecute, I get the proper result.
> 

This is not a problem... ODBC 3 specification document that
SQLExecDirect should return SQL_NO_DATA if no data returned... mssql
driver seems to not complain to these specifications... I'll look more
deeper...

Can you post a query that cause this behavior?


> I have looked at the source, and found the problem.  Maybe you can look at the before and after code snippets and tell me if I made the right change, or direct me how to make the correct change.   Eventually the fix should probably be incorperated into the main code.   Basically, from debugging the program, the done flag doesn't get set, and the program tries to get another token, but there aren't any more, so it thinks it was trying to do a SQLFetch for more data which in that case should return SQL_NO_DATA, since, in this case in_row is zero, this is not the case. My question would be whether or not TDS_DONEPROC_RESULT should also do this?
> 
> Snippets from src/odbc/odbc.c    function SQLExecDirect
> 
> Before:
>         case TDS_PARAM_RESULT:
>             odbc_set_return_params(stmt);
>             break;
> 
>         case TDS_DONE_RESULT:
>         case TDS_DONEPROC_RESULT:
>             if (done_flags & TDS_DONE_COUNT) {
>                 got_rows = 1;
> After:
> 
>         case TDS_PARAM_RESULT:
>             odbc_set_return_params(stmt);
>             break;
> 
>         case TDS_DONE_RESULT:
>             if (!in_row && !(done_flags & TDS_DONE_COUNT) && !(done_flags & TDS_DONE_ERROR))
>         /* prevent queries with no result set from returning SQL_NO_DATA jww */
>                 stmt->row_count = 0;
>             else {
>                 if (done_flags & TDS_DONE_COUNT) {
>                     got_rows = 1;
>                     stmt->row_count = tds->rows_affected;
>                 }
>                 if (done_flags & TDS_DONE_ERROR)
>                     stmt->errs.lastrc = SQL_ERROR;
>             }
>             done = 1;
>             break;

Quite complicated... where does this code came?

>         case TDS_DONEPROC_RESULT:
>             if (done_flags & TDS_DONE_COUNT) {
>                 got_rows = 1;
> 
> Thanks
> 
> John

freddy77





More information about the FreeTDS mailing list