Index: ChangeLog =================================================================== --- ChangeLog (revision 422) +++ ChangeLog (working copy) @@ -3,6 +3,9 @@ Functionality added or changed: Bugs fixed: + * Accessing the results of catalog functions could cause a crash when the + "Don't cache results" option was set and a forward-only cursor was + being used. (Bug #4657) * SQLForeignKeys() did not properly escape wildcard characters in its table name parameters when retrieving information. (Bug #27723) * Calls to SQLSetPos() could cause the driver to incorrectly calculate the Index: driver/results.c =================================================================== --- driver/results.c (revision 422) +++ driver/results.c (working copy) @@ -1293,8 +1293,13 @@ "Wrong fetchtype with FORWARD ONLY cursor", 0)); - if ( (stmt->dbc->flag & FLAG_NO_CACHE) ) + 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) ) Index: test/my_use_result.c =================================================================== --- test/my_use_result.c (revision 422) +++ test/my_use_result.c (working copy) @@ -70,8 +70,45 @@ } +/** + Bug #4657: "Don't Cache Results" crashes when using catalog functions +*/ +DECLARE_TEST(t_bug4657) +{ + SQLCHAR name[10]; + SQLSMALLINT column_count; + SQLLEN name_length; + + ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug4657"); + ok_sql(hstmt, "CREATE TABLE t_bug4657 (a INT)"); + + ok_stmt(hstmt, SQLSetStmtAttr(hstmt, SQL_ATTR_CURSOR_TYPE, + (SQLPOINTER)SQL_CURSOR_FORWARD_ONLY, 0)); + + ok_stmt(hstmt, SQLTables(hstmt, (SQLCHAR *)"", SQL_NTS, + (SQLCHAR *)"", SQL_NTS, + (SQLCHAR *)"", SQL_NTS, + (SQLCHAR *)"TABLE,VIEW", SQL_NTS)); + + ok_stmt(hstmt, SQLNumResultCols(hstmt, &column_count)); + is_num(column_count, 5); + + ok_stmt(hstmt, SQLBindCol(hstmt, 3, SQL_C_CHAR, name, sizeof(name), + &name_length)); + expect_stmt(hstmt, SQLFetch(hstmt), SQL_NO_DATA_FOUND); + + ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_UNBIND)); + ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE)); + + ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug4657"); + + return OK; +} + + BEGIN_TESTS ADD_TEST(t_use_result) + ADD_TEST(t_bug4657) END_TESTS