~ubuntu-branches/ubuntu/hardy/mysql-dfsg-5.0/hardy-updates

« back to all changes in this revision

Viewing changes to libmysqld/item_func.cc

  • Committer: Bazaar Package Importer
  • Author(s): sean finney
  • Date: 2007-05-13 12:32:45 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20070513123245-8c3l187dk34cz2ar
Tags: 5.0.41-2
the previous "translation changes" inadvertently introduced unrelated
changes in the package control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
230
230
      (*traverser)(this, argument);
231
231
    }
232
232
  }
 
233
  else
 
234
    (*traverser)(this, argument);
233
235
}
234
236
 
235
237
 
431
433
 
432
434
  switch (result_type()) {
433
435
  case INT_RESULT:
434
 
    if (max_length > 11)
 
436
    if (max_length > MY_INT32_NUM_DECIMAL_DIGITS)
435
437
      res= new Field_longlong(max_length, maybe_null, name, t_arg,
436
438
                              unsigned_flag);
437
439
    else
2321
2323
 
2322
2324
void Item_func_locate::fix_length_and_dec()
2323
2325
{
2324
 
  maybe_null=0; max_length=11;
 
2326
  maybe_null= 0;
 
2327
  max_length= MY_INT32_NUM_DECIMAL_DIGITS;
2325
2328
  agg_arg_charsets(cmp_collation, args, 2, MY_COLL_CMP_CONV, 1);
2326
2329
}
2327
2330
 
3212
3215
    Structure is now initialized.  Try to get the lock.
3213
3216
    Set up control struct to allow others to abort locks
3214
3217
  */
3215
 
  thd->proc_info="User lock";
 
3218
  thd_proc_info(thd, "User lock");
3216
3219
  thd->mysys_var->current_mutex= &LOCK_user_locks;
3217
3220
  thd->mysys_var->current_cond=  &ull->cond;
3218
3221
 
3237
3240
  }
3238
3241
  pthread_mutex_unlock(&LOCK_user_locks);
3239
3242
  pthread_mutex_lock(&thd->mysys_var->mutex);
3240
 
  thd->proc_info=0;
 
3243
  thd_proc_info(thd, 0);
3241
3244
  thd->mysys_var->current_mutex= 0;
3242
3245
  thd->mysys_var->current_cond=  0;
3243
3246
  pthread_mutex_unlock(&thd->mysys_var->mutex);
3318
3321
    Structure is now initialized.  Try to get the lock.
3319
3322
    Set up control struct to allow others to abort locks.
3320
3323
  */
3321
 
  thd->proc_info="User lock";
 
3324
  thd_proc_info(thd, "User lock");
3322
3325
  thd->mysys_var->current_mutex= &LOCK_user_locks;
3323
3326
  thd->mysys_var->current_cond=  &ull->cond;
3324
3327
 
3356
3359
  pthread_mutex_unlock(&LOCK_user_locks);
3357
3360
 
3358
3361
  pthread_mutex_lock(&thd->mysys_var->mutex);
3359
 
  thd->proc_info=0;
 
3362
  thd_proc_info(thd, 0);
3360
3363
  thd->mysys_var->current_mutex= 0;
3361
3364
  thd->mysys_var->current_cond=  0;
3362
3365
  pthread_mutex_unlock(&thd->mysys_var->mutex);
4614
4617
    fields.push_back(new Item_string(" ",1, cmp_collation.collation));
4615
4618
    for (uint i=1; i < arg_count; i++)
4616
4619
      fields.push_back(args[i]);
4617
 
    concat=new Item_func_concat_ws(fields);
 
4620
    concat_ws=new Item_func_concat_ws(fields);
4618
4621
    /*
4619
4622
      Above function used only to get value and do not need fix_fields for it:
4620
4623
      Item_string - basic constant
4621
4624
      fields - fix_fields() was already called for this arguments
4622
4625
      Item_func_concat_ws - do not need fix_fields() to produce value
4623
4626
    */
4624
 
    concat->quick_fix_field();
 
4627
    concat_ws->quick_fix_field();
4625
4628
  }
4626
4629
 
4627
4630
  if (master)
4836
4839
 
4837
4840
  if (key == NO_SUCH_KEY)
