| 514 | |
| 515 | |
| 516 | bool sp_rcontext::handle_sql_condition(THD *thd, |
| 517 | uint *ip, |
| 518 | const sp_instr *cur_spi) |
| 519 | { |
| 520 | DBUG_ENTER("sp_rcontext::handle_sql_condition"); |
| 521 | |
| 522 | /* |
| 523 | If this is a fatal sub-statement error, and this runtime |
| 524 | context corresponds to a sub-statement, no CONTINUE/EXIT |
| 525 | handlers from this context are applicable: try to locate one |
| 526 | in the outer scope. |
| 527 | */ |
| 528 | if (unlikely(thd->is_fatal_sub_stmt_error) && m_in_sub_stmt) |
| 529 | DBUG_RETURN(false); |
| 530 | |
| 531 | Diagnostics_area *da= thd->get_stmt_da(); |
| 532 | const sp_handler *found_handler= NULL; |
| 533 | const Sql_condition *found_condition= NULL; |
| 534 | |
| 535 | if (unlikely(thd->is_error())) |
| 536 | { |
| 537 | found_handler= |
| 538 | cur_spi->m_ctx->find_handler(da->get_error_condition_identity()); |
| 539 | |
| 540 | if (found_handler) |
| 541 | found_condition= da->get_error_condition(); |
| 542 | |
| 543 | /* |
| 544 | Found condition can be NULL if the diagnostics area was full |
| 545 | when the error was raised. It can also be NULL if |
| 546 | Diagnostics_area::set_error_status(uint sql_error) was used. |
| 547 | In these cases, make a temporary Sql_condition here so the |
| 548 | error can be handled. |
| 549 | */ |
| 550 | if (!found_condition) |
| 551 | { |
| 552 | found_condition= |
| 553 | new (callers_arena->mem_root) Sql_condition(callers_arena->mem_root, |
| 554 | da->get_error_condition_identity(), |
| 555 | da->message(), |
| 556 | da->current_row_for_warning()); |
| 557 | } |
| 558 | } |
| 559 | else if (da->current_statement_warn_count()) |
| 560 | { |
| 561 | Diagnostics_area::Sql_condition_iterator it= da->sql_conditions(); |
| 562 | const Sql_condition *c; |
| 563 | |
| 564 | // Here we need to find the last warning/note from the stack. |
| 565 | // In MySQL most substantial warning is the last one. |
| 566 | // (We could have used a reverse iterator here if one existed) |
| 567 | |
| 568 | while ((c= it++)) |
| 569 | { |
| 570 | if (c->get_level() == Sql_condition::WARN_LEVEL_WARN || |
| 571 | c->get_level() == Sql_condition::WARN_LEVEL_NOTE) |
| 572 | { |
| 573 | const sp_handler *handler= cur_spi->m_ctx->find_handler(*c); |
no test coverage detected