~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to sql/sql_show.cc

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2010-06-21 15:31:05 UTC
  • mfrom: (1.1.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20100621153105-pbbz3t6nyrf9t2zq
Tags: upstream-5.1.48
ImportĀ upstreamĀ versionĀ 5.1.48

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include "event_data_objects.h"
31
31
#endif
32
32
#include <my_dir.h>
 
33
#include "debug_sync.h"
33
34
 
34
35
#define STR_OR_NIL(S) ((S) ? (S) : "<nil>")
35
36
 
3450
3451
            lex->sql_command= SQLCOM_SHOW_FIELDS;
3451
3452
            show_table_list->i_s_requested_object=
3452
3453
              schema_table->i_s_requested_object;
 
3454
            DEBUG_SYNC(thd, "before_open_in_get_all_tables");
3453
3455
            res= open_normal_and_derived_tables(thd, show_table_list,
3454
3456
                                                MYSQL_LOCK_IGNORE_FLUSH);
3455
3457
            lex->sql_command= save_sql_command;
4180
4182
}
4181
4183
 
4182
4184
 
 
4185
static inline void copy_field_as_string(Field *to_field, Field *from_field)
 
4186
{
 
4187
  char buff[MAX_FIELD_WIDTH];
 
4188
  String tmp_str(buff, sizeof(buff), system_charset_info);
 
4189
  from_field->val_str(&tmp_str);
 
4190
  to_field->store(tmp_str.ptr(), tmp_str.length(), system_charset_info);
 
4191
}
 
4192
 
 
4193
 
4183
4194
bool store_schema_proc(THD *thd, TABLE *table, TABLE *proc_table,
4184
4195
                       const char *wild, bool full_access, const char *sp_user)
