summaryrefslogtreecommitdiff
path: root/sql/events.cc
diff options
context:
space:
mode:
authorAlexander Nozdrin <alik@sun.com>2010-01-31 01:06:50 +0300
committerAlexander Nozdrin <alik@sun.com>2010-01-31 01:06:50 +0300
commitddc8765a9e35a020446fc28712751fe62200ea11 (patch)
tree64c1a58bb6f6f5516fbf930759b54e0081b98b90 /sql/events.cc
parent744d6cf57cfb9803a899a2d54e7407a27db96a27 (diff)
parent788c28aceb023702282bfbf372016da79f9ab49f (diff)
downloadmariadb-git-ddc8765a9e35a020446fc28712751fe62200ea11.tar.gz
Manual merge from mysql-trunk-merge.
Conflicts: - mysql-test/suite/rpl/r/rpl_binlog_grant.result - mysql-test/suite/rpl/r/rpl_sp.result - mysql-test/suite/rpl/t/rpl_binlog_grant.test - sql/sql_parse.cc - sql/sql_table.cc - sql/sql_test.cc
Diffstat (limited to 'sql/events.cc')
-rw-r--r--sql/events.cc79
1 files changed, 39 insertions, 40 deletions
diff --git a/sql/events.cc b/sql/events.cc
index 73f3427607d..35fbca871bb 100644
--- a/sql/events.cc
+++ b/sql/events.cc
@@ -246,31 +246,48 @@ common_1_lev_code:
}
-/**
- Create a new query string for removing executable comments
- for avoiding leak and keeping consistency of the execution
- on master and slave.
-
+/*
+ Binlog '{CREATE|ALTER} EVENT' statements.
+ Definer part is always rewritten, for definer can be CURRENT_USER() function.
+
@param[in] thd Thread handler
- @param[in] buf Query string
+ @param[in] create CREATE or ALTER statement
@return
- 0 ok
- 1 error
+ FASE ok
+ TRUE error
*/
-static int
-create_query_string(THD *thd, String *buf)
+static bool event_write_bin_log(THD *thd, bool create)
{
- /* Append the "CREATE" part of the query */
- if (buf->append(STRING_WITH_LEN("CREATE ")))
- return 1;
- /* Append definer */
- append_definer(thd, buf, &(thd->lex->definer->user), &(thd->lex->definer->host));
+ String log_query;
+ if (create)
+ {
+ /* Append the "CREATE" part of the query */
+ if (log_query.append(STRING_WITH_LEN("CREATE ")))
+ return TRUE;
+ }
+ else
+ {
+ /* Append the "ALETR " part of the query */
+ if (log_query.append(STRING_WITH_LEN("ALTER ")))
+ return TRUE;
+ }
+
+ /* Append definer
+ If the definer is not set or set to CURRENT_USER, the value of CURRENT_USER
+ will be written into the binary log as the definer for the SQL thread.
+ */
+ append_definer(thd, &log_query, &(thd->lex->definer->user),
+ &(thd->lex->definer->host));
+
/* Append the left part of thd->query after "DEFINER" part */
- if (buf->append(thd->lex->stmt_definition_begin))
- return 1;
-
- return 0;
+ if (log_query.append(thd->lex->stmt_definition_begin,
+ thd->lex->stmt_definition_end -
+ thd->lex->stmt_definition_begin))
+ return TRUE;
+
+ return write_bin_log(thd, TRUE, log_query.c_ptr_safe(), log_query.length())
+ != 0;
}
/**
@@ -285,8 +302,7 @@ create_query_string(THD *thd, String *buf)
@sa Events::drop_event for the notes about locking, pre-locking
and Events DDL.
- @retval FALSE OK
- @retval TRUE Error (reported)
+ @retval FALSE OK @retval TRUE Error (reported)
*/
bool
@@ -368,22 +384,7 @@ Events::create_event(THD *thd, Event_parse_data *parse_data,
binlog the create event unless it's been successfully dropped
*/
if (!dropped)
- {
- /* Binlog the create event. */
- DBUG_ASSERT(thd->query() && thd->query_length());
- String log_query;
- if (create_query_string(thd, &log_query))
- {
- sql_print_error("Event Error: An error occurred while creating query string, "
- "before writing it into binary log.");
- /* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
- DBUG_RETURN(TRUE);
- }
- /* If the definer is not set or set to CURRENT_USER, the value of CURRENT_USER
- will be written into the binary log as the definer for the SQL thread. */
- ret= write_bin_log(thd, TRUE, log_query.c_ptr(), log_query.length());
- }
+ ret= event_write_bin_log(thd, TRUE);
}
mysql_mutex_unlock(&LOCK_event_metadata);
/* Restore the state of binlog format */
@@ -502,9 +503,7 @@ Events::update_event(THD *thd, Event_parse_data *parse_data,
if (event_queue)
event_queue->update_event(thd, parse_data->dbname, parse_data->name,
new_element);
- /* Binlog the alter event. */
- DBUG_ASSERT(thd->query() && thd->query_length());
- ret= write_bin_log(thd, TRUE, thd->query(), thd->query_length());
+ ret= event_write_bin_log(thd, FALSE);
}
}
mysql_mutex_unlock(&LOCK_event_metadata);