@brief Execute function and store the return value in the field. @note This function was intended to be the concrete implementation of the interface function execute. This was never realized. @return The error state. @retval FALSE on success @retval TRUE if an error occurred. */
| 3035 | @retval TRUE if an error occurred. |
| 3036 | */ |
| 3037 | bool |
| 3038 | Item_sp::execute_impl(THD *thd, Item **args, uint arg_count) |
| 3039 | { |
| 3040 | Sub_statement_state statement_state; |
| 3041 | Security_context *save_security_ctx= thd->security_ctx; |
| 3042 | enum enum_sp_data_access access= |
| 3043 | (m_sp->daccess() == SP_DEFAULT_ACCESS) ? |
| 3044 | SP_DEFAULT_ACCESS_MAPPING : m_sp->daccess(); |
| 3045 | |
| 3046 | DBUG_ENTER("Item_sp::execute_impl"); |
| 3047 | |
| 3048 | if (context && context->security_ctx) |
| 3049 | { |
| 3050 | /* Set view definer security context */ |
| 3051 | thd->security_ctx= context->security_ctx; |
| 3052 | } |
| 3053 | |
| 3054 | if (unlikely(sp_check_access(thd))) |
| 3055 | { |
| 3056 | thd->security_ctx= save_security_ctx; |
| 3057 | DBUG_RETURN(TRUE); |
| 3058 | } |
| 3059 | |
| 3060 | /* |
| 3061 | Throw an error if a non-deterministic function is called while |
| 3062 | statement-based replication (SBR) is active. |
| 3063 | */ |
| 3064 | |
| 3065 | if (unlikely(!m_sp->detistic() && !trust_function_creators && |
| 3066 | (access == SP_CONTAINS_SQL || access == SP_MODIFIES_SQL_DATA) && |
| 3067 | (mysql_bin_log.is_open() && |
| 3068 | thd->variables.binlog_format == BINLOG_FORMAT_STMT))) |
| 3069 | { |
| 3070 | my_error(ER_BINLOG_UNSAFE_ROUTINE, MYF(0)); |
| 3071 | thd->security_ctx= save_security_ctx; |
| 3072 | DBUG_RETURN(TRUE); |
| 3073 | } |
| 3074 | |
| 3075 | /* |
| 3076 | Disable the binlogging if this is not a SELECT statement. If this is a |
| 3077 | SELECT, leave binlogging on, so execute_function() code writes the |
| 3078 | function call into binlog. |
| 3079 | */ |
| 3080 | thd->reset_sub_statement_state(&statement_state, SUB_STMT_FUNCTION); |
| 3081 | |
| 3082 | /* |
| 3083 | If this function is an aggregate function, we want to initialise the |
| 3084 | mem_root only once per group. For a regular stored function, we will |
| 3085 | initialise once for each call to execute_function. |
| 3086 | */ |
| 3087 | m_sp->agg_type(); |
| 3088 | DBUG_ASSERT(m_sp->agg_type() == GROUP_AGGREGATE || |
| 3089 | (m_sp->agg_type() == NOT_AGGREGATE && !func_ctx)); |
| 3090 | if (!func_ctx) |
| 3091 | { |
| 3092 | init_sql_alloc(key_memory_sp_head_call_root, &sp_mem_root, |
| 3093 | MEM_ROOT_BLOCK_SIZE, 0, MYF(0)); |
| 3094 | *sp_query_arena= Query_arena(&sp_mem_root, |
nothing calls this directly
no test coverage detected