4838
4841
  {
4839
 
    String *a= concat->val_str(&value);
4840
 
    if ((null_value= (a == 0)))
 
4842
    String *a= concat_ws->val_str(&value);
 
4843
    if ((null_value= (a == 0)) || !a->length())
4841
4844
      DBUG_RETURN(0);
4842
4845
    DBUG_RETURN(ft_handler->please->find_relevance(ft_handler,
4843
4846
                                      (byte *)a->ptr(), a->length()));
4995
4998
}
4996
4999
 
4997
5000
 
4998
 
Item_func_sp::Item_func_sp(Name_resolution_context *context_arg,
4999
 
                           sp_name *name_arg)
5000
 
  :Item_func(), context(context_arg), m_name(name_arg), m_sp(NULL),
5001
 
   result_field(NULL)
5002
 
{
5003
 
  maybe_null= 1;
5004
 
  m_name->init_qname(current_thd);
5005
 
  dummy_table= (TABLE*) sql_calloc(sizeof(TABLE));
5006
 
}
5007
 
 
5008
 
 
5009
 
Item_func_sp::Item_func_sp(Name_resolution_context *context_arg,
5010
 
                           sp_name *name_arg, List<Item> &list)
5011
 
  :Item_func(list), context(context_arg), m_name(name_arg), m_sp(NULL),
5012
 
   result_field(NULL)
5013
 
{
5014
 
  maybe_null= 1;
5015
 
  m_name->init_qname(current_thd);
5016
 
  dummy_table= (TABLE*) sql_calloc(sizeof(TABLE));
5017
 
}
 
5001
 
 
5002
 
 
5003
Item_func_sp::Item_func_sp(Name_resolution_context *context_arg, sp_name *name)
 
5004
  :Item_func(), context(context_arg), m_name(name), m_sp(NULL), sp_result_field(NULL)
 
5005
{
 
5006
  maybe_null= 1;
 
5007
  m_name->init_qname(current_thd);
 
5008
  dummy_table= (TABLE*) sql_calloc(sizeof(TABLE));
 
5009
}
 
5010
 
 
5011
 
 
5012
Item_func_sp::Item_func_sp(Name_resolution_context *context_arg,
 
5013
                           sp_name *name, List<Item> &list)
 
5014
  :Item_func(list), context(context_arg), m_name(name), m_sp(NULL),sp_result_field(NULL)
 
5015
{
 
5016
  maybe_null= 1;
 
5017
  m_name->init_qname(current_thd);
 
5018
  dummy_table= (TABLE*) sql_calloc(sizeof(TABLE));
 
5019
}
 
5020
 
5018
5021
 
