Index: driver/results.c =================================================================== --- driver/results.c (revision 1046) +++ driver/results.c (working copy) @@ -1256,14 +1256,6 @@ if ( fFetchType != SQL_FETCH_NEXT && !(stmt->dbc->flag & FLAG_SAFE) ) return set_error(stmt,MYERR_S1106, "Wrong fetchtype with FORWARD ONLY cursor", 0); - - if ((stmt->dbc->flag & FLAG_NO_CACHE)) - { - if (stmt->result_array) - values= stmt->result_array + (cur_row * stmt->result->field_count); - else - values= mysql_fetch_row(stmt->result); - } } if ( if_dynamic_cursor(stmt) && set_dynamic_result(stmt) ) @@ -1337,7 +1329,7 @@ if ( !stmt->result_array && !if_forward_cache(stmt) ) { /* - If Dynamic, it looses the stmt->end_of_set, so + If Dynamic, it loses the stmt->end_of_set, so seek to desired row, might have new data or might be deleted */ @@ -1350,7 +1342,10 @@ } stmt->current_row= cur_row; - rows_to_fetch= min(max_row-cur_row, (long)stmt->stmt_options.rows_in_set); + if (if_forward_cache(stmt) && !stmt->result_array) + rows_to_fetch= stmt->stmt_options.rows_in_set; + else + rows_to_fetch= min(max_row-cur_row, (long)stmt->stmt_options.rows_in_set); if ( !rows_to_fetch ) { *pcrow= 0; @@ -1373,14 +1368,11 @@ } else { - if ( !if_forward_cache(stmt) ) - { - /* This code will ensure that values is alway set */ - if ( i == 0 ) - save_position= mysql_row_tell(stmt->result); - if ( !(values= mysql_fetch_row(stmt->result)) ) - break; - } + /* This code will ensure that values is always set */ + if ( i == 0 ) + save_position= mysql_row_tell(stmt->result); + if ( !(values= mysql_fetch_row(stmt->result)) ) + break; if ( stmt->fix_fields ) values= (*stmt->fix_fields)(stmt,values); else @@ -1486,6 +1478,9 @@ if ( !(stmt->dbc->flag & FLAG_NO_LOCALE) ) setlocale(LC_NUMERIC,default_locale); + if (SQL_SUCCEEDED(res) && stmt->rows_found_in_set == 0) + return SQL_NO_DATA_FOUND; + return res; } Index: test/my_result.c =================================================================== --- test/my_result.c (revision 1046) +++ test/my_result.c (working copy) @@ -2003,6 +2003,61 @@ } +/* + Bug #32420 - Don't cache results and SQLExtendedFetch work badly together +*/ +DECLARE_TEST(t_bug32420) +{ + SQLHANDLE henv1, hdbc1, hstmt1; + SQLINTEGER nData[4]; + SQLCHAR szData[4][16]; + SQLUSMALLINT rgfRowStatus[4]; + + SET_DSN_OPTION(1048576); + + alloc_basic_handles(&henv1, &hdbc1, &hstmt1); + + ok_sql(hstmt1, "drop table if exists bug32420"); + ok_sql(hstmt1, "CREATE TABLE bug32420 ("\ + "tt_int INT PRIMARY KEY auto_increment,"\ + "tt_varchar VARCHAR(128) NOT NULL)"); + ok_sql(hstmt1, "INSERT INTO bug32420 VALUES "\ + "(100, 'string 1'),"\ + "(200, 'string 2'),"\ + "(300, 'string 3'),"\ + "(400, 'string 4')"); + + ok_stmt(hstmt1, SQLFreeStmt(hstmt1, SQL_CLOSE)); + + ok_stmt(hstmt1, SQLSetStmtOption(hstmt1, SQL_ROWSET_SIZE, 4)); + + ok_sql(hstmt1, "select * from bug32420 order by 1"); + ok_stmt(hstmt1, SQLBindCol(hstmt1, 1, SQL_C_LONG, nData, 0, NULL)); + ok_stmt(hstmt1, SQLBindCol(hstmt1, 2, SQL_C_CHAR, szData, sizeof(szData[0]), + NULL)); + ok_stmt(hstmt1, SQLExtendedFetch(hstmt1, SQL_FETCH_NEXT, 0, NULL, + rgfRowStatus)); + + is_num(nData[0], 100); + is_str(szData[0], "string 1", 8); + is_num(nData[1], 200); + is_str(szData[1], "string 2", 8); + is_num(nData[2], 300); + is_str(szData[2], "string 3", 8); + is_num(nData[3], 400); + is_str(szData[3], "string 4", 8); + + ok_stmt(hstmt1, SQLFreeStmt(hstmt1, SQL_CLOSE)); + ok_sql(hstmt1, "drop table if exists bug32420"); + + free_basic_handles(&henv1, &hdbc1, &hstmt1); + + SET_DSN_OPTION(1048576); + + return OK; +} + + BEGIN_TESTS ADD_TEST(my_resultset) ADD_TEST(t_convert_type) @@ -2030,6 +2085,7 @@ ADD_TEST(t_bug31246) ADD_TEST(t_bug13776) ADD_TEST(t_bug13776_auto) + ADD_TEST(t_bug32420) END_TESTS