4185
static inline void copy_field_as_string(Field *to_field, Field *from_field)
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);
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)
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);
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);
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(),
4198
proc_table->field[2]->
4200
TYPE_ENUM_PROCEDURE))
4211
full_access= !strcmp(sp_user, definer.c_ptr_safe());
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))
4203
4218
if ((lex->sql_command == SQLCOM_SHOW_STATUS_PROC &&
4207
4222
(sql_command_flags[lex->sql_command] & CF_STATUS_COMMAND) == 0)
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))
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)
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();
4225
4237
if (full_access)
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();
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]);
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);
4251
get_field(thd->mem_root, proc_table->field[16], &tmp_string);
4252
table->field[20]->store(tmp_string.ptr(), tmp_string.length(), cs);
4254
get_field(thd->mem_root, proc_table->field[17], &tmp_string);
4255
table->field[21]->store(tmp_string.ptr(), tmp_string.length(), cs);
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]);
4260
4262
return schema_table_store_record(thd, table);