• unknown's avatar
    Bug#8153 (Stored procedure with subquery and continue handler, wrong result) · f748b691
    unknown authored
    Before this fix,
    - a runtime error in a statement in a stored procedure with no error handlers
    was properly detected (as expected)
    - a runtime error in a statement with an error handler inherited from a non
    local runtime context (i.e., proc a with a handler, calling proc b) was
    properly detected (as expected)
    - a runtime error in a statement with a *local* error handler was executed
    as follows :
    a) the statement would succeed, regardless of the error condition, (bug)
    b) the error handler would be called (as expected).
    
    The root cause is that functions like my_messqge_sql would "forget" to set
    the thread flag thd->net.report_error to 1, because of the check involving
    sp_rcontext::found_handler_here().
    Failure to set this flag would cause, later in the call stack,
    in Item_func::fix_fields() at line 190, the code to return FALSE and consider
    that executing the statement was successful.
    
    With this fix :
    - error handling code, that was duplicated in different places in the code,
    is now implemented in sp_rcontext::handle_error(),
    - handle_error() correctly sets thd->net.report_error when a handler is
    present, regardless of the handler location (local, or in the call stack).
    
    A test case, bug8153_subselect, has been written to demonstrate the change
    of behavior before and after the fix.
    
    Another test case, bug8153_function_a, as also been writen.
    This test has the same behavior before and after the fix.
    This test has been written to demonstrate that the previous expected
    result of procedure bug18787, was incorrect, since select no_such_function()
    should fail and therefore not produce a result.
    
    The incorrect result for bug18787 has the same root cause as Bug#8153,
    and the expected result has been adjusted.
    
    
    sql/mysqld.cc:
      Bug#8153, use sp_rcontext::handle_error() to handle errors.
    sql/sql_error.cc:
      Bug#8153, use sp_rcontext::handle_error() to handle errors.
    sql/protocol.cc:
      Bug#8153, use sp_rcontext::handle_error() to handle errors.
    sql/sp_rcontext.h:
      Bug#8153, created helper sp_rcontext::handle_error() to handle errors.
    sql/sp_rcontext.cc:
      Bug#8153, created helper sp_rcontext::handle_error() to handle errors.
    mysql-test/t/sp.test:
      Bug#8153, added test cases.
    mysql-test/r/sp.result:
      Bug#8153, added test cases, fixed expected result of bug18787.
    f748b691
sp_rcontext.h 7.68 KB