| 3554 | */ |
| 3555 | |
| 3556 | static |
| 3557 | bool mysql_sql_stmt_execute(THD *thd, const Lex_ident_sys &name, |
| 3558 | const char *cmd, |
| 3559 | bool open_dynamic_cursor, |
| 3560 | select_result *result_arg, |
| 3561 | Server_side_cursor **cursor_arg) |
| 3562 | { |
| 3563 | LEX *lex= thd->lex; |
| 3564 | Prepared_statement *stmt; |
| 3565 | /* Query text for binary, general or slow log, if any of them is open */ |
| 3566 | String expanded_query; |
| 3567 | DBUG_ENTER("mysql_sql_stmt_execute"); |
| 3568 | DBUG_PRINT("info", ("EXECUTE: %.*s", (int) name.length, name.str)); |
| 3569 | CSET_STRING orig_query= thd->query_string; |
| 3570 | |
| 3571 | if (!(stmt= Prepared_statement::find_by_name_or_error(thd, name, cmd))) |
| 3572 | DBUG_RETURN(true); |
| 3573 | |
| 3574 | DBUG_PRINT("info",("stmt: %p", stmt)); |
| 3575 | |
| 3576 | if (!open_dynamic_cursor) |
| 3577 | { |
| 3578 | if (stmt->param_count != lex->prepared_stmt.param_count()) |
| 3579 | { |
| 3580 | my_error(ER_WRONG_ARGUMENTS, MYF(0), cmd); |
| 3581 | DBUG_RETURN(true); |
| 3582 | } |
| 3583 | |
| 3584 | if (lex->prepared_stmt.params_fix_fields(thd)) |
| 3585 | DBUG_RETURN(true); |
| 3586 | } |
| 3587 | else |
| 3588 | { |
| 3589 | if (stmt->lex->sql_command != SQLCOM_SELECT) |
| 3590 | { |
| 3591 | my_error(ER_SP_BAD_CURSOR_QUERY, MYF(0)); |
| 3592 | DBUG_RETURN(true); |
| 3593 | } |
| 3594 | |
| 3595 | /* |
| 3596 | Check if all placeholder parameters were set by the USING list: |
| 3597 | OPEN c USING expr1, expr2; |
| 3598 | */ |
| 3599 | if (stmt->check_all_placeholders_set()) |
| 3600 | DBUG_RETURN(true); |
| 3601 | } |
| 3602 | |
| 3603 | /* |
| 3604 | thd->free_list can already have some Items. |
| 3605 | |
| 3606 | Example queries: |
| 3607 | - SET STATEMENT var=expr FOR EXECUTE stmt; |
| 3608 | - EXECUTE stmt USING expr; |
| 3609 | |
| 3610 | E.g. for a query like this: |
| 3611 | PREPARE stmt FROM 'INSERT INTO t1 VALUES (@@max_sort_length)'; |
| 3612 | SET STATEMENT max_sort_length=2048 FOR EXECUTE stmt; |
| 3613 | thd->free_list contains a pointer to Item_int corresponding to 2048. |
no test coverage detected