4185
4196
{
4186
 
  String tmp_string;
4187
 
  String sp_db, sp_name, definer;
4188
4197
  MYSQL_TIME time;
4189
4198
  LEX *lex= thd->lex;
4190
4199
  CHARSET_INFO *cs= system_charset_info;
4191
 
  get_field(thd->mem_root, proc_table->field[0], &sp_db);
4192
 
  get_field(thd->mem_root, proc_table->field[1], &sp_name);
4193
 
  get_field(thd->mem_root, proc_table->field[11], &definer);
 
4200
  char sp_db_buff[NAME_LEN + 1], sp_name_buff[NAME_LEN + 1],
 
4201
    definer_buff[USERNAME_LENGTH + HOSTNAME_LENGTH + 2];
 
4202
  String sp_db(sp_db_buff, sizeof(sp_db_buff), cs);
 
4203
  String sp_name(sp_name_buff, sizeof(sp_name_buff), cs);
 
4204
  String definer(definer_buff, sizeof(definer_buff), cs);
 
4205
 
 
4206
  proc_table->field[0]->val_str(&sp_db);
 
4207
  proc_table->field[1]->val_str(&sp_name);
 
4208
  proc_table->field[11]->val_str(&definer);
 
4209
 
4194
4210
  if (!full_access)
4195
 
    full_access= !strcmp(sp_user, definer.ptr());
4196
 
  if (!full_access && check_some_routine_access(thd, sp_db.ptr(),
4197
 
                                                sp_name.ptr(),
4198
 
                                                proc_table->field[2]->
4199
 
                                                val_int() ==
4200
 
                                                TYPE_ENUM_PROCEDURE))
 
4211
    full_access= !strcmp(sp_user, definer.c_ptr_safe());
 
4212
  if (!full_access &&
 
4213
      check_some_routine_access(thd, sp_db.c_ptr_safe(), sp_name.c_ptr_safe(),
 
4214
                                proc_table->field[2]->val_int() ==
 
4215
                                TYPE_ENUM_PROCEDURE))
4201
4216
    return 0;
4202
4217
 
4203
4218
  if ((lex->sql_command == SQLCOM_SHOW_STATUS_PROC &&
4207
4222
      (sql_command_flags[lex->sql_command] & CF_STATUS_COMMAND) == 0)
4208
4223
  {
4209
4224
    restore_record(table, s->default_values);
4210
 
    if (!wild || !wild[0] || !wild_compare(sp_name.ptr(), wild, 0))
 
4225
    if (!wild || !wild[0] || !wild_compare(sp_name.c_ptr_safe(), wild, 0))
4211
4226
    {
4212
4227
      int enum_idx= (int) proc_table->field[5]->val_int();
4213
4228
      table->field[3]->store(sp_name.ptr(), sp_name.length(), cs);
4214
 
      get_field(thd->mem_root, proc_table->field[3], &tmp_string);
4215
 
      table->field[0]->store(tmp_string.ptr(), tmp_string.length(), cs);
 
4229
      copy_field_as_string(table->field[0], proc_table->field[3]);
4216
4230
      table->field[2]->store(sp_db.ptr(), sp_db.length(), cs);
4217
 
      get_field(thd->mem_root, proc_table->field[2], &tmp_string);
4218
 
      table->field[4]->store(tmp_string.ptr(), tmp_string.length(), cs);
 
4231
      copy_field_as_string(table->field[4], proc_table->field[2]);
4219
4232
      if (proc_table->field[2]->val_int() == TYPE_ENUM_FUNCTION)
4220
4233
      {
4221
 
        get_field(thd->mem_root, proc_table->field[9], &tmp_string);
4222
 
        table->field[5]->store(tmp_string.ptr(), tmp_string.length(), cs);
 
4234
        copy_field_as_string(table->field[5], proc_table->field[9]);
4223
4235
        table->field[5]->set_notnull();
4224
4236
      }
4225
4237
      if (full_access)
4226
4238
      {
4227
 
        get_field(thd->mem_root, proc_table->field[19], &tmp_string);
4228
 
        table->field[7]->store(tmp_string.ptr(), tmp_string.length(), cs);
 
4239
        copy_field_as_string(table->field[7], proc_table->field[19]);
4229
4240
        table->field[7]->set_notnull();
4230
4241
      }
4231
4242
      table->field[6]->store(STRING_WITH_LEN("SQL"), cs);
4232
4243
      table->field[10]->store(STRING_WITH_LEN("SQL"), cs);
4233
 
      get_field(thd->mem_root, proc_table->field[6], &tmp_string);
4234
 
      table->field[11]->store(tmp_string.ptr(), tmp_string.length(), cs);
 
4244
      copy_field_as_string(table->field[11], proc_table->field[6]);
4235
4245
      table->field[12]->store(sp_data_access_name[enum_idx].str, 
4236
4246
                              sp_data_access_name[enum_idx].length , cs);
4237
 
      get_field(thd->mem_root, proc_table->field[7], &tmp_string);
4238
 
      table->field[14]->store(tmp_string.ptr(), tmp_string.length(), cs);
 
4247
      copy_field_as_string(table->field[14], proc_table->field[7]);
 
4248
 
4239
4249
      bzero((char *)&time, sizeof(time));
4240
4250
      ((Field_timestamp *) proc_table->field[12])->get_time(&time);
4241
4251
      table->field[15]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
4242
4252
      bzero((char *)&time, sizeof(time));
4243
4253
      ((Field_timestamp *) proc_table->field[13])->get_time(&time);
4244
4254
      table->field[16]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
4245
 
      get_field(thd->mem_root, proc_table->field[14], &tmp_string);
4246
 
      table->field[17]->store(tmp_string.ptr(), tmp_string.length(), cs);
4247
 
      get_field(thd->mem_root, proc_table->field[15], &tmp_string);
4248
 
      table->field[18]->store(tmp_string.ptr(), tmp_string.length(), cs);
 
4255
      copy_field_as_string(table->field[17], proc_table->field[14]);
 
4256
      copy_field_as_string(table->field[18], proc_table->field[15]);
4249
4257
      table->field[19]->store(definer.ptr(), definer.length(), cs);
4250
 
 
4251
 
      get_field(thd->mem_root, proc_table->field[16], &tmp_string);
4252
 
      table->field[20]->store(tmp_string.ptr(), tmp_string.length(), cs);
4253
 
 
4254
 
      get_field(thd->mem_root, proc_table->field[17], &tmp_string);
4255
 
      table->field[21]->store(tmp_string.ptr(), tmp_string.length(), cs);
4256
 
 
4257
 
      get_field(thd->mem_root, proc_table->field[18], &tmp_string);
4258
 
      table->field[22]->store(tmp_string.ptr(), tmp_string.length(), cs);
 
4258
      copy_field_as_string(table->field[20], proc_table->field[16]);
 
4259
      copy_field_as_string(table->field[21], proc_table->field[17]);
 
4260
      copy_field_as_string(table->field[22], proc_table->field[18]);
4259
4261
 
4260
4262
      return schema_table_store_record(thd, table);
4261
4263
    }