summaryrefslogtreecommitdiff
path: root/sql/log.cc
diff options
context:
space:
mode:
authorheikki@hundin.mysql.fi <>2003-05-25 23:37:32 +0300
committerheikki@hundin.mysql.fi <>2003-05-25 23:37:32 +0300
commit11ae9595c74f05265ed98ea8d4346869dd65ce92 (patch)
tree113fb41a577fba8fc061c54f33034e80ad7a7124 /sql/log.cc
parent6bbeecc64219ee6c99c2a407667ce0c6c88bce72 (diff)
downloadmariadb-git-11ae9595c74f05265ed98ea8d4346869dd65ce92.tar.gz
log.cc:
If FOREIGN_KEY_CHECKS=0, wrap in binlog SQL statements inside SET FOREIGN_...=0; ... ; SET FOREIGN_...=1
Diffstat (limited to 'sql/log.cc')
-rw-r--r--sql/log.cc47
1 files changed, 46 insertions, 1 deletions
diff --git a/sql/log.cc b/sql/log.cc
index 79ee59eedf8..8bf51100147 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -1071,6 +1071,12 @@ bool MYSQL_LOG::write(Log_event* event_info)
No check for auto events flag here - this write method should
never be called if auto-events are enabled
*/
+
+ /*
+ 1. Write first log events which describe the 'run environment'
+ of the SQL command
+ */
+
if (thd)
{
if (thd->last_insert_id_used)
@@ -1109,11 +1115,50 @@ bool MYSQL_LOG::write(Log_event* event_info)
if (e.write(file))
goto err;
}
+
+ /* If the user has set FOREIGN_KEY_CHECKS=0 we wrap every SQL
+ command in the binlog inside:
+ SET FOREIGN_KEY_CHECKS=0;
+ <command>;
+ SET FOREIGN_KEY_CHECKS=1; */
+
+ if (thd->options & OPTION_NO_FOREIGN_KEY_CHECKS)
+ {
+ char buf[256], *p;
+ p= strmov(buf, "SET FOREIGN_KEY_CHECKS=0");
+ Query_log_event e(thd, buf, (ulong) (p - buf), 0);
+ e.set_log_pos(this);
+ if (e.write(file))
+ goto err;
+ }
}
+
+ /*
+ 2. Write the SQL command
+ */
+
event_info->set_log_pos(this);
if (event_info->write(file) ||
- file == &log_file && flush_io_cache(file))
+ file == &log_file && flush_io_cache(file))
goto err;
+
+ /*
+ 3. Write log events to reset the 'run environment' of the SQL command
+ */
+
+ if (thd && thd->options & OPTION_NO_FOREIGN_KEY_CHECKS)
+ {
+ char buf[256], *p;
+
+ p= strmov(buf, "SET FOREIGN_KEY_CHECKS=1");
+ Query_log_event e(thd, buf, (ulong) (p - buf), 0);
+ e.set_log_pos(this);
+
+ if (e.write(file) ||
+ file == &log_file && flush_io_cache(file))
+ goto err;
+ }
+
error=0;
/*