42 { C_STRING_WITH_LEN(
"db") },
43 { C_STRING_WITH_LEN(
"char(64)") },
44 { C_STRING_WITH_LEN(
"utf8") }
47 { C_STRING_WITH_LEN(
"name") },
48 { C_STRING_WITH_LEN(
"char(64)") },
49 { C_STRING_WITH_LEN(
"utf8") }
52 { C_STRING_WITH_LEN(
"body") },
53 { C_STRING_WITH_LEN(
"longblob") },
57 { C_STRING_WITH_LEN(
"definer") },
58 { C_STRING_WITH_LEN(
"char(77)") },
59 { C_STRING_WITH_LEN(
"utf8") }
62 { C_STRING_WITH_LEN(
"execute_at") },
63 { C_STRING_WITH_LEN(
"datetime") },
67 { C_STRING_WITH_LEN(
"interval_value") },
68 { C_STRING_WITH_LEN(
"int(11)") },
72 { C_STRING_WITH_LEN(
"interval_field") },
73 { C_STRING_WITH_LEN(
"enum('YEAR','QUARTER','MONTH','DAY',"
74 "'HOUR','MINUTE','WEEK','SECOND','MICROSECOND','YEAR_MONTH','DAY_HOUR',"
75 "'DAY_MINUTE','DAY_SECOND','HOUR_MINUTE','HOUR_SECOND','MINUTE_SECOND',"
76 "'DAY_MICROSECOND','HOUR_MICROSECOND','MINUTE_MICROSECOND',"
77 "'SECOND_MICROSECOND')") },
81 { C_STRING_WITH_LEN(
"created") },
82 { C_STRING_WITH_LEN(
"timestamp") },
86 { C_STRING_WITH_LEN(
"modified") },
87 { C_STRING_WITH_LEN(
"timestamp") },
91 { C_STRING_WITH_LEN(
"last_executed") },
92 { C_STRING_WITH_LEN(
"datetime") },
96 { C_STRING_WITH_LEN(
"starts") },
97 { C_STRING_WITH_LEN(
"datetime") },
101 { C_STRING_WITH_LEN(
"ends") },
102 { C_STRING_WITH_LEN(
"datetime") },
106 { C_STRING_WITH_LEN(
"status") },
107 { C_STRING_WITH_LEN(
"enum('ENABLED','DISABLED','SLAVESIDE_DISABLED')") },
111 { C_STRING_WITH_LEN(
"on_completion") },
112 { C_STRING_WITH_LEN(
"enum('DROP','PRESERVE')") },
116 { C_STRING_WITH_LEN(
"sql_mode") },
117 { C_STRING_WITH_LEN(
"set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES',"
118 "'IGNORE_SPACE','NOT_USED','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION',"
119 "'NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB',"
120 "'NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40',"
121 "'ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES',"
122 "'STRICT_ALL_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','INVALID_DATES',"
123 "'ERROR_FOR_DIVISION_BY_ZERO','TRADITIONAL','NO_AUTO_CREATE_USER',"
124 "'HIGH_NOT_PRECEDENCE','NO_ENGINE_SUBSTITUTION','PAD_CHAR_TO_FULL_LENGTH')") },
128 { C_STRING_WITH_LEN(
"comment") },
129 { C_STRING_WITH_LEN(
"char(64)") },
130 { C_STRING_WITH_LEN(
"utf8") }
133 { C_STRING_WITH_LEN(
"originator") },
134 { C_STRING_WITH_LEN(
"int(10)") },
138 { C_STRING_WITH_LEN(
"time_zone") },
139 { C_STRING_WITH_LEN(
"char(64)") },
140 { C_STRING_WITH_LEN(
"latin1") }
143 { C_STRING_WITH_LEN(
"character_set_client") },
144 { C_STRING_WITH_LEN(
"char(32)") },
145 { C_STRING_WITH_LEN(
"utf8") }
148 { C_STRING_WITH_LEN(
"collation_connection") },
149 { C_STRING_WITH_LEN(
"char(32)") },
150 { C_STRING_WITH_LEN(
"utf8") }
153 { C_STRING_WITH_LEN(
"db_collation") },
154 { C_STRING_WITH_LEN(
"char(32)") },
155 { C_STRING_WITH_LEN(
"utf8") }
158 { C_STRING_WITH_LEN(
"body_utf8") },
159 { C_STRING_WITH_LEN(
"longblob") },
165 event_table_def= {ET_FIELD_COUNT, event_table_fields};
170 void report_error(uint,
const char *
fmt, ...)
174 error_log_print(ERROR_LEVEL, fmt, args);
199 mysql_event_fill_row(THD *thd,
207 enum enum_events_table_field f_num;
208 Field **fields= table->field;
211 DBUG_ENTER(
"mysql_event_fill_row");
213 DBUG_PRINT(
"info", (
"dbname=[%s]", et->dbname.str));
214 DBUG_PRINT(
"info", (
"name =[%s]", et->name.str));
216 DBUG_ASSERT(et->on_completion != Event_parse_data::ON_COMPLETION_DEFAULT);
218 if (table->s->fields < ET_FIELD_COUNT)
224 my_error(ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2, MYF(0),
225 table->s->db.str, table->s->table_name.str,
226 (
int) ET_FIELD_COUNT, table->s->fields);
230 if (fields[f_num= ET_FIELD_DEFINER]->
231 store(et->definer.str, et->definer.length, scs))
234 if (fields[f_num= ET_FIELD_DB]->store(et->dbname.str, et->dbname.length, scs))
237 if (fields[f_num= ET_FIELD_NAME]->store(et->name.str, et->name.length, scs))
241 rs|= fields[ET_FIELD_ON_COMPLETION]->store((longlong)et->on_completion, TRUE);
248 if (!is_update || et->status_changed)
249 rs|= fields[ET_FIELD_STATUS]->store((longlong)et->status, TRUE);
250 rs|= fields[ET_FIELD_ORIGINATOR]->store((longlong)et->originator, TRUE);
256 if (et->body_changed)
258 DBUG_ASSERT(sp->m_body.str);
260 rs|= fields[ET_FIELD_SQL_MODE]->store((longlong)sql_mode, TRUE);
262 if (fields[f_num= ET_FIELD_BODY]->store(sp->m_body.str,
272 const String *tz_name= thd->variables.time_zone->get_name();
273 if (!is_update || !et->starts_null)
275 fields[ET_FIELD_TIME_ZONE]->set_notnull();
276 rs|= fields[ET_FIELD_TIME_ZONE]->store(tz_name->ptr(), tz_name->length(),
280 fields[ET_FIELD_INTERVAL_EXPR]->set_notnull();
281 rs|= fields[ET_FIELD_INTERVAL_EXPR]->store((longlong)et->expression, TRUE);
283 fields[ET_FIELD_TRANSIENT_INTERVAL]->set_notnull();
285 rs|= fields[ET_FIELD_TRANSIENT_INTERVAL]->
286 store(interval_type_to_name[et->interval].str,
287 interval_type_to_name[et->interval].length,
290 fields[ET_FIELD_EXECUTE_AT]->set_null();
292 if (!et->starts_null)
297 fields[ET_FIELD_STARTS]->set_notnull();
306 fields[ET_FIELD_ENDS]->set_notnull();
310 else if (et->execute_at)
312 const String *tz_name= thd->variables.time_zone->get_name();
313 fields[ET_FIELD_TIME_ZONE]->set_notnull();
314 rs|= fields[ET_FIELD_TIME_ZONE]->store(tz_name->ptr(), tz_name->length(),
317 fields[ET_FIELD_INTERVAL_EXPR]->set_null();
318 fields[ET_FIELD_TRANSIENT_INTERVAL]->set_null();
319 fields[ET_FIELD_STARTS]->set_null();
320 fields[ET_FIELD_ENDS]->set_null();
325 fields[ET_FIELD_EXECUTE_AT]->set_notnull();
326 fields[ET_FIELD_EXECUTE_AT]->
store_time(&time);
330 DBUG_ASSERT(is_update);
341 if (fields[f_num= ET_FIELD_COMMENT]->
342 store(et->comment.str, et->comment.length, scs))
346 fields[ET_FIELD_CHARACTER_SET_CLIENT]->set_notnull();
347 rs|= fields[ET_FIELD_CHARACTER_SET_CLIENT]->store(
348 thd->variables.character_set_client->csname,
349 strlen(thd->variables.character_set_client->csname),
350 system_charset_info);
352 fields[ET_FIELD_COLLATION_CONNECTION]->set_notnull();
353 rs|= fields[ET_FIELD_COLLATION_CONNECTION]->store(
354 thd->variables.collation_connection->name,
355 strlen(thd->variables.collation_connection->name),
356 system_charset_info);
359 const CHARSET_INFO *db_cl= get_default_db_collation(thd, et->dbname.str);
361 fields[ET_FIELD_DB_COLLATION]->set_notnull();
362 rs|= fields[ET_FIELD_DB_COLLATION]->store(db_cl->name,
364 system_charset_info);
367 if (et->body_changed)
369 fields[ET_FIELD_BODY_UTF8]->set_notnull();
370 rs|= fields[ET_FIELD_BODY_UTF8]->store(sp->m_body_utf8.str,
371 sp->m_body_utf8.length,
372 system_charset_info);
377 my_error(ER_EVENT_STORE_FAILED, MYF(0), fields[f_num]->field_name, rs);
384 my_error(ER_EVENT_DATA_TOO_LONG, MYF(0), fields[f_num]->field_name);
405 Event_db_repository::index_read_for_db_for_i_s(THD *thd,
TABLE *schema_table,
412 uchar *key_buf= NULL;
415 DBUG_ENTER(
"Event_db_repository::index_read_for_db_for_i_s");
417 DBUG_PRINT(
"info", (
"Using prefix scanning on PK"));
426 key_info= event_table->key_info;
429 key_info->key_part[0].field != event_table->field[ET_FIELD_DB])
432 my_error(ER_CANNOT_LOAD_FROM_TABLE_V2, MYF(0),
"mysql",
"event");
437 event_table->field[ET_FIELD_DB]->store(db, strlen(db), scs);
438 key_len= key_info->key_part[0].store_length;
440 if (!(key_buf= (uchar *)alloc_root(thd->mem_root, key_len)))
447 key_copy(key_buf, event_table->record[0], key_info, key_len);
452 DBUG_PRINT(
"info",(
"Found rows. Let's retrieve them. ret=%d", ret));
455 ret= copy_event_to_schema_table(thd, schema_table, event_table);
461 DBUG_PRINT(
"info", (
"Scan finished. ret=%d", ret));
464 if (ret == HA_ERR_END_OF_FILE || ret == HA_ERR_KEY_NOT_FOUND)
472 DBUG_RETURN(
test(ret));
491 Event_db_repository::table_scan_all_for_i_s(THD *thd,
TABLE *schema_table,
496 DBUG_ENTER(
"Event_db_repository::table_scan_all_for_i_s");
498 if (init_read_record(&read_record_info, thd, event_table, NULL, 1, 1, FALSE))
508 ret= read_record_info.read_record(&read_record_info);
510 ret= copy_event_to_schema_table(thd, schema_table, event_table);
513 DBUG_PRINT(
"info", (
"Scan finished. ret=%d", ret));
514 end_read_record(&read_record_info);
517 DBUG_RETURN(ret == -1 ? FALSE : TRUE);
539 TABLE *schema_table= i_s_table->table;
540 Open_tables_backup open_tables_backup;
544 DBUG_ENTER(
"Event_db_repository::fill_schema_events");
545 DBUG_PRINT(
"info",(
"db=%s", db? db:
"(null)"));
547 event_table.
init_one_table(
"mysql", 5,
"event", 5,
"event", TL_READ);
549 if (open_system_tables_for_read(thd, &event_table, &open_tables_backup))
552 if (!event_table.table->key_info)
554 close_system_tables(thd, &open_tables_backup);
555 my_error(ER_TABLE_CORRUPT, MYF(0), event_table.table->s->db.str,
556 event_table.table->s->table_name.str);
560 if (table_intact.
check(event_table.table, &event_table_def))
562 close_system_tables(thd, &open_tables_backup);
563 my_error(ER_EVENT_OPEN_TABLE_FAILED, MYF(0));
577 ret= index_read_for_db_for_i_s(thd, schema_table, event_table.table, db);
579 ret= table_scan_all_for_i_s(thd, schema_table, event_table.table);
581 close_system_tables(thd, &open_tables_backup);
583 DBUG_PRINT(
"info", (
"Return code=%d", ret));
615 DBUG_ENTER(
"Event_db_repository::open_event_table");
617 tables.
init_one_table(
"mysql", 5,
"event", 5,
"event", lock_type);
622 *table= tables.table;
623 tables.table->use_all_columns();
625 if (table_intact.
check(*table, &event_table_def))
627 close_thread_tables(thd);
628 my_error(ER_EVENT_OPEN_TABLE_FAILED, MYF(0));
660 bool *event_already_exists)
665 sql_mode_t saved_mode= thd->variables.sql_mode;
671 MDL_savepoint mdl_savepoint= thd->mdl_context.mdl_savepoint();
673 DBUG_ENTER(
"Event_db_repository::create_event");
675 DBUG_PRINT(
"info", (
"open mysql.event for update"));
679 thd->variables.sql_mode= 0;
684 DBUG_PRINT(
"info", (
"name: %.*s", (
int) parse_data->name.length,
685 parse_data->name.str));
687 DBUG_PRINT(
"info", (
"check existance of an event with the same name"));
692 *event_already_exists=
true;
693 push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
694 ER_EVENT_ALREADY_EXISTS, ER(ER_EVENT_ALREADY_EXISTS),
695 parse_data->name.str);
699 my_error(ER_EVENT_ALREADY_EXISTS, MYF(0), parse_data->name.str);
703 *event_already_exists=
false;
705 DBUG_PRINT(
"info", (
"non-existent, go forward"));
707 restore_record(table, s->default_values);
709 if (system_charset_info->cset->
710 numchars(system_charset_info, parse_data->dbname.str,
711 parse_data->dbname.str + parse_data->dbname.length) >
712 table->field[ET_FIELD_DB]->char_length())
714 my_error(ER_TOO_LONG_IDENT, MYF(0), parse_data->dbname.str);
718 if (system_charset_info->cset->
719 numchars(system_charset_info, parse_data->name.str,
720 parse_data->name.str + parse_data->name.length) >
721 table->field[ET_FIELD_NAME]->char_length())
723 my_error(ER_TOO_LONG_IDENT, MYF(0), parse_data->name.str);
727 if (sp->m_body.length > table->field[ET_FIELD_BODY]->field_length)
729 my_error(ER_TOO_LONG_BODY, MYF(0), parse_data->name.str);
739 if (mysql_event_fill_row(thd, table, parse_data, sp, saved_mode, FALSE))
742 if ((ret= table->file->ha_write_row(table->record[0])))
750 close_thread_tables(thd);
751 thd->mdl_context.rollback_to_savepoint(mdl_savepoint);
753 thd->variables.sql_mode= saved_mode;
754 DBUG_RETURN(
test(ret));
784 sql_mode_t saved_mode= thd->variables.sql_mode;
790 MDL_savepoint mdl_savepoint= thd->mdl_context.mdl_savepoint();
793 DBUG_ENTER(
"Event_db_repository::update_event");
796 DBUG_ASSERT((new_dbname && new_name) || new_dbname == new_name);
799 thd->variables.sql_mode= 0;
804 DBUG_PRINT(
"info", (
"dbname: %s", parse_data->dbname.str));
805 DBUG_PRINT(
"info", (
"name: %s", parse_data->name.str));
806 DBUG_PRINT(
"info", (
"user: %s", parse_data->definer.str));
811 DBUG_PRINT(
"info", (
"rename to: %s@%s", new_dbname->str, new_name->str));
814 my_error(ER_EVENT_ALREADY_EXISTS, MYF(0), new_name->str);
826 my_error(ER_EVENT_DOES_NOT_EXIST, MYF(0), parse_data->name.str);
830 store_record(table,
record[1]);
840 if (parse_data->check_dates(thd,
841 (
int) table->field[ET_FIELD_ON_COMPLETION]->val_int()))
848 if (mysql_event_fill_row(thd, table, parse_data, sp, saved_mode, TRUE))
853 table->field[ET_FIELD_DB]->store(new_dbname->str, new_dbname->length, scs);
854 table->field[ET_FIELD_NAME]->store(new_name->str, new_name->length, scs);
857 if ((ret= table->file->ha_update_row(table->record[1], table->record[0])))
865 close_thread_tables(thd);
866 thd->mdl_context.rollback_to_savepoint(mdl_savepoint);
868 thd->variables.sql_mode= saved_mode;
869 DBUG_RETURN(
test(ret));
897 MDL_savepoint mdl_savepoint= thd->mdl_context.mdl_savepoint();
900 DBUG_ENTER(
"Event_db_repository::drop_event");
901 DBUG_PRINT(
"enter", (
"%s@%s", db.str, name.str));
908 if ((ret= table->file->ha_delete_row(table->record[0])))
916 my_error(ER_EVENT_DOES_NOT_EXIST, MYF(0), name.str);
920 push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
921 ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST),
926 close_thread_tables(thd);
927 thd->mdl_context.rollback_to_savepoint(mdl_savepoint);
929 DBUG_RETURN(
test(ret));
952 uchar key[MAX_KEY_LENGTH];
953 DBUG_ENTER(
"Event_db_repository::find_named_event");
954 DBUG_PRINT(
"enter", (
"name: %.*s", (
int) name.length, name.str));
963 if (db.length > table->field[ET_FIELD_DB]->field_length ||
964 name.length > table->field[ET_FIELD_NAME]->field_length)
967 if (!table->key_info)
969 my_error(ER_TABLE_CORRUPT, MYF(0), table->s->db.str,
970 table->s->table_name.str);
974 table->field[ET_FIELD_DB]->store(db.str, db.length, &my_charset_bin);
975 table->field[ET_FIELD_NAME]->store(name.str, name.length, &my_charset_bin);
977 key_copy(key, table->record[0], table->key_info, table->key_info->
key_length);
982 DBUG_PRINT(
"info", (
"Row not found"));
986 DBUG_PRINT(
"info", (
"Row found!"));
1001 Event_db_repository::drop_schema_events(THD *thd,
LEX_STRING schema)
1006 enum enum_events_table_field field= ET_FIELD_DB;
1007 MDL_savepoint mdl_savepoint= thd->mdl_context.mdl_savepoint();
1008 DBUG_ENTER(
"Event_db_repository::drop_schema_events");
1009 DBUG_PRINT(
"enter", (
"field=%d schema=%s", field, schema.str));
1015 if (init_read_record(&read_record_info, thd, table, NULL, 1, 1, FALSE))
1017 while (!ret && !(read_record_info.read_record(&read_record_info)) )
1019 char *et_field= get_field(thd->mem_root, table->field[field]);
1024 LEX_STRING et_field_lex= { et_field, strlen(et_field) };
1025 DBUG_PRINT(
"info", (
"Current event %s name=%s", et_field,
1026 get_field(thd->mem_root,
1027 table->field[ET_FIELD_NAME])));
1029 if (!sortcmp_lex_string(et_field_lex, schema, system_charset_info))
1031 DBUG_PRINT(
"info", (
"Dropping"));
1032 if ((ret= table->file->ha_delete_row(table->record[0])))
1037 end_read_record(&read_record_info);
1038 close_thread_tables(thd);
1043 thd->mdl_context.rollback_to_savepoint(mdl_savepoint);
1064 sql_mode_t saved_mode= thd->variables.sql_mode;
1065 Open_tables_backup open_tables_backup;
1068 DBUG_ENTER(
"Event_db_repository::load_named_event");
1069 DBUG_PRINT(
"enter",(
"thd: 0x%lx name: %*s", (
long) thd,
1070 (
int) name.length, name.str));
1072 event_table.
init_one_table(
"mysql", 5,
"event", 5,
"event", TL_READ);
1075 thd->variables.sql_mode= 0;
1083 if (!(ret= open_system_tables_for_read(thd, &event_table, &open_tables_backup)))
1085 if (table_intact.
check(event_table.table, &event_table_def))
1087 close_system_tables(thd, &open_tables_backup);
1088 my_error(ER_EVENT_OPEN_TABLE_FAILED, MYF(0));
1093 my_error(ER_EVENT_DOES_NOT_EXIST, MYF(0), name.str);
1094 else if ((ret= etn->load_from_row(thd, event_table.table)))
1095 my_error(ER_CANNOT_LOAD_FROM_TABLE_V2, MYF(0),
"mysql",
"event");
1097 close_system_tables(thd, &open_tables_backup);
1100 thd->variables.sql_mode= saved_mode;
1117 my_time_t last_executed,
1123 bool save_binlog_row_based;
1126 DBUG_ENTER(
"Event_db_repository::update_timing_fields_for_event");
1132 if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
1133 thd->clear_current_stmt_binlog_format_row();
1135 DBUG_ASSERT(thd->security_ctx->master_access & SUPER_ACL);
1140 fields= table->field;
1145 store_record(table,
record[1]);
1148 fields[ET_FIELD_LAST_EXECUTED]->set_notnull();
1149 fields[ET_FIELD_LAST_EXECUTED]->
store_time(&time);
1151 fields[ET_FIELD_STATUS]->set_notnull();
1152 fields[ET_FIELD_STATUS]->store(status, TRUE);
1154 if ((ret= table->file->ha_update_row(table->record[1], table->record[0])))
1167 DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
1168 if (save_binlog_row_based)
1169 thd->set_current_stmt_binlog_format_row();
1171 DBUG_RETURN(
test(ret));
1194 const unsigned int event_priv_column_position= 29;
1196 DBUG_ENTER(
"Event_db_repository::check_system_tables");
1197 DBUG_PRINT(
"enter", (
"thd: 0x%lx", (
long) thd));
1205 sql_print_error(
"Cannot open mysql.db");
1209 if (table_intact.
check(tables.table, &mysql_db_table_def))
1211 close_acl_tables(thd);
1219 sql_print_error(
"Cannot open mysql.user");
1223 if (tables.table->s->fields < event_priv_column_position ||
1224 strncmp(tables.table->field[event_priv_column_position]->field_name,
1225 STRING_WITH_LEN(
"Event_priv")))
1227 sql_print_error(
"mysql.user has no `Event_priv` column at position %d",
1228 event_priv_column_position);
1231 close_acl_tables(thd);
1239 sql_print_error(
"Cannot open mysql.event");
1243 if (table_intact.
check(tables.table, &event_table_def))
1248 DBUG_RETURN(
test(ret));