summaryrefslogtreecommitdiff
path: root/sql/sql_db.cc
diff options
context:
space:
mode:
authorunknown <guilhem@mysql.com>2004-06-09 16:07:01 +0200
committerunknown <guilhem@mysql.com>2004-06-09 16:07:01 +0200
commit43489240ad0293721c58a2b872f745b62027ca07 (patch)
tree1003fd9ceb90dc1ddeb6db7ff4e98d8da2cc51c4 /sql/sql_db.cc
parentee401045be84b32ef930092ede1974117cde4b85 (diff)
downloadmariadb-git-43489240ad0293721c58a2b872f745b62027ca07.tar.gz
Making DROP TABLE IF EXISTS, DROP DATABASE IF EXISTS, DELETE FROM, UPDATE be logged to
binlog even if they changed nothing, and a test for this. This is useful when users use these commands to clean up their master and slave by issuing one command on master (assume master and slave have slightly different data for some reason and you want to clean up both). Note that I have not changed multi-table DELETE and multi-table UPDATE because their error-reporting mechanism is more complicated. mysql-test/r/mysqlbinlog.result: result update mysql-test/r/rpl_charset.result: result update mysql-test/r/rpl_flush_log_loop.result: result update mysql-test/r/rpl_replicate_do.result: result update mysql-test/r/rpl_temporary.result: result update mysql-test/t/mysqlbinlog.test: moving SET TIMESTAMP up as DROP shows up in binlog sql/sql_db.cc: DROP DATABASE IF EXISTS is now always logged to binlog, even if db did not exist sql/sql_delete.cc: DELETE FROM t is now always logged to binlog even if no rows deleted (but in this case, only if really no error). sql/sql_table.cc: DROP TABLE IF EXISTS is now always logged to binlog even if table did not exist sql/sql_update.cc: UPDATE is now always logged to binlog even if no rows updated (but in this case, only if really no error).
Diffstat (limited to 'sql/sql_db.cc')
-rw-r--r--sql/sql_db.cc72
1 files changed, 35 insertions, 37 deletions
diff --git a/sql/sql_db.cc b/sql/sql_db.cc
index 48c355b6cd9..9db2198268a 100644
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@ -358,15 +358,25 @@ int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
{
error= -1;
my_error(ER_DB_DROP_EXISTS,MYF(0),db);
+ goto exit;
}
else
- {
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_DB_DROP_EXISTS, ER(ER_DB_DROP_EXISTS), db);
- if (!silent)
- send_ok(thd,0);
+ }
+ else
+ {
+ pthread_mutex_lock(&LOCK_open);
+ remove_db_from_cache(db);
+ pthread_mutex_unlock(&LOCK_open);
+
+ error= -1;
+ if ((deleted= mysql_rm_known_files(thd, dirp, db, path, 0)) >= 0)
+ {
+ ha_drop_database(path);
+ query_cache_invalidate1(db);
+ error = 0;
}
- goto exit;
}
if (lower_case_table_names)
{
@@ -375,42 +385,30 @@ int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
my_casedn_str(files_charset_info, tmp_db);
db= tmp_db;
}
-
- pthread_mutex_lock(&LOCK_open);
- remove_db_from_cache(db);
- pthread_mutex_unlock(&LOCK_open);
-
- error = -1;
- if ((deleted=mysql_rm_known_files(thd, dirp, db, path,0)) >= 0 && thd)
+ if (!silent && deleted>=0 && thd)
{
- ha_drop_database(path);
- query_cache_invalidate1(db);
- if (!silent)
+ const char *query;
+ ulong query_length;
+ if (!thd->query)
{
- const char *query;
- ulong query_length;
- if (!thd->query)
- {
- /* The client used the old obsolete mysql_drop_db() call */
- query= path;
- query_length = (uint) (strxmov(path,"drop database `", db, "`",
- NullS)- path);
- }
- else
- {
- query=thd->query;
- query_length=thd->query_length;
- }
- mysql_update_log.write(thd, query, query_length);
- if (mysql_bin_log.is_open())
- {
- Query_log_event qinfo(thd, query, query_length, 0);
- thd->clear_error();
- mysql_bin_log.write(&qinfo);
- }
- send_ok(thd,(ulong) deleted);
+ /* The client used the old obsolete mysql_drop_db() call */
+ query= path;
+ query_length= (uint) (strxmov(path, "drop database `", db, "`",
+ NullS) - path);
+ }
+ else
+ {
+ query =thd->query;
+ query_length= thd->query_length;
+ }
+ mysql_update_log.write(thd, query, query_length);
+ if (mysql_bin_log.is_open())
+ {
+ Query_log_event qinfo(thd, query, query_length, 0);
+ thd->clear_error();
+ mysql_bin_log.write(&qinfo);
}
- error = 0;
+ send_ok(thd, (ulong) deleted);
}
exit: