| 576 | |
| 577 | |
| 578 | sp_handler* |
| 579 | sp_pcontext::find_handler(const Sql_condition_identity &value) const |
| 580 | { |
| 581 | sp_handler *found_handler= NULL; |
| 582 | sp_condition_value *found_cv= NULL; |
| 583 | |
| 584 | for (size_t i= 0; i < m_handlers.elements(); ++i) |
| 585 | { |
| 586 | sp_handler *h= m_handlers.at(i); |
| 587 | |
| 588 | List_iterator_fast<sp_condition_value> li(h->condition_values); |
| 589 | sp_condition_value *cv; |
| 590 | |
| 591 | while ((cv= li++)) |
| 592 | { |
| 593 | if (cv->matches(value, found_cv)) |
| 594 | { |
| 595 | found_cv= cv; |
| 596 | found_handler= h; |
| 597 | } |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | if (found_handler) |
| 602 | return found_handler; |
| 603 | |
| 604 | |
| 605 | // There is no appropriate handler in this parsing context. We need to look up |
| 606 | // in parent contexts. There might be two cases here: |
| 607 | // |
| 608 | // 1. The current context has REGULAR_SCOPE. That means, it's a simple |
| 609 | // BEGIN..END block: |
| 610 | // ... |
| 611 | // BEGIN |
| 612 | // ... # We're here. |
| 613 | // END |
| 614 | // ... |
| 615 | // In this case we simply call find_handler() on parent's context recursively. |
| 616 | // |
| 617 | // 2. The current context has HANDLER_SCOPE. That means, we're inside an |
| 618 | // SQL-handler block: |
| 619 | // ... |
| 620 | // DECLARE ... HANDLER FOR ... |
| 621 | // BEGIN |
| 622 | // ... # We're here. |
| 623 | // END |
| 624 | // ... |
| 625 | // In this case we can not just call parent's find_handler(), because |
| 626 | // parent's handler don't catch conditions from this scope. Instead, we should |
| 627 | // try to find first parent context (we might have nested handler |
| 628 | // declarations), which has REGULAR_SCOPE (i.e. which is regular BEGIN..END |
| 629 | // block). |
| 630 | |
| 631 | const sp_pcontext *p= this; |
| 632 | |
| 633 | while (p && p->m_scope == HANDLER_SCOPE) |
| 634 | p= p->m_parent; |
| 635 |
no test coverage detected