5019
5022
void
5020
5023
Item_func_sp::cleanup()
5021
5024
{
5022
 
  if (result_field)
 
5025
  if (sp_result_field)
5023
5026
  {
5024
 
    delete result_field;
5025
 
    result_field= NULL;
 
5027
    delete sp_result_field;
 
5028
    sp_result_field= NULL;
5026
5029
  }
5027
5030
  m_sp= NULL;
5028
5031
  dummy_table->s= NULL;
5034
5037
{
5035
5038
  THD *thd= current_thd;
5036
5039
  /* Calculate length to avoid reallocation of string for sure */
5037
 
  uint len= ((m_name->m_db.length +
 
5040
  uint len= ((m_name->m_explicit_name ? m_name->m_db.length : 0 +
5038
5041
              m_name->m_name.length)*2 + //characters*quoting
5039
5042
             2 +                         // ` and `
5040
5043
             1 +                         // .
5044
5047
               system_charset_info);
5045
5048
 
5046
5049
  qname.length(0);
5047
 
  append_identifier(thd, &qname, m_name->m_db.str, m_name->m_db.length);
5048
 
  qname.append('.');
 
5050
  if (m_name->m_explicit_name)
 
5051
  {
 
5052
    append_identifier(thd, &qname, m_name->m_db.str, m_name->m_db.length);
 
5053
    qname.append('.');
 
5054
  }
5049
5055
  append_identifier(thd, &qname, m_name->m_name.str, m_name->m_name.length);
5050
5056
  return qname.ptr();
5051
5057
}
5052
5058
 
5053
5059
 
5054
 
Field *
5055
 
Item_func_sp::sp_result_field(void) const
5056
 
{
5057
 
  Field *field;
5058
 
  DBUG_ENTER("Item_func_sp::sp_result_field");
5059
 
  DBUG_PRINT("info", ("sp: %s, flags: %x, level: %lu",
5060
 
                      (m_sp ? "YES" : "NO"),
5061
 
                      (m_sp ? m_sp->m_flags : (uint)0),
5062
 
                      (m_sp ? m_sp->m_recursion_level : (ulong)0)));
5063
 
 
5064
 
  if (!m_sp)
5065
 
  {
5066
 
    THD *thd= current_thd;
5067
 
    if (!(m_sp= sp_find_routine(thd, TYPE_ENUM_FUNCTION, m_name,
5068
 
                                &thd->sp_func_cache, TRUE)))
5069
 
    {
5070
 
      my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", m_name->m_qname.str);
5071
 
      DBUG_RETURN(0);
5072
 
    }
5073
 
  }
5074
 
  if (!dummy_table->s)
5075
 
  {
5076
 
    char *empty_name= (char *) "";
5077
 
    TABLE_SHARE *share;
5078
 
    dummy_table->s= share= &dummy_table->share_not_to_be_used;
5079
 
    dummy_table->alias = empty_name;
5080
 
    dummy_table->maybe_null = maybe_null;
5081
 
    dummy_table->in_use= current_thd;
5082
 
    dummy_table->copy_blobs= TRUE;
5083
 
    share->table_cache_key = empty_name;
5084
 
    share->table_name = empty_name;
5085
 
  }
5086
 
  if (!(field= m_sp->create_result_field(max_length, name, dummy_table)))
5087
 
    my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
5088
 
 
5089
 
  DBUG_RETURN(field);
5090
 
}
5091
 
 
5092
 
 
5093
 
/*
5094
 
  Execute function & store value in field
5095
 
 
5096
 
  RETURN
5097
 
   0  value <> NULL
5098
 
   1  value =  NULL  or error
5099
 
*/
5100
 
 
5101
 
bool
5102
 
Item_func_sp::execute(Field **flp)
 
5060
 
 
5061
/**
 
5062
  @brief Initialize the result field by creating a temporary dummy table
 
5063
    and assign it to a newly created field object. Meta data used to
 
5064
    create the field is fetched from the sp_head belonging to the stored
 
5065
    proceedure found in the stored procedure functon cache.
 
5066
  
 
5067
  @note This function should be called from fix_fields to init the result
 
5068
    field. It is some what related to Item_field.
 
5069
 
 
5070
  @see Item_field
 
5071
 
 
5072
  @param thd A pointer to the session and thread context.
 
5073
 
 
5074
  @return Function return error status.
 
5075
  @retval TRUE is returned on an error
 
5076
  @retval FALSE is returned on success.
 
5077
*/
 
5078
bool
 
5079
Item_func_sp::init_result_field(THD *thd)
 
5080
{
 
5081
  DBUG_ENTER("Item_func_sp::init_result_field");
 
5082
  
 
5083
  char *empty_name= (char *) "";
 
5084
  TABLE_SHARE *share;
 
5085
 
 
5086
  DBUG_ASSERT(m_sp == NULL);
 
5087
  DBUG_ASSERT(sp_result_field == NULL);
 
5088
  DBUG_ASSERT(dummy_table->s == NULL);  
 
5089
 
 
5090
  if (!(m_sp= sp_find_routine(thd, TYPE_ENUM_FUNCTION, m_name,
 
5091
                               &thd->sp_func_cache, TRUE)))
 
5092
  {
 
5093
    my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", m_name->m_qname.str);
 
5094
    context->process_error(thd);
 
5095
    DBUG_RETURN(TRUE);
 
5096
  }
 
5097
 
 
5098
  /*
 
5099
     A Field need to be attached to a Table.
 
5100
     Below we "create" a dummy table by initializing 
 
5101
     the needed pointers.
 
5102
   */
 
5103
  dummy_table->s= share= &dummy_table->share_not_to_be_used;
 
5104
  dummy_table->alias = empty_name;
 
5105
  dummy_table->maybe_null = maybe_null;
 
5106
  dummy_table->in_use= thd;
 
5107
  dummy_table->copy_blobs= TRUE;
 
5108
  share->table_cache_key = empty_name;
 
5109
  share->table_name = empty_name;
 
5110
 
 
5111
  if (!(sp_result_field= m_sp->create_result_field(max_length, name, dummy_table)))
 
5112
  {
 
5113
   DBUG_RETURN(TRUE);
 
5114
  }
 
5115
  
 
5116
  if (sp_result_field->pack_length() > sizeof(result_buf))
 
5117
  {
 
5118
    sp_result_field->move_field(sql_alloc(sp_result_field->pack_length()));
 
5119
  } else {
 
5120
    sp_result_field->move_field(result_buf);
 
5121
  }
 
5122
  
 
5123
  sp_result_field->null_ptr= (uchar *) &null_value;
 
5124
  sp_result_field->null_bit= 1;
 
5125
  
 
5126
 
 
5127
  DBUG_RETURN(FALSE);
 
5128
}
 
5129
 
 
5130
/**
 
5131
  @brief Initialize local members with values from the Field interface.
 
5132
 
 
5133
  @note called from Item::fix_fields.
 
5134
*/
 
5135
void Item_func_sp::fix_length_and_dec()
 
5136
{
 
5137
  DBUG_ENTER("Item_func_sp::fix_length_and_dec");
 
5138
 
 
5139
  DBUG_ASSERT(sp_result_field);
 
5140
  decimals= sp_result_field->decimals();
 
5141
  max_length= sp_result_field->field_length;
 
5142
  collation.set(sp_result_field->charset());
 
5143
  maybe_null= 1;
 
5144
  unsigned_flag= test(sp_result_field->flags & UNSIGNED_FLAG);
 
5145
 
 
5146
  DBUG_VOID_RETURN;
 
5147
}
 
5148
 
 
5149
/**
 
5150
  @brief Execute function & store value in field.
 
5151
 
 
5152
  @return Function returns error status.
 
5153
  @retval FALSE on success.
 
5154
  @retval TRUE if an error occurred.
 
5155
*/
 
5156
 
 
5157
bool
 
5158
Item_func_sp::execute()
5103
5159
{
5104
5160
  THD *thd= current_thd;
5105
 
  Field *f;
5106
 
 
 
5161
  
5107
5162
  /*
5108
5163
    Get field in virtual tmp table to store result. Create the field if
5109
5164
    invoked first time.
5110
5165
  */
5111
 
  
5112
 
  if (!(f= *flp))
5113
 
  {
5114
 
    if (!(*flp= f= sp_result_field()))
5115
 
    {
5116
 
      /* Error set by sp_result_field() */
5117
 
      null_value= 1;
5118
 
      return TRUE;
5119
 
    }
5120
5166
 
5121
 
    f->move_field((f->pack_length() > sizeof(result_buf)) ?
5122
 
                  sql_alloc(f->pack_length()) : result_buf);
5123
 
    f->null_ptr= (uchar *)&null_value;
5124
 
    f->null_bit= 1;
5125
 
  }
5126
5167
 
5127
5168
  /* Execute function and store the return value in the field. */
5128
5169
 
5129
 
  if (execute_impl(thd, f))
 
5170
  if (execute_impl(thd))
5130
5171
  {
5131
5172
    null_value= 1;
5132
5173
    context->process_error(thd);
5135
5176
 
5136
5177
  /* Check that the field (the value) is not NULL. */
5137
5178
 
5138
 
  null_value= f->is_null();
 
5179
  null_value= sp_result_field->is_null();
5139
5180
 
5140
5181
  return null_value;
5141
5182
}
5142
5183
 
5143
5184
 
 
5185
/**
 
5186
   @brief Execute function and store the return value in the field.
 
5187
 
 
5188
   @note This function was intended to be the concrete implementation of
 
5189
    the interface function execute. This was never realized.
 
5190
 
 
5191
   @return The error state.
 
5192
   @retval FALSE on success
 
5193
   @retval TRUE if an error occurred.
 
5194
*/
5144
5195
bool
5145
 
Item_func_sp::execute_impl(THD *thd, Field *return_value_fld)
 
5196
Item_func_sp::execute_impl(THD *thd)
5146
5197
{
5147
5198
  bool err_status= TRUE;
5148
5199
  Sub_statement_state statement_state;
5159
5210
    thd->security_ctx= context->security_ctx;
5160
5211
  }
5161
5212
#endif
5162
 
  if (find_and_check_access(thd))
 
5213
  if (sp_check_access(thd))
5163
5214
    goto error;
5164
5215
 
5165
5216
  /*
5168
5219
    function call into binlog.
5169
5220
  */
5170
5221
  thd->reset_sub_statement_state(&statement_state, SUB_STMT_FUNCTION);
5171
 
  err_status= m_sp->execute_function(thd, args, arg_count, return_value_fld);
 
5222
  err_status= m_sp->execute_function(thd, args, arg_count, sp_result_field); 
5172
5223
  thd->restore_sub_statement_state(&statement_state);
5173
5224
 
5174
5225
error:
5183
5234
void
5184
5235
Item_func_sp::make_field(Send_field *tmp_field)
5185
5236
{
5186
 
  Field *field;
5187
5237
  DBUG_ENTER("Item_func_sp::make_field");
5188
 
  if ((field= sp_result_field()))
5189
 
  {
5190
 
    field->make_field(tmp_field);
5191
 
    delete field;
5192
 
    DBUG_VOID_RETURN;
5193
 
  }
5194
 
  init_make_field(tmp_field, MYSQL_TYPE_VARCHAR);  
 
5238
  DBUG_ASSERT(sp_result_field);
 
5239
  sp_result_field->make_field(tmp_field);
5195
5240
  DBUG_VOID_RETURN;
5196
5241
}
5197
5242
 
5199
5244
enum enum_field_types
5200
5245
Item_func_sp::field_type() const
5201
5246
{
5202
 
  Field *field;
5203
5247
  DBUG_ENTER("Item_func_sp::field_type");
5204
 
 
5205
 
  if (result_field)
5206
 
    DBUG_RETURN(result_field->type());
5207
 
  if ((field= sp_result_field()))
5208
 
  {
5209
 
    enum_field_types result= field->type();
5210
 
    delete field;
5211
 
    DBUG_RETURN(result);
5212
 
  }
5213
 
  DBUG_RETURN(MYSQL_TYPE_VARCHAR);
 
5248
  DBUG_ASSERT(sp_result_field);
 
5249
  DBUG_RETURN(sp_result_field->type());
5214
5250
}
5215
5251
 
5216
 
 
5217
5252
Item_result
5218
5253
Item_func_sp::result_type() const
5219
5254
{
5220
 
  Field *field;
5221
5255
  DBUG_ENTER("Item_func_sp::result_type");
5222
5256
  DBUG_PRINT("info", ("m_sp = %p", m_sp));
5223
 
 
5224
 
  if (result_field)
5225
 
    DBUG_RETURN(result_field->result_type());
5226
 
  if ((field= sp_result_field()))
5227
 
  {
5228
 
    Item_result result= field->result_type();
5229
 
    delete field;
5230
 
    DBUG_RETURN(result);
5231
 
  }
5232
 
  DBUG_RETURN(STRING_RESULT);
5233
 
}
5234
 
 
5235
 
void
5236
 
Item_func_sp::fix_length_and_dec()
5237
 
{
5238
 
  Field *field;
5239
 
  DBUG_ENTER("Item_func_sp::fix_length_and_dec");
5240
 
 
5241
 
  if (result_field)
5242
 
  {
5243
 
    decimals= result_field->decimals();
5244
 
    max_length= result_field->field_length;
5245
 
    collation.set(result_field->charset());
5246
 
    DBUG_VOID_RETURN;
5247
 
  }
5248
 
 
5249
 
  if (!(field= sp_result_field()))
5250
 
  {
5251
 
    context->process_error(current_thd);
5252
 
    DBUG_VOID_RETURN;
5253
 
  }
5254
 
  decimals= field->decimals();
5255
 
  max_length= field->field_length;
5256
 
  collation.set(field->charset());
5257
 
  maybe_null= 1;
5258
 
  delete field;
5259
 
  DBUG_VOID_RETURN;
5260
 
}
5261
 
 
 
5257
  DBUG_ASSERT(sp_result_field);
 
5258
  DBUG_RETURN(sp_result_field->result_type());
 
5259
}
5262
5260
 
5263
5261
longlong Item_func_found_rows::val_int()
5264
5262
{
5270
5268
Field *
5271
5269
Item_func_sp::tmp_table_field(TABLE *t_arg)
5272
5270
{
5273
 
  Field *field= 0;
5274
5271
  DBUG_ENTER("Item_func_sp::tmp_table_field");
5275
5272
 
5276
 
  if (m_sp)
5277
 
    field= m_sp->create_result_field(max_length, (const char*) name, t_arg);
5278
 
  
5279
 
  if (!field) 
5280
 
    field= Item_func::tmp_table_field(t_arg);
5281
 
 
5282
 
  if (!field)
5283
 
    my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
5284
 
 
5285
 
  DBUG_RETURN(field);
 
5273
  DBUG_ASSERT(sp_result_field);
 
5274
  DBUG_RETURN(sp_result_field);
5286
5275
}
5287
5276
 
5288
5277
 
5289
 
/*
5290
 
  Find the function and check access rights to the function
5291
 
 
5292
 
  SYNOPSIS
5293
 
    find_and_check_access()
5294
 
    thd           thread handler
5295
 
 
5296
 
  RETURN
5297
 
    FALSE    Access granted
5298
 
    TRUE     Requested access can't be granted or function doesn't exists
5299
 
 
5300
 
  NOTES
5301
 
    Checks if requested access to function can be granted to user.
 
5278
/**
 
5279
  @brief Checks if requested access to function can be granted to user.
5302
5280
    If function isn't found yet, it searches function first.
5303
5281
    If function can't be found or user don't have requested access
5304
5282
    error is raised.
 
5283
 
 
5284
  @param thd thread handler
 
5285
 
 
5286
  @return Indication if the access was granted or not.
 
5287
  @retval FALSE Access is granted.
 
5288
  @retval TRUE Requested access can't be granted or function doesn't exists.
 
5289
    
5305
5290
*/
5306
5291
 
5307
5292
bool
5308
 
Item_func_sp::find_and_check_access(THD *thd)
 
5293
Item_func_sp::sp_check_access(THD *thd)
5309
5294
{
5310
 
  if (! m_sp && ! (m_sp= sp_find_routine(thd, TYPE_ENUM_FUNCTION, m_name,
5311
 
                                         &thd->sp_func_cache, TRUE)))
5312
 
  {
5313
 
    my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", m_name->m_qname.str);
5314
 
    return TRUE;
5315
 
  }
5316
 
 
 
5295
  DBUG_ENTER("Item_func_sp::sp_check_access");
 
5296
  DBUG_ASSERT(m_sp);
5317
5297
#ifndef NO_EMBEDDED_ACCESS_CHECKS
5318
5298
  if (check_routine_access(thd, EXECUTE_ACL,
5319
5299
                           m_sp->m_db.str, m_sp->m_name.str, 0, FALSE))
5320
 
    return TRUE;
 
5300
    DBUG_RETURN(TRUE);
5321
5301
#endif
5322
5302
 
5323
 
  return FALSE;
 
5303
  DBUG_RETURN(FALSE);
5324
5304
}
5325
5305
 
5326
5306
 
5328
5308
Item_func_sp::fix_fields(THD *thd, Item **ref)
5329
5309
{
5330
5310
  bool res;
 
5311
  DBUG_ENTER("Item_func_sp::fix_fields");
5331
5312
  DBUG_ASSERT(fixed == 0);
 
5313
 
 
5314
  /*
 
5315
    We must call init_result_field before Item_func::fix_fields() 
 
5316
    to make m_sp and result_field members available to fix_length_and_dec(),
 
5317
    which is called from Item_func::fix_fields().
 
5318
  */
 
5319
  res= init_result_field(thd);
 
5320
 
 
5321
  if (res)
 
5322
    DBUG_RETURN(res);
 
5323
 
5332
5324
  res= Item_func::fix_fields(thd, ref);
5333
 
  if (!res && thd->lex->view_prepare_mode)
 
5325
 
 
5326
  if (res)
 
5327
    DBUG_RETURN(res);
 
5328
 
 
5329
  if (thd->lex->view_prepare_mode)
5334
5330
  {
5335
5331
    /*
5336
5332
      Here we check privileges of the stored routine only during view
5342
5338
      good idea especially if the view has SQL SECURITY DEFINER and
5343
5339
      the used stored procedure has SQL SECURITY DEFINER.
5344
5340
    */
5345
 
    res= find_and_check_access(thd);
 
5341
    res= sp_check_access(thd);
5346
5342
#ifndef NO_EMBEDDED_ACCESS_CHECKS
 
5343
    /*
 
5344
      Try to set and restore the security context to see whether it's valid
 
5345
    */
5347
5346
    Security_context *save_secutiry_ctx;
5348
 
    if (!res && !(res= set_routine_security_ctx(thd, m_sp, false,
5349
 
                                                &save_secutiry_ctx)))
5350
 
    {
 
5347
    res= set_routine_security_ctx(thd, m_sp, false, &save_secutiry_ctx);
 
5348
    if (!res)
5351
5349
      sp_restore_security_context(thd, save_secutiry_ctx);
5352
 
    }
 
5350
    
5353
5351
#endif /* ! NO_EMBEDDED_ACCESS_CHECKS */
5354
5352
  }
5355
 
  return res;
 
5353
  DBUG_RETURN(res);
5356
5354
}