| 41 | */ |
| 42 | |
| 43 | bool |
| 44 | Sql_cmd_get_diagnostics::execute(THD *thd) |
| 45 | { |
| 46 | bool rv; |
| 47 | Diagnostics_area new_stmt_da(thd->query_id, false, true); |
| 48 | Diagnostics_area *save_stmt_da= thd->get_stmt_da(); |
| 49 | DBUG_ENTER("Sql_cmd_get_diagnostics::execute"); |
| 50 | |
| 51 | /* Disable the unneeded read-only mode of the original DA. */ |
| 52 | save_stmt_da->set_warning_info_read_only(false); |
| 53 | |
| 54 | /* Set new diagnostics area, execute statement and restore. */ |
| 55 | thd->set_stmt_da(&new_stmt_da); |
| 56 | rv= m_info->aggregate(thd, save_stmt_da); |
| 57 | thd->set_stmt_da(save_stmt_da); |
| 58 | |
| 59 | /* Bail out early if statement succeeded. */ |
| 60 | if (! rv) |
| 61 | { |
| 62 | thd->get_stmt_da()->set_ok_status(0, 0, NULL); |
| 63 | DBUG_RETURN(false); |
| 64 | } |
| 65 | |
| 66 | /* Statement failed, retrieve the error information for propagation. */ |
| 67 | uint sql_errno= new_stmt_da.sql_errno(); |
| 68 | const char *message= new_stmt_da.message(); |
| 69 | const char *sqlstate= new_stmt_da.get_sqlstate(); |
| 70 | |
| 71 | /* In case of a fatal error, set it into the original DA.*/ |
| 72 | if (unlikely(thd->is_fatal_error)) |
| 73 | { |
| 74 | save_stmt_da->set_error_status(sql_errno, message, sqlstate, NULL); |
| 75 | DBUG_RETURN(true); |
| 76 | } |
| 77 | |
| 78 | /* Otherwise, just append the new error as a exception condition. */ |
| 79 | save_stmt_da->push_warning(thd, sql_errno, sqlstate, |
| 80 | Sql_condition::WARN_LEVEL_ERROR, |
| 81 | message); |
| 82 | |
| 83 | /* Appending might have failed. */ |
| 84 | if (unlikely(!(rv= thd->is_error()))) |
| 85 | thd->get_stmt_da()->set_ok_status(0, 0, NULL); |
| 86 | |
| 87 | DBUG_RETURN(rv); |
| 88 | } |
| 89 | |
| 90 | |
| 91 | /** |
nothing calls this directly
no test coverage detected