List:Commits« Previous MessageNext Message »
From:Alfranio Correia Date:January 19 2011 3:48pm
Subject:bzr commit into mysql-trunk branch (alfranio.correia:3527) Bug#57873
View as plain text  
#At file:///home/acorreia/workspace.oracle/repository.mysql/bzrwork/bug-57873/mysql-trunk/ based on revid:alexander.barkov@stripped

 3527 Alfranio Correia	2011-01-19
      BUG#57873 Backtick in savepoint name causes replication failure
      
      Backticks can be used as part of a name which may be wrongly interpreted if
      appropriated quotes are not used. This patch thus quotes names that are
      written to the binary log in the following cases:
      
        . User variable events;
        . Create database;
        . Create table;
        . Savepoint/Rollback;
        . Load data;
        . Drop table;
        . Drop database;
        . Other cases, where statements are constructed 
          and injected in the binary log.
      
      When an event is read from the binary log and used in the mysqlbinlog, the
      current database must have its name quoted before being processed. Such data
      is not quoted before being written to binary log in order to avoid problems
      with filters as they are not expecting quoted names.
     @ client/mysqldump.c
        Refactored this routine in order to avoid duplicated code.
        The code removed from here is used in the quote_str() in
        strings/strfill.c
     @ include/m_string.h
        Created quote_str() to quote strings.
     @ mysql-test/r/mysqlbinlog.result
        Updated result file.
     @ mysql-test/r/mysqlbinlog2.result
        Updated result file.
     @ mysql-test/r/user_var-binlog.result
        Updated result file.
     @ mysql-test/suite/binlog/r/binlog_base64_flag.result
        Updated result file.
     @ mysql-test/suite/binlog/r/binlog_row_mysqlbinlog_verbose.result
        Updated result file.
     @ mysql-test/suite/binlog/r/binlog_stm_ctype_ucs.result
        Updated result file.
     @ mysql-test/suite/rpl/r/rpl_backtick.result
        Added result file.
     @ mysql-test/suite/rpl/r/rpl_row_ignorable_event.result
        Updated result file.
     @ mysql-test/suite/rpl/r/rpl_row_mysqlbinlog.result
        Updated result file.
     @ mysql-test/suite/rpl/r/rpl_sp.result
        Updated result file.
     @ mysql-test/suite/rpl/t/rpl_backtick-master.opt
        Added test case.
     @ mysql-test/suite/rpl/t/rpl_backtick-slave.opt
        Added test case.
     @ mysql-test/suite/rpl/t/rpl_backtick.test
        Added test case.
     @ sql/binlog.cc
        Quoted "Savepoint" and "Rollback".
     @ sql/ha_ndbcluster_binlog.cc
        The name of the table is quoted before being written to the
        binary log.
     @ sql/log_event.cc
        Quoted the current database and information related to Load_log_event.
     @ sql/log_event.h
        Created a wrapper to quote_str in strings/strfill.c.
     @ sql/sql_base.cc
        The name of the table is quoted before being written to the
        binary log.
     @ sql/sql_db.cc
        The name of the table is quoted before being written to the
        binary log.
     @ sql/sql_load.cc
        The name of the table is quoted before being written to the
        binary log.
     @ sql/sql_show.cc
        Added a return to append_identifier as in the future you should check
        if operations do not go wrong.
     @ sql/sql_show.h
        Added a return to append_identifier as in the future you should check
        if operations do not go wrong.
     @ sql/sql_table.cc
        Quoted "Drop table".
     @ strings/strfill.c
        Created function to quote names.

    added:
      mysql-test/suite/rpl/r/rpl_backtick.result
      mysql-test/suite/rpl/t/rpl_backtick-master.opt
      mysql-test/suite/rpl/t/rpl_backtick-slave.opt
      mysql-test/suite/rpl/t/rpl_backtick.test
    modified:
      client/mysqldump.c
      include/m_string.h
      mysql-test/r/mysqlbinlog.result
      mysql-test/r/mysqlbinlog2.result
      mysql-test/r/user_var-binlog.result
      mysql-test/suite/binlog/r/binlog_base64_flag.result
      mysql-test/suite/binlog/r/binlog_row_mysqlbinlog_verbose.result
      mysql-test/suite/binlog/r/binlog_stm_ctype_ucs.result
      mysql-test/suite/rpl/r/rpl_row_ignorable_event.result
      mysql-test/suite/rpl/r/rpl_row_mysqlbinlog.result
      mysql-test/suite/rpl/r/rpl_sp.result
      sql/binlog.cc
      sql/ha_ndbcluster_binlog.cc
      sql/log_event.cc
      sql/log_event.h
      sql/sql_base.cc
      sql/sql_db.cc
      sql/sql_load.cc
      sql/sql_show.cc
      sql/sql_show.h
      sql/sql_table.cc
      strings/strfill.c
=== modified file 'client/mysqldump.c'
--- a/client/mysqldump.c	2011-01-16 04:02:29 +0000
+++ b/client/mysqldump.c	2011-01-19 15:48:29 +0000
@@ -533,7 +533,7 @@ static int init_dumping_tables(char *);
 static int init_dumping(char *, int init_func(char*));
 static int dump_databases(char **);
 static int dump_all_databases();
-static char *quote_name(const char *name, char *buff, my_bool force);
+static char *quote_name(const char *name, char *buffer, my_bool force);
 char check_if_ignore_table(const char *table_name, char *table_type);
 static char *primary_key_fields(const char *table_name);
 static my_bool get_view_structure(char *table, char* db);
@@ -1574,23 +1574,14 @@ static my_bool test_if_special_chars(con
   buff                 quoted string
 
 */
-static char *quote_name(const char *name, char *buff, my_bool force)
+static char *quote_name(const char *name, char *buffer, my_bool force)
 {
-  char *to= buff;
   char qtype= (opt_compatible_mode & MASK_ANSI_QUOTES) ? '\"' : '`';
 
   if (!force && !opt_quoted && !test_if_special_chars(name))
     return (char*) name;
-  *to++= qtype;
-  while (*name)
-  {
-    if (*name == qtype)
-      *to++= qtype;
-    *to++= *name++;
-  }
-  to[0]= qtype;
-  to[1]= 0;
-  return buff;
+
+  return (quote_str(buffer, name, qtype));
 } /* quote_name */
 
 

=== modified file 'include/m_string.h'
--- a/include/m_string.h	2010-11-22 10:02:01 +0000
+++ b/include/m_string.h	2011-01-19 15:48:29 +0000
@@ -101,6 +101,7 @@ extern	void strappend(char *s,size_t len
 extern	char *strend(const char *s);
 extern  char *strcend(const char *, pchar);
 extern	char *strfill(char * s,size_t len,pchar fill);
+extern  char *quote_str(char *buffer, const char *name, char qtype);
 extern	char *strmake(char *dst,const char *src,size_t length);
 
 #ifndef strmov
@@ -291,5 +292,4 @@ static inline void lex_string_set(LEX_ST
   lex_str->str= (char *) c_str;
   lex_str->length= strlen(c_str);
 }
-
 #endif

=== modified file 'mysql-test/r/mysqlbinlog.result'
--- a/mysql-test/r/mysqlbinlog.result	2010-12-29 05:35:31 +0000
+++ b/mysql-test/r/mysqlbinlog.result	2011-01-19 15:48:29 +0000
@@ -18,7 +18,7 @@ flush logs;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1000000000/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
@@ -111,7 +111,7 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1000000000/*!*/;
 LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-#-#' INTO TABLE `t1` FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' (`word`)
 /*!*/;
@@ -202,7 +202,7 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1000000000/*!*/;
 insert into t1 values ("Alas")
 /*!*/;
@@ -219,7 +219,7 @@ ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1000000000/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
@@ -312,7 +312,7 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1000000000/*!*/;
 LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-#-#' INTO TABLE `t1` FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' (`word`)
 /*!*/;
@@ -403,7 +403,7 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1000000000/*!*/;
 insert into t1 values ("Alas")
 /*!*/;
@@ -420,7 +420,7 @@ ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1108844556/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
@@ -438,7 +438,7 @@ ROLLBACK /* added by mysqlbinlog */;
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1108844556/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
@@ -498,7 +498,7 @@ ERROR 42000: PROCEDURE test.p1 does not
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1000000000/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
@@ -548,7 +548,7 @@ flush logs;
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1000000000/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
@@ -725,7 +725,7 @@ FLUSH LOGS;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1253783037/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
@@ -822,22 +822,22 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1266652094/*!*/;
 SavePoint mixed_cases
 /*!*/;
-use db1/*!*/;
+use `db1`/*!*/;
 SET TIMESTAMP=1266652094/*!*/;
 INSERT INTO db1.t2 VALUES("in savepoint mixed_cases")
 /*!*/;
 SET TIMESTAMP=1266652094/*!*/;
 INSERT INTO db1.t1 VALUES(40)
 /*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1266652094/*!*/;
 ROLLBACK TO mixed_cases
 /*!*/;
-use db1/*!*/;
+use `db1`/*!*/;
 SET TIMESTAMP=1266652094/*!*/;
 INSERT INTO db1.t2 VALUES("after rollback to")
 /*!*/;
@@ -865,7 +865,7 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1266652094/*!*/;
 SavePoint mixed_cases
 /*!*/;

=== modified file 'mysql-test/r/mysqlbinlog2.result'
--- a/mysql-test/r/mysqlbinlog2.result	2010-01-07 15:39:11 +0000
+++ b/mysql-test/r/mysqlbinlog2.result	2011-01-19 15:48:29 +0000
@@ -19,7 +19,7 @@ insert into t1 values(null, "f");
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609942/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
@@ -103,7 +103,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET INSERT_ID=1/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609942/*!*/;
 insert into t1 values(null, "a")
 /*!*/;
@@ -172,7 +172,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET INSERT_ID=3/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609944/*!*/;
 insert into t1 values(null, "c")
 /*!*/;
@@ -209,7 +209,7 @@ ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609942/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
@@ -263,7 +263,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET INSERT_ID=3/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609944/*!*/;
 insert into t1 values(null, "c")
 /*!*/;
@@ -289,7 +289,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET INSERT_ID=3/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609944/*!*/;
 insert into t1 values(null, "c")
 /*!*/;
@@ -326,7 +326,7 @@ ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609942/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
@@ -369,7 +369,7 @@ flush logs;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609942/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
@@ -445,7 +445,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET INSERT_ID=6/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609943/*!*/;
 insert into t1 values(null, "f")
 /*!*/;
@@ -474,7 +474,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET INSERT_ID=1/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609942/*!*/;
 insert into t1 values(null, "a")
 /*!*/;
@@ -535,7 +535,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET INSERT_ID=6/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609943/*!*/;
 insert into t1 values(null, "f")
 /*!*/;
@@ -564,7 +564,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET INSERT_ID=3/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609944/*!*/;
 insert into t1 values(null, "c")
 /*!*/;
@@ -605,7 +605,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET INSERT_ID=6/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609943/*!*/;
 insert into t1 values(null, "f")
 /*!*/;
@@ -622,7 +622,7 @@ ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609942/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
@@ -720,7 +720,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET INSERT_ID=3/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609944/*!*/;
 insert into t1 values(null, "c")
 /*!*/;
@@ -761,7 +761,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET INSERT_ID=6/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609943/*!*/;
 insert into t1 values(null, "f")
 /*!*/;
@@ -778,7 +778,7 @@ ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609942/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
@@ -820,7 +820,7 @@ ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609942/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
@@ -904,7 +904,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET INSERT_ID=1/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609942/*!*/;
 insert into t1 values(null, "a")
 /*!*/;
@@ -972,7 +972,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET INSERT_ID=3/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609944/*!*/;
 insert into t1 values(null, "c")
 /*!*/;
@@ -1009,7 +1009,7 @@ ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609942/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
@@ -1062,7 +1062,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET INSERT_ID=3/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609944/*!*/;
 insert into t1 values(null, "c")
 /*!*/;
@@ -1088,7 +1088,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET INSERT_ID=3/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609944/*!*/;
 insert into t1 values(null, "c")
 /*!*/;
@@ -1125,7 +1125,7 @@ ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609942/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
@@ -1167,7 +1167,7 @@ ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609942/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
@@ -1243,7 +1243,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET INSERT_ID=6/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609943/*!*/;
 insert into t1 values(null, "f")
 /*!*/;
@@ -1272,7 +1272,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET INSERT_ID=1/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609942/*!*/;
 insert into t1 values(null, "a")
 /*!*/;
@@ -1333,7 +1333,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET INSERT_ID=6/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609943/*!*/;
 insert into t1 values(null, "f")
 /*!*/;
@@ -1361,7 +1361,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET INSERT_ID=3/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609944/*!*/;
 insert into t1 values(null, "c")
 /*!*/;
@@ -1402,7 +1402,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET INSERT_ID=6/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609943/*!*/;
 insert into t1 values(null, "f")
 /*!*/;
@@ -1419,7 +1419,7 @@ ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609942/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
@@ -1516,7 +1516,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET INSERT_ID=3/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609944/*!*/;
 insert into t1 values(null, "c")
 /*!*/;
@@ -1557,7 +1557,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET INSERT_ID=6/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609943/*!*/;
 insert into t1 values(null, "f")
 /*!*/;
@@ -1574,7 +1574,7 @@ ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609942/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
@@ -1616,7 +1616,7 @@ ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1579609942/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;

=== modified file 'mysql-test/r/user_var-binlog.result'
--- a/mysql-test/r/user_var-binlog.result	2010-01-07 15:39:11 +0000
+++ b/mysql-test/r/user_var-binlog.result	2011-01-19 15:48:29 +0000
@@ -34,7 +34,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET @`a b`:=_latin1 0x68656C6C6F COLLATE `latin1_swedish_ci`/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=10000/*!*/;
 INSERT INTO t1 VALUES(@`a b`)
 /*!*/;

=== modified file 'mysql-test/suite/binlog/r/binlog_base64_flag.result'
--- a/mysql-test/suite/binlog/r/binlog_base64_flag.result	2010-12-02 13:44:21 +0000
+++ b/mysql-test/suite/binlog/r/binlog_base64_flag.result	2011-01-19 15:48:29 +0000
@@ -35,7 +35,7 @@ DELIMITER /*!*/;
 # at 4
 <#>ROLLBACK/*!*/;
 # at 102
-<#>use test/*!*/;
+<#>use `test`/*!*/;
 SET TIMESTAMP=1196959712/*!*/;
 <#>SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;

=== modified file 'mysql-test/suite/binlog/r/binlog_row_mysqlbinlog_verbose.result'
--- a/mysql-test/suite/binlog/r/binlog_row_mysqlbinlog_verbose.result	2009-10-14 13:25:11 +0000
+++ b/mysql-test/suite/binlog/r/binlog_row_mysqlbinlog_verbose.result	2011-01-19 15:48:29 +0000
@@ -1,152 +1,152 @@
 Verbose statements from : write-partial-row.binlog
 select replace(txt,'\r', '') as stmt from raw_binlog_rows where txt like '###%';
 stmt
-### INSERT INTO mysql.ndb_apply_status
+### INSERT INTO `mysql`.`ndb_apply_status`
 ### SET
 ###   @1=1
 ###   @2=25769803786
 ###   @3=''
 ###   @4=0
 ###   @5=0
-### INSERT INTO test.ba
+### INSERT INTO `test`.`ba`
 ### SET
 ###   @1=3
 ###   @2=3
 ###   @3=3
-### INSERT INTO test.ba
+### INSERT INTO `test`.`ba`
 ### SET
 ###   @1=1
 ###   @2=1
 ###   @3=1
-### INSERT INTO test.ba
+### INSERT INTO `test`.`ba`
 ### SET
 ###   @1=2
 ###   @2=2
 ###   @3=2
-### INSERT INTO test.ba
+### INSERT INTO `test`.`ba`
 ### SET
 ###   @1=4
 ###   @2=4
 ###   @3=4
-### INSERT INTO test.ba
+### INSERT INTO `test`.`ba`
 ### SET
 ###   @1=4
 ###   @3=40
-### DELETE FROM test.ba
+### DELETE FROM `test`.`ba`
 ### WHERE
 ###   @1=2
 drop table raw_binlog_rows;
 Verbose statements from : write-full-row.binlog
 select replace(txt,'\r', '') as stmt from raw_binlog_rows where txt like '###%';
 stmt
-### INSERT INTO mysql.ndb_apply_status
+### INSERT INTO `mysql`.`ndb_apply_status`
 ### SET
 ###   @1=2
 ###   @2=25769803786
 ###   @3=''
 ###   @4=0
 ###   @5=0
-### INSERT INTO test.ba
+### INSERT INTO `test`.`ba`
 ### SET
 ###   @1=3
 ###   @2=3
 ###   @3=3
-### INSERT INTO test.ba
+### INSERT INTO `test`.`ba`
 ### SET
 ###   @1=1
 ###   @2=1
 ###   @3=1
-### INSERT INTO test.ba
+### INSERT INTO `test`.`ba`
 ### SET
 ###   @1=2
 ###   @2=2
 ###   @3=2
-### INSERT INTO test.ba
+### INSERT INTO `test`.`ba`
 ### SET
 ###   @1=4
 ###   @2=4
 ###   @3=4
-### INSERT INTO test.ba
+### INSERT INTO `test`.`ba`
 ### SET
 ###   @1=4
 ###   @2=4
 ###   @3=40
-### DELETE FROM test.ba
+### DELETE FROM `test`.`ba`
 ### WHERE
 ###   @1=2
 drop table raw_binlog_rows;
 Verbose statements from : update-partial-row.binlog
 select replace(txt,'\r', '') as stmt from raw_binlog_rows where txt like '###%';
 stmt
-### INSERT INTO mysql.ndb_apply_status
+### INSERT INTO `mysql`.`ndb_apply_status`
 ### SET
 ###   @1=3
 ###   @2=25769803786
 ###   @3=''
 ###   @4=0
 ###   @5=0
-### INSERT INTO test.ba
+### INSERT INTO `test`.`ba`
 ### SET
 ###   @1=3
 ###   @2=3
 ###   @3=3
-### INSERT INTO test.ba
+### INSERT INTO `test`.`ba`
 ### SET
 ###   @1=1
 ###   @2=1
 ###   @3=1
-### INSERT INTO test.ba
+### INSERT INTO `test`.`ba`
 ### SET
 ###   @1=2
 ###   @2=2
 ###   @3=2
-### INSERT INTO test.ba
+### INSERT INTO `test`.`ba`
 ### SET
 ###   @1=4
 ###   @2=4
 ###   @3=4
-### UPDATE test.ba
+### UPDATE `test`.`ba`
 ### WHERE
 ###   @1=4
 ###   @3=4
 ### SET
 ###   @1=4
 ###   @3=40
-### DELETE FROM test.ba
+### DELETE FROM `test`.`ba`
 ### WHERE
 ###   @1=2
 drop table raw_binlog_rows;
 Verbose statements from : update-full-row.binlog
 select replace(txt,'\r', '') as stmt from raw_binlog_rows where txt like '###%';
 stmt
-### INSERT INTO mysql.ndb_apply_status
+### INSERT INTO `mysql`.`ndb_apply_status`
 ### SET
 ###   @1=4
 ###   @2=25769803786
 ###   @3=''
 ###   @4=0
 ###   @5=0
-### INSERT INTO test.ba
+### INSERT INTO `test`.`ba`
 ### SET
 ###   @1=3
 ###   @2=3
 ###   @3=3
-### INSERT INTO test.ba
+### INSERT INTO `test`.`ba`
 ### SET
 ###   @1=1
 ###   @2=1
 ###   @3=1
-### INSERT INTO test.ba
+### INSERT INTO `test`.`ba`
 ### SET
 ###   @1=2
 ###   @2=2
 ###   @3=2
-### INSERT INTO test.ba
+### INSERT INTO `test`.`ba`
 ### SET
 ###   @1=4
 ###   @2=4
 ###   @3=4
-### UPDATE test.ba
+### UPDATE `test`.`ba`
 ### WHERE
 ###   @1=4
 ###   @2=4
@@ -155,7 +155,7 @@ stmt
 ###   @1=4
 ###   @2=4
 ###   @3=40
-### DELETE FROM test.ba
+### DELETE FROM `test`.`ba`
 ### WHERE
 ###   @1=2
 drop table raw_binlog_rows;

=== modified file 'mysql-test/suite/binlog/r/binlog_stm_ctype_ucs.result'
--- a/mysql-test/suite/binlog/r/binlog_stm_ctype_ucs.result	2010-01-07 15:39:11 +0000
+++ b/mysql-test/suite/binlog/r/binlog_stm_ctype_ucs.result	2011-01-19 15:48:29 +0000
@@ -26,7 +26,7 @@ SET @@session.collation_database=DEFAULT
 BEGIN
 /*!*/;
 SET @`v`:=_ucs2 0x006100620063 COLLATE `ucs2_general_ci`/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=10000/*!*/;
 insert into t2 values (@v)
 /*!*/;

=== added file 'mysql-test/suite/rpl/r/rpl_backtick.result'
--- a/mysql-test/suite/rpl/r/rpl_backtick.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/r/rpl_backtick.result	2011-01-19 15:48:29 +0000
@@ -0,0 +1,217 @@
+include/master-slave.inc
+[connection master]
+set timestamp=1000000000;
+select @@session.read_buffer_size - @@session.max_allowed_packet > 0;
+@@session.read_buffer_size - @@session.max_allowed_packet > 0
+1
+============== 1. USER VARIABLE ==============
+SET @`var``var` = '```';
+SELECT @`var``var`;
+@`var``var`
+```
+============== 2. CREATE DATABASE ==============
+CREATE DATABASE `db``db`;
+USE `db``db`;
+============== 3. CREATE TABLE ==============
+USE test;
+CREATE TABLE `db``db`.```t``import_1` (`id``` int not null primary key auto_increment, other TEXT);
+CREATE TABLE `db``db`.```t``import_2` (`id``` int not null primary key auto_increment, other TEXT);
+CREATE TABLE `db``db`.```t``.``import_3` (`id``` int not null primary key auto_increment, other TEXT);
+CREATE TABLE `db``db`.```t``import_4` (`id``` int not null primary key auto_increment, other TEXT);
+CREATE TABLE `db``db`.```t``import_5` (`id``` int not null primary key auto_increment, other TEXT);
+CREATE TABLE `db``db`.```t``.``import_6` (`id``` int not null primary key auto_increment, other TEXT);
+============== 4. SAVEPOINT/ROLLBACK  ==============
+USE test;
+BEGIN;
+INSERT INTO `db``db`.```t``import_1` VALUES (1, @`var``var`);
+SAVEPOINT `s``p`;
+ROLLBACK TO `s``p`;
+Warnings:
+Warning	1196	Some non-transactional changed tables couldn't be rolled back
+DELETE FROM `db``db`.```t``import_1`;
+COMMIT;
+============== 5. LOAD DATA ==============
+USE `db``db`;
+USE test;
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug-57873.txt' into table `db``db`.```t``import_1` (`id```, other);
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug-57873.txt' into table `db``db`.```t``import_2` (`id```, other);
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug-57873.txt' into table `db``db`.```t``.``import_3` (`id```, other);
+USE `db``db`;
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug-57873.txt' into table `db``db`.```t``import_4` (`id```, other);
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug-57873.txt' into table `db``db`.```t``import_5` (`id```, other);
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug-57873.txt' into table `db``db`.```t``.``import_6` (`id```, other);
+USE `db``db`;
+SELECT count(*) FROM ```t``import_1` where other = '```';
+count(*)
+5000
+SELECT count(*) FROM ```t``import_2` where other = '```';
+count(*)
+5000
+SELECT count(*) FROM ```t``.``import_3` where other = '```';
+ERROR 42S02: Table 'db`db.`t`.`import_3' doesn't exist
+SELECT count(*) FROM ```t``import_4` where other = '```';
+count(*)
+5000
+SELECT count(*) FROM ```t``import_5` where other = '```';
+count(*)
+5000
+SELECT count(*) FROM ```t``.``import_6` where other = '```';
+ERROR 42S02: Table 'db`db.`t`.`import_6' doesn't exist
+============== 6. DROP TABLE ==============
+USE test;
+DROP TABLE `db``db`.```t``import_1`;
+DROP TABLE `db``db`.```t``import_2`;
+DROP TABLE `db``db`.```t``.``import_3`;
+DROP TABLE `db``db`.```t``import_4`;
+DROP TABLE `db``db`.```t``import_5`;
+DROP TABLE `db``db`.```t``.``import_6`;
+============== 7. DROP DATABASE ==============
+DROP DATABASE `db``db`;
+/*!40019 SET @@session.max_insert_delayed_threads=0*/;
+/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
+DELIMITER /*!*/;
+ROLLBACK/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+SET @@session.pseudo_thread_id=999999999/*!*/;
+SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
+SET @@session.sql_mode=0/*!*/;
+SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
+/*!\C latin1 *//*!*/;
+SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
+SET @@session.lc_time_names=0/*!*/;
+SET @@session.collation_database=DEFAULT/*!*/;
+CREATE DATABASE `db``db`
+/*!*/;
+use `test`/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+CREATE TABLE `db``db`.```t``import_1` (`id``` int not null primary key auto_increment, other TEXT)
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+CREATE TABLE `db``db`.```t``import_2` (`id``` int not null primary key auto_increment, other TEXT)
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+CREATE TABLE `db``db`.```t``.``import_3` (`id``` int not null primary key auto_increment, other TEXT)
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+CREATE TABLE `db``db`.```t``import_4` (`id``` int not null primary key auto_increment, other TEXT)
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+CREATE TABLE `db``db`.```t``import_5` (`id``` int not null primary key auto_increment, other TEXT)
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+CREATE TABLE `db``db`.```t``.``import_6` (`id``` int not null primary key auto_increment, other TEXT)
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+BEGIN
+/*!*/;
+SET @`var``var`:=_latin1 0x606060 COLLATE `latin1_swedish_ci`/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+INSERT INTO `db``db`.```t``import_1` VALUES (1, @`var``var`)
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+BEGIN
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+DELETE FROM `db``db`.```t``import_1`
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+BEGIN
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+SAVEPOINT `s``p`
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+ROLLBACK TO `s``p`
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+BEGIN
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-#-#' INTO TABLE `db``db`.```t``import_1` FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' (`id```, `other`)
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+BEGIN
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-#-#' INTO TABLE `db``db`.```t``import_2` FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' (`id```, `other`)
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+BEGIN
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-#-#' INTO TABLE `db``db`.```t``.``import_3` FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' (`id```, `other`)
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+BEGIN
+/*!*/;
+use `db``db`/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-#-#' INTO TABLE ```t``import_4` FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' (`id```, `other`)
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+BEGIN
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-#-#' INTO TABLE ```t``import_5` FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' (`id```, `other`)
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+BEGIN
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-#-#' INTO TABLE ```t``.``import_6` FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' (`id```, `other`)
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+use `test`/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+DROP TABLE `db``db`.```t``import_1` /* generated by server */
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+DROP TABLE `db``db`.```t``import_2` /* generated by server */
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+DROP TABLE `db``db`.```t``.``import_3` /* generated by server */
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+DROP TABLE `db``db`.```t``import_4` /* generated by server */
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+DROP TABLE `db``db`.```t``import_5` /* generated by server */
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+DROP TABLE `db``db`.```t``.``import_6` /* generated by server */
+/*!*/;
+SET TIMESTAMP=1000000000/*!*/;
+DROP DATABASE `db``db`
+/*!*/;
+DELIMITER ;
+# End of log file
+ROLLBACK /* added by mysqlbinlog */;
+/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
+set @@session.binlog_rows_query_log_events= 0;
+include/rpl_end.inc

=== modified file 'mysql-test/suite/rpl/r/rpl_row_ignorable_event.result'
--- a/mysql-test/suite/rpl/r/rpl_row_ignorable_event.result	2010-12-19 17:22:30 +0000
+++ b/mysql-test/suite/rpl/r/rpl_row_ignorable_event.result	2011-01-19 15:48:29 +0000
@@ -155,7 +155,7 @@ DELIMITER /*!*/;
 ROLLBACK/*!*/;
 # at #
 #server id #  end_log_pos # 	Query	thread_id=#	exec_time=#	error_code=#
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=t/*!*/;
 SET @@session.pseudo_thread_id=#/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
@@ -179,11 +179,11 @@ BEGIN
 #server id #  end_log_pos # 	Table_map: `test`.`t1` mapped to number #
 # at #
 #server id #  end_log_pos # 	Write_rows: table id # flags: STMT_END_F
-### INSERT INTO test.t1
+### INSERT INTO `test`.`t1`
 ### SET
 ###   @1=1 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=1 /* INT meta=0 nullable=1 is_null=0 */
-### INSERT INTO test.t1
+### INSERT INTO `test`.`t1`
 ### SET
 ###   @1=2 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=1 /* INT meta=0 nullable=1 is_null=0 */
@@ -204,7 +204,7 @@ BEGIN
 #server id #  end_log_pos # 	Table_map: `test`.`t1` mapped to number #
 # at #
 #server id #  end_log_pos # 	Update_rows: table id # flags: STMT_END_F
-### UPDATE test.t1
+### UPDATE `test`.`t1`
 ### WHERE
 ###   @1=1 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=1 /* INT meta=0 nullable=1 is_null=0 */
@@ -228,7 +228,7 @@ BEGIN
 #server id #  end_log_pos # 	Table_map: `test`.`t1` mapped to number #
 # at #
 #server id #  end_log_pos # 	Delete_rows: table id # flags: STMT_END_F
-### DELETE FROM test.t1
+### DELETE FROM `test`.`t1`
 ### WHERE
 ###   @1=6 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=1 /* INT meta=0 nullable=1 is_null=0 */
@@ -254,11 +254,11 @@ BEGIN
 #server id #  end_log_pos # 	Table_map: `test`.`t2` mapped to number #
 # at #
 #server id #  end_log_pos # 	Write_rows: table id # flags: STMT_END_F
-### INSERT INTO test.t2
+### INSERT INTO `test`.`t2`
 ### SET
 ###   @1=2 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=1 /* INT meta=0 nullable=1 is_null=0 */
-### INSERT INTO test.t2
+### INSERT INTO `test`.`t2`
 ### SET
 ###   @1=3 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=1 /* INT meta=0 nullable=1 is_null=0 */
@@ -269,14 +269,14 @@ BEGIN
 #server id #  end_log_pos # 	Table_map: `test`.`t2` mapped to number #
 # at #
 #server id #  end_log_pos # 	Update_rows: table id # flags: STMT_END_F
-### UPDATE test.t2
+### UPDATE `test`.`t2`
 ### WHERE
 ###   @1=2 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=1 /* INT meta=0 nullable=1 is_null=0 */
 ### SET
 ###   @1=7 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=1 /* INT meta=0 nullable=1 is_null=0 */
-### UPDATE test.t2
+### UPDATE `test`.`t2`
 ### WHERE
 ###   @1=3 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=1 /* INT meta=0 nullable=1 is_null=0 */
@@ -290,7 +290,7 @@ BEGIN
 #server id #  end_log_pos # 	Table_map: `test`.`t2` mapped to number #
 # at #
 #server id #  end_log_pos # 	Delete_rows: table id # flags: STMT_END_F
-### DELETE FROM test.t2
+### DELETE FROM `test`.`t2`
 ### WHERE
 ###   @1=7 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=1 /* INT meta=0 nullable=1 is_null=0 */
@@ -309,7 +309,7 @@ BEGIN
 #server id #  end_log_pos # 	Table_map: `test`.`t1` mapped to number #
 # at #
 #server id #  end_log_pos # 	Write_rows: table id # flags: STMT_END_F
-### INSERT INTO test.t1
+### INSERT INTO `test`.`t1`
 ### SET
 ###   @1=1 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=5 /* INT meta=0 nullable=1 is_null=0 */
@@ -330,7 +330,7 @@ BEGIN
 #server id #  end_log_pos # 	Table_map: `test`.`t1` mapped to number #
 # at #
 #server id #  end_log_pos # 	Write_rows: table id # flags: STMT_END_F
-### INSERT INTO test.t1
+### INSERT INTO `test`.`t1`
 ### SET
 ###   @1=1 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=7 /* INT meta=0 nullable=1 is_null=0 */
@@ -351,7 +351,7 @@ BEGIN
 #server id #  end_log_pos # 	Table_map: `test`.`t2` mapped to number #
 # at #
 #server id #  end_log_pos # 	Write_rows: table id # flags: STMT_END_F
-### INSERT INTO test.t2
+### INSERT INTO `test`.`t2`
 ### SET
 ###   @1=2 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=5 /* INT meta=0 nullable=1 is_null=0 */
@@ -362,7 +362,7 @@ BEGIN
 #server id #  end_log_pos # 	Table_map: `test`.`t2` mapped to number #
 # at #
 #server id #  end_log_pos # 	Write_rows: table id # flags: STMT_END_F
-### INSERT INTO test.t2
+### INSERT INTO `test`.`t2`
 ### SET
 ###   @1=2 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=6 /* INT meta=0 nullable=1 is_null=0 */
@@ -401,7 +401,7 @@ BEGIN
 #server id #  end_log_pos # 	Table_map: `test`.`t3` mapped to number #
 # at #
 #server id #  end_log_pos # 	Write_rows: table id # flags: STMT_END_F
-### INSERT INTO test.t3
+### INSERT INTO `test`.`t3`
 ### SET
 ###   @1=1 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=1 /* INT meta=0 nullable=1 is_null=0 */
@@ -422,7 +422,7 @@ BEGIN
 #server id #  end_log_pos # 	Table_map: `test`.`t4` mapped to number #
 # at #
 #server id #  end_log_pos # 	Write_rows: table id # flags: STMT_END_F
-### INSERT INTO test.t4
+### INSERT INTO `test`.`t4`
 ### SET
 ###   @1=2 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=1 /* INT meta=0 nullable=1 is_null=0 */
@@ -447,14 +447,14 @@ BEGIN
 #server id #  end_log_pos # 	Update_rows: table id #
 # at #
 #server id #  end_log_pos # 	Update_rows: table id # flags: STMT_END_F
-### UPDATE test.t3
+### UPDATE `test`.`t3`
 ### WHERE
 ###   @1=1 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=1 /* INT meta=0 nullable=1 is_null=0 */
 ### SET
 ###   @1=3 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=1 /* INT meta=0 nullable=1 is_null=0 */
-### UPDATE test.t4
+### UPDATE `test`.`t4`
 ### WHERE
 ###   @1=2 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=1 /* INT meta=0 nullable=1 is_null=0 */
@@ -478,7 +478,7 @@ BEGIN
 #server id #  end_log_pos # 	Table_map: `test`.`t5` mapped to number #
 # at #
 #server id #  end_log_pos # 	Write_rows: table id # flags: STMT_END_F
-### INSERT INTO test.t5
+### INSERT INTO `test`.`t5`
 ### SET
 ###   @1=3 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=1 /* INT meta=0 nullable=1 is_null=0 */
@@ -501,7 +501,7 @@ BEGIN
 #server id #  end_log_pos # 	Table_map: `test`.`t5` mapped to number #
 # at #
 #server id #  end_log_pos # 	Update_rows: table id # flags: STMT_END_F
-### UPDATE test.t5
+### UPDATE `test`.`t5`
 ### WHERE
 ###   @1=3 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=1 /* INT meta=0 nullable=1 is_null=0 */
@@ -525,7 +525,7 @@ BEGIN
 #server id #  end_log_pos # 	Table_map: `test`.`t3` mapped to number #
 # at #
 #server id #  end_log_pos # 	Write_rows: table id # flags: STMT_END_F
-### INSERT INTO test.t3
+### INSERT INTO `test`.`t3`
 ### SET
 ###   @1=1 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=5 /* INT meta=0 nullable=1 is_null=0 */
@@ -533,7 +533,7 @@ BEGIN
 #server id #  end_log_pos # 	Table_map: `test`.`t3` mapped to number #
 # at #
 #server id #  end_log_pos # 	Write_rows: table id # flags: STMT_END_F
-### INSERT INTO test.t3
+### INSERT INTO `test`.`t3`
 ### SET
 ###   @1=1 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=6 /* INT meta=0 nullable=1 is_null=0 */
@@ -541,7 +541,7 @@ BEGIN
 #server id #  end_log_pos # 	Table_map: `test`.`t3` mapped to number #
 # at #
 #server id #  end_log_pos # 	Write_rows: table id # flags: STMT_END_F
-### INSERT INTO test.t3
+### INSERT INTO `test`.`t3`
 ### SET
 ###   @1=1 /* INT meta=0 nullable=1 is_null=0 */
 ###   @2=7 /* INT meta=0 nullable=1 is_null=0 */
@@ -569,214 +569,214 @@ BEGIN
 #server id #  end_log_pos # 	Write_rows: table id #
 # at #
 #server id #  end_log_pos # 	Write_rows: table id # flags: STMT_END_F
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='Aarhus' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='Aaron' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='Ababa' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='aback' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abaft' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abandon' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abandoned' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abandoning' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abandonment' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abandons' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='Aarhus' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='Aaron' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='Ababa' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='aback' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abaft' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abandon' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abandoned' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abandoning' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abandonment' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abandons' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abase' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abased' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abasement' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abasements' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abases' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abash' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abashed' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abashes' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abashing' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abasing' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abate' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abated' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abatement' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abatements' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abater' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abates' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abating' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='Abba' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abbe' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abbey' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abbeys' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abbot' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abbots' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='Abbott' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abbreviate' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abbreviated' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abbreviates' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abbreviating' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abbreviation' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abbreviations' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='Abby' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abdomen' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abdomens' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abdominal' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abduct' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abducted' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abduction' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abductions' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abductor' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abductors' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abducts' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='Abe' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='abed' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='Abel' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='Abelian' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='Abelson' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='Aberdeen' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='Abernathy' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='aberrant' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
-### INSERT INTO test.t6
+### INSERT INTO `test`.`t6`
 ### SET
 ###   @1='aberration' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
 # at #

=== modified file 'mysql-test/suite/rpl/r/rpl_row_mysqlbinlog.result'
--- a/mysql-test/suite/rpl/r/rpl_row_mysqlbinlog.result	2010-12-19 17:22:30 +0000
+++ b/mysql-test/suite/rpl/r/rpl_row_mysqlbinlog.result	2011-01-19 15:48:29 +0000
@@ -154,7 +154,7 @@ c1	c3	c4	c5
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1000000000/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
@@ -176,7 +176,7 @@ ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1000000000/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
@@ -287,7 +287,7 @@ ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1000000000/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
@@ -318,7 +318,7 @@ ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=1000000000/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;

=== modified file 'mysql-test/suite/rpl/r/rpl_sp.result'
--- a/mysql-test/suite/rpl/r/rpl_sp.result	2010-12-19 17:22:30 +0000
+++ b/mysql-test/suite/rpl/r/rpl_sp.result	2011-01-19 15:48:29 +0000
@@ -670,7 +670,7 @@ drop database if exists mysqltest1
 SET TIMESTAMP=t/*!*/;
 create database mysqltest1
 /*!*/;
-use mysqltest1/*!*/;
+use `mysqltest1`/*!*/;
 SET TIMESTAMP=t/*!*/;
 create table t1 (a varchar(100))
 /*!*/;
@@ -1015,7 +1015,7 @@ drop database mysqltest1
 SET TIMESTAMP=t/*!*/;
 drop user "zedjzlcsjhd"@127.0.0.1
 /*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=t/*!*/;
 drop function if exists f1
 /*!*/;
@@ -1112,7 +1112,7 @@ create database mysqltest
 SET TIMESTAMP=t/*!*/;
 create database mysqltest2
 /*!*/;
-use mysqltest2/*!*/;
+use `mysqltest2`/*!*/;
 SET TIMESTAMP=t/*!*/;
 create table t ( t integer )
 /*!*/;
@@ -1139,7 +1139,7 @@ end
 SET TIMESTAMP=t/*!*/;
 BEGIN
 /*!*/;
-use mysqltest/*!*/;
+use `mysqltest`/*!*/;
 SET TIMESTAMP=t/*!*/;
 SELECT `mysqltest2`.`f1`()
 /*!*/;
@@ -1152,14 +1152,14 @@ drop database mysqltest
 SET TIMESTAMP=t/*!*/;
 drop database mysqltest2
 /*!*/;
-use test/*!*/;
+use `test`/*!*/;
 SET TIMESTAMP=t/*!*/;
 CREATE DEFINER=`root`@`localhost` PROCEDURE `mysqltestbug36570_p1`()
 begin
 select 1;
 end
 /*!*/;
-use mysql/*!*/;
+use `mysql`/*!*/;
 SET TIMESTAMP=t/*!*/;
 CREATE DEFINER=`root`@`localhost` PROCEDURE `test`.` mysqltestbug36570_p2`( a int )
 `label`:

=== added file 'mysql-test/suite/rpl/t/rpl_backtick-master.opt'
--- a/mysql-test/suite/rpl/t/rpl_backtick-master.opt	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_backtick-master.opt	2011-01-19 15:48:29 +0000
@@ -0,0 +1 @@
+--read_buffer_size=12K --max_allowed_packet=8K --binlog-rows-query-log-events=1

=== added file 'mysql-test/suite/rpl/t/rpl_backtick-slave.opt'
--- a/mysql-test/suite/rpl/t/rpl_backtick-slave.opt	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_backtick-slave.opt	2011-01-19 15:48:29 +0000
@@ -0,0 +1 @@
+--max_allowed_packet=8K --replicate-ignore-table=db`db.`t`.`import_3 --replicate-ignore-table=db`db.`t`.`import_6 --binlog-rows-query-log-events=1

=== added file 'mysql-test/suite/rpl/t/rpl_backtick.test'
--- a/mysql-test/suite/rpl/t/rpl_backtick.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_backtick.test	2011-01-19 15:48:29 +0000
@@ -0,0 +1,119 @@
+###############################################################################
+# This test case aims at checking if names with backticks are correctly       #
+# replicated. Specificially, we focus on seven cases:                         #
+#                                                                             #
+# 1. User variable;                                                           #
+# 2. Create database;                                                         #
+# 3. Create table;                                                            #
+# 4. Savepoint/Rollback;                                                      #
+# 5. Load data;                                                               #
+# 6. Drop table;                                                              #
+# 7. Drop database;                                                           #
+#                                                                             #
+# We ensure that names with backticks are correclty replicated by checking if #
+# slave is in sycn with master and through mysqlbinlog                        #
+###############################################################################
+--source include/master-slave.inc
+--source include/have_binlog_format_statement.inc
+set timestamp=1000000000;
+# We are going to replicate big transactions through LOAD DATA. So, we must
+# ensure that buffers are correclty configured.
+--connection slave
+select @@session.read_buffer_size - @@session.max_allowed_packet > 0;
+--connection master
+
+--echo ============== 1. USER VARIABLE ==============
+SET @`var``var` = '```';
+SELECT @`var``var`;
+
+--echo ============== 2. CREATE DATABASE ==============
+CREATE DATABASE `db``db`;
+USE `db``db`;
+
+--echo ============== 3. CREATE TABLE ==============
+USE test;
+CREATE TABLE `db``db`.```t``import_1` (`id``` int not null primary key auto_increment, other TEXT);
+CREATE TABLE `db``db`.```t``import_2` (`id``` int not null primary key auto_increment, other TEXT);
+CREATE TABLE `db``db`.```t``.``import_3` (`id``` int not null primary key auto_increment, other TEXT);
+CREATE TABLE `db``db`.```t``import_4` (`id``` int not null primary key auto_increment, other TEXT);
+CREATE TABLE `db``db`.```t``import_5` (`id``` int not null primary key auto_increment, other TEXT);
+CREATE TABLE `db``db`.```t``.``import_6` (`id``` int not null primary key auto_increment, other TEXT);
+
+--echo ============== 4. SAVEPOINT/ROLLBACK  ==============
+USE test;
+BEGIN;
+INSERT INTO `db``db`.```t``import_1` VALUES (1, @`var``var`);
+SAVEPOINT `s``p`;
+ROLLBACK TO `s``p`;
+DELETE FROM `db``db`.```t``import_1`;
+COMMIT;
+
+--echo ============== 5. LOAD DATA ==============
+#  In what follows, We are creating information to be load in tables.
+USE `db``db`;
+--disable_query_log
+SET @@sql_log_bin= 0;
+let $rows= 5000;
+CREATE TABLE ```t``export` (`id``` int not null primary key auto_increment, other TEXT);
+while($rows)
+{
+  INSERT INTO ```t``export` VALUES (null, @`var``var`);
+  dec $rows;
+}
+eval SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/bug-57873.txt' FROM ```t``export`;
+SET @@sql_log_bin= 1;
+--enable_query_log
+
+USE test;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/bug-57873.txt' into table `db``db`.```t``import_1` (`id```, other);
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/bug-57873.txt' into table `db``db`.```t``import_2` (`id```, other);
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/bug-57873.txt' into table `db``db`.```t``.``import_3` (`id```, other);
+USE `db``db`;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/bug-57873.txt' into table `db``db`.```t``import_4` (`id```, other);
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/bug-57873.txt' into table `db``db`.```t``import_5` (`id```, other);
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/bug-57873.txt' into table `db``db`.```t``.``import_6` (`id```, other);
+
+--sync_slave_with_master
+
+USE `db``db`;
+SELECT count(*) FROM ```t``import_1` where other = '```';
+SELECT count(*) FROM ```t``import_2` where other = '```';
+--error 1146
+SELECT count(*) FROM ```t``.``import_3` where other = '```';
+SELECT count(*) FROM ```t``import_4` where other = '```';
+SELECT count(*) FROM ```t``import_5` where other = '```';
+--error 1146
+SELECT count(*) FROM ```t``.``import_6` where other = '```';
+
+--connection master
+
+--echo ============== 6. DROP TABLE ==============
+USE test;
+DROP TABLE `db``db`.```t``import_1`;
+DROP TABLE `db``db`.```t``import_2`;
+DROP TABLE `db``db`.```t``.``import_3`;
+DROP TABLE `db``db`.```t``import_4`;
+DROP TABLE `db``db`.```t``import_5`;
+DROP TABLE `db``db`.```t``.``import_6`;
+
+--echo ============== 7. DROP DATABASE ==============
+DROP DATABASE `db``db`;
+
+# Clean up the test case.
+--sync_slave_with_master
+--connection master
+
+let $MYSQLD_DATADIR= `select @@datadir`;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--replace_regex /SQL_LOAD_MB-[0-9]-[0-9]/SQL_LOAD_MB-#-#/
+--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ $MYSQLD_DATADIR/master-bin.000001
+
+set @@session.binlog_rows_query_log_events= 0;
+--remove_file $MYSQLTEST_VARDIR/tmp/bug-57873.txt
+--source include/rpl_end.inc

=== modified file 'sql/binlog.cc'
--- a/sql/binlog.cc	2010-12-17 02:01:32 +0000
+++ b/sql/binlog.cc	2011-01-19 15:48:29 +0000
@@ -17,6 +17,7 @@
 #include "my_global.h"
 #include "log.h"
 #include "binlog.h"
+#include "sql_show.h"
 #include "log_event.h"
 #include "rpl_filter.h"
 #include "rpl_rli.h"
@@ -856,12 +857,20 @@ static int binlog_savepoint_set(handlert
 {
   DBUG_ENTER("binlog_savepoint_set");
   int error= 1;
+  /*
+    Statically allocates room to store savepoint, '\0' and an
+    identifier: savepoint name.
+
+    Each identifier may have NAME_LEN * 2 due to quoting and
+    there are two quoting characters that wrap them.
+  */
+  char buffer[10 + 1 + NAME_LEN * 2 + 2];
+  String log_query(buffer, sizeof(buffer), system_charset_info);
+  log_query.length(0);
 
-  String log_query;
   if (log_query.append(STRING_WITH_LEN("SAVEPOINT ")) ||
-      log_query.append("`") ||
-      log_query.append(thd->lex->ident.str, thd->lex->ident.length) ||
-      log_query.append("`"))
+      append_identifier(thd, &log_query, thd->lex->ident.str,
+                        thd->lex->ident.length))
     DBUG_RETURN(error);
 
   int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
@@ -889,7 +898,6 @@ static int binlog_savepoint_set(handlert
 static int binlog_savepoint_rollback(handlerton *hton, THD *thd, void *sv)
 {
   DBUG_ENTER("binlog_savepoint_rollback");
-
   /*
     Write ROLLBACK TO SAVEPOINT to the binlog cache if we have updated some
     non-transactional table. Otherwise, truncate the binlog cache starting
@@ -898,11 +906,20 @@ static int binlog_savepoint_rollback(han
   if (unlikely(trans_has_updated_non_trans_table(thd) ||
                (thd->variables.option_bits & OPTION_KEEP_LOG)))
   {
-    String log_query;
+    /*
+      Statically allocates room to store rollback to, '\0' and
+      an identifier: savepoint name.
+
+      Each identifier may have NAME_LEN * 2 due to quoting and
+      there are two quoting characters that wrap them.
+    */
+    char buffer[12 + 1 + NAME_LEN * 2 + 2];
+    String log_query(buffer, sizeof(buffer), system_charset_info);
+    log_query.length(0);
+
     if (log_query.append(STRING_WITH_LEN("ROLLBACK TO ")) ||
-        log_query.append("`") ||
-        log_query.append(thd->lex->ident.str, thd->lex->ident.length) ||
-        log_query.append("`"))
+        append_identifier(thd, &log_query, thd->lex->ident.str,
+                          thd->lex->ident.length))
       DBUG_RETURN(1);
     int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
     Query_log_event qinfo(thd, log_query.c_ptr_safe(), log_query.length(),
@@ -4302,7 +4319,6 @@ err1:
   return 1;
 }
 
-
 /*
   These functions are placed in this file since they need access to
   binlog_hton, which has internal linkage.

=== modified file 'sql/ha_ndbcluster_binlog.cc'
--- a/sql/ha_ndbcluster_binlog.cc	2010-10-21 09:49:16 +0000
+++ b/sql/ha_ndbcluster_binlog.cc	2011-01-19 15:48:29 +0000
@@ -1291,8 +1291,19 @@ int ndbcluster_log_schema_op(THD *thd, N
   {
     DBUG_RETURN(0);
   }
+  
+  /*
+    Statically allocates room to store either drop or rename,
+    dots, '\0' and some identifiers: db, new_db, table_name
+    and new_table_name.
+
+    Each identifier may have NAME_LEN * 2 due to quoting and
+    there are two quoting characters that wrap them.
+  */
+  char buffer[13 + 1 + 2 + (NAME_LEN * 8) + 8];
+  String log_query(buffer, sizeof(buffer), system_charset_info);
+  log_query.length(0);
 
-  char tmp_buf2[FN_REFLEN];
   const char *type_str;
   switch (type)
   {
@@ -1300,18 +1311,35 @@ int ndbcluster_log_schema_op(THD *thd, N
     /* drop database command, do not log at drop table */
     if (thd->lex->sql_command ==  SQLCOM_DROP_DB)
       DBUG_RETURN(0);
+
     /* redo the drop table query as is may contain several tables */
-    query= tmp_buf2;
-    query_length= (uint) (strxmov(tmp_buf2, "drop table `",
-                                  table_name, "`", NullS) - tmp_buf2);
+    if (log_query.append("drop table ") ||
+        append_identifier(thd_ndb, &log_query, table_name,
+                          strlen(table_name)))
+      DBUG_RETURN(1);
+
+    query= log_query.c_safe_ptr();
+    query_length= log_query.length();
     type_str= "drop table";
     break;
   case SOT_RENAME_TABLE:
     /* redo the rename table query as is may contain several tables */
-    query= tmp_buf2;
-    query_length= (uint) (strxmov(tmp_buf2, "rename table `",
-                                  db, ".", table_name, "` to `",
-                                  new_db, ".", new_table_name, "`", NullS) - tmp_buf2);
+    
+    if (query_log.append("rename table ") ||
+        append_identifier(thd_ndb, &log_query, db,
+                          strlen(db)) ||
+        query_log.append(".") ||
+        append_identifier(thd_ndb, &log_query, table_name,
+                          strlen(table_name)) ||
+        append_identifier(thd_ndb, &log_query, new_db,
+                          strlen(new_db)) ||
+        query_log.append(".") ||
+        append_identifier(thd_ndb, &log_query, new_table_name,
+                          strlen(new_table_name))) 
+      DBUG_RETURN(1);
+
+    query= log_query.c_safe_ptr();
+    query_length= log_query.length();
     type_str= "rename table";
     break;
   case SOT_CREATE_TABLE:

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2011-01-11 05:13:23 +0000
+++ b/sql/log_event.cc	2011-01-19 15:48:29 +0000
@@ -2190,6 +2190,13 @@ Rows_log_event::print_verbose_one_row(IO
 void Rows_log_event::print_verbose(IO_CACHE *file,
                                    PRINT_EVENT_INFO *print_event_info)
 {
+  /*
+    Statically allocates room to store '\0' and an identifier
+    that may have NAME_LEN * 2 due to quoting and there are
+    two quoting characters that wrap them.
+  */
+  char quoted_db[1 + NAME_LEN * 2 + 2];
+  char quoted_table[1 + NAME_LEN * 2 + 2];
   Table_map_log_event *map;
   table_def *td;
   const char *sql_command, *sql_clause1, *sql_clause2;
@@ -2226,17 +2233,20 @@ void Rows_log_event::print_verbose(IO_CA
   /* If the write rows event contained no values for the AI */
   if (((type_code == WRITE_ROWS_EVENT) && (m_rows_buf==m_rows_end)))
   {
-    my_b_printf(file, "### INSERT INTO `%s`.`%s` VALUES ()\n", 
-                      map->get_db_name(), map->get_table_name());
+    Log_event::quote_name(quoted_db, map->get_db_name());
+    Log_event::quote_name(quoted_table, map->get_table_name());
+    my_b_printf(file, "### INSERT INTO %s.%s VALUES ()\n", 
+                      quoted_db, quoted_table);
     goto end;
   }
 
   for (const uchar *value= m_rows_buf; value < m_rows_end; )
   {
     size_t length;
+    Log_event::quote_name(quoted_db, map->get_db_name());
+    Log_event::quote_name(quoted_table, map->get_table_name());
     my_b_printf(file, "### %s %s.%s\n",
-                      sql_command,
-                      map->get_db_name(), map->get_table_name());
+                      sql_command, quoted_db, quoted_table);
     /* Print the first image */
     if (!(length= print_verbose_one_row(file, td, print_event_info,
                                   &m_cols, value,
@@ -2399,15 +2409,27 @@ void Query_log_event::pack_info(Protocol
 {
   // TODO: show the catalog ??
   char *buf, *pos;
-  if (!(buf= (char*) my_malloc(9 + db_len + q_len, MYF(MY_WME))))
+  if (!(buf= (char*) my_malloc(6 + q_len + 1 + (db_len * 2) + 2, MYF(MY_WME))))
     return;
   pos= buf;
   if (!(flags & LOG_EVENT_SUPPRESS_USE_F)
       && db && db_len)
   {
-    pos= strmov(buf, "use `");
-    memcpy(pos, db, db_len);
-    pos= strmov(pos+db_len, "`; ");
+    /*
+      Statically allocates room to store '\0' and an identifier
+      that may have NAME_LEN * 2 due to quoting and there are
+      two quoting characters that wrap them.
+    */
+    char quoted_db[1 + NAME_LEN * 2 + 2];
+    size_t size= 0;
+
+    pos= strmov(buf, "use ");
+
+    Log_event::quote_name(quoted_db, db);
+    size= strlen(quoted_db);     
+    memcpy(pos, quoted_db, size);
+
+    pos= strmov(pos + size, "; ");
   }
   if (query && q_len)
   {
@@ -3241,8 +3263,17 @@ void Query_log_event::print_query_header
     different_db= memcmp(print_event_info->db, db, db_len + 1);
     if (different_db)
       memcpy(print_event_info->db, db, db_len + 1);
-    if (db[0] && different_db) 
-      my_b_printf(file, "use %s%s\n", db, print_event_info->delimiter);
+    if (db[0] && different_db)
+    {
+      /*
+        Statically allocates room to store '\0' and an identifier
+        that may have NAME_LEN * 2 due to quoting and there are
+        two quoting characters that wrap them.
+      */
+      char quoted_db[1 + NAME_LEN * 2 + 2];
+      Log_event::quote_name(quoted_db, db);
+      my_b_printf(file, "use %s%s\n", quoted_db, print_event_info->delimiter);
+    }
   }
 
   end=int10_to_str((long) when, strmov(buff,"SET TIMESTAMP="),10);
@@ -4656,34 +4687,46 @@ uint8 get_checksum_alg(const char* buf,
 
 #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
 uint Load_log_event::get_query_buffer_length()
-{
+{ 
   return
-    5 + db_len + 3 +                        // "use DB; "
-    18 + fname_len + 2 +                    // "LOAD DATA INFILE 'file''"
-    11 +                                    // "CONCURRENT "
-    7 +					    // LOCAL
-    9 +                                     // " REPLACE or IGNORE "
-    13 + table_name_len*2 +                 // "INTO TABLE `table`"
-    21 + sql_ex.field_term_len*4 + 2 +      // " FIELDS TERMINATED BY 'str'"
-    23 + sql_ex.enclosed_len*4 + 2 +        // " OPTIONALLY ENCLOSED BY 'str'"
-    12 + sql_ex.escaped_len*4 + 2 +         // " ESCAPED BY 'str'"
-    21 + sql_ex.line_term_len*4 + 2 +       // " LINES TERMINATED BY 'str'"
-    19 + sql_ex.line_start_len*4 + 2 +      // " LINES STARTING BY 'str'"
-    15 + 22 +                               // " IGNORE xxx  LINES"
-    3 + (num_fields-1)*2 + field_block_len; // " (field1, field2, ...)"
+    5 + (NAME_LEN * 2)  + 3 +                   // "use DB; "
+    18 + fname_len + 2 +                        // "LOAD DATA INFILE 'file''"
+    11 +                                        // "CONCURRENT "
+    7 +					        // LOCAL
+    9 +                                         // " REPLACE or IGNORE "
+    13 + table_name_len +                       // "INTO TABLE `table`"
+    21 + sql_ex.field_term_len*4 + 2 +          // " FIELDS TERMINATED BY 'str'"
+    23 + sql_ex.enclosed_len*4 + 2 +            // " OPTIONALLY ENCLOSED BY 'str'"
+    12 + sql_ex.escaped_len*4 + 2 +             // " ESCAPED BY 'str'"
+    21 + sql_ex.line_term_len*4 + 2 +           // " LINES TERMINATED BY 'str'"
+    19 + sql_ex.line_start_len*4 + 2 +          // " LINES STARTING BY 'str'"
+    15 + 22 +                                   // " IGNORE xxx  LINES"
+    3 + (num_fields - 1) * 2 + field_block_len; // " (field1, field2, ...)"
 }
 
 
 void Load_log_event::print_query(bool need_db, const char *cs, char *buf,
                                  char **end, char **fn_start, char **fn_end)
 {
+  /*
+    Statically allocates room to store '\0' and an identifier
+    that may have NAME_LEN * 2 due to quoting and there are
+    two quoting characters that wrap them.
+  */
+  char quoted_id[1 + NAME_LEN * 2 + 2];
+  size_t quoted_id_len= 0;
   char *pos= buf;
 
   if (need_db && db && db_len)
   {
-    pos= strmov(pos, "use `");
-    memcpy(pos, db, db_len);
-    pos= strmov(pos+db_len, "`; ");
+    String buffer;
+
+    buffer.set_charset(&my_charset_bin);
+    buffer.append("use ");
+    buffer.append(Log_event::quote_name(quoted_id, db));
+    buffer.append("; ");
+
+    pos= strmov(pos, buffer.c_ptr_safe());
   }
 
   pos= strmov(pos, "LOAD DATA ");
@@ -4710,17 +4753,15 @@ void Load_log_event::print_query(bool ne
   if (fn_end)
     *fn_end= pos;
 
-  pos= strmov(pos ," TABLE `");
+  pos= strmov(pos ," TABLE ");
   memcpy(pos, table_name, table_name_len);
   pos+= table_name_len;
 
   if (cs != NULL)
   {
-    pos= strmov(pos ,"` CHARACTER SET ");
+    pos= strmov(pos ," CHARACTER SET ");
     pos= strmov(pos ,  cs);
   }
-  else
-    pos= strmov(pos, "`");
 
   /* We have to create all optional fields as the default is not empty */
   pos= strmov(pos, " FIELDS TERMINATED BY ");
@@ -4760,8 +4801,12 @@ void Load_log_event::print_query(bool ne
         *pos++= ' ';
         *pos++= ',';
       }
-      memcpy(pos, field, field_lens[i]);
-      pos+=   field_lens[i];
+
+      Log_event::quote_name(quoted_id, field);
+      quoted_id_len= strlen(quoted_id);
+      memcpy(pos, quoted_id, quoted_id_len);
+      pos+= quoted_id_len;
+
       field+= field_lens[i]  + 1;
     }
     *pos++= ')';
@@ -5006,10 +5051,15 @@ void Load_log_event::print(FILE* file, P
   print(file, print_event_info, 0);
 }
 
-
 void Load_log_event::print(FILE* file_arg, PRINT_EVENT_INFO* print_event_info,
 			   bool commented)
 {
+  /*
+    Statically allocates room to store '\0' and an identifier
+    that may have NAME_LEN * 2 due to quoting and there are
+    two quoting characters that wrap them.
+  */
+  char quoted_id[1 + NAME_LEN * 2 + 2];
   IO_CACHE *const head= &print_event_info->head_cache;
 
   DBUG_ENTER("Load_log_event::print");
@@ -5033,11 +5083,14 @@ void Load_log_event::print(FILE* file_ar
         !commented)
       memcpy(print_event_info->db, db, db_len + 1);
   }
-  
+
   if (db && db[0] && different_db)
+  {
+    Log_event::quote_name(quoted_id, db);
     my_b_printf(head, "%suse %s%s\n", 
             commented ? "# " : "",
-            db, print_event_info->delimiter);
+            quoted_id, print_event_info->delimiter);
+  }
 
   if (flags & LOG_EVENT_THREAD_SPECIFIC_F)
     my_b_printf(head,"%sSET @@session.pseudo_thread_id=%lu%s\n",
@@ -5053,8 +5106,15 @@ void Load_log_event::print(FILE* file_ar
     my_b_printf(head,"REPLACE ");
   else if (sql_ex.opt_flags & IGNORE_FLAG)
     my_b_printf(head,"IGNORE ");
-  
-  my_b_printf(head, "INTO TABLE `%s`", table_name);
+
+  /*
+    This part of the code is called for old Load_log_event events and will
+    not work correctly if table is fully qualified (e.g. db`.`table) as we
+    cannot distinguish this case from tables with names like xxx`.`yyy or
+    xxx.yyy, i.e. with dots. See also write_execute_load_query_log_event.
+  */
+  Log_event::quote_name(quoted_id, table_name);
+  my_b_printf(head, "INTO TABLE %s", quoted_id);
   my_b_printf(head, " FIELDS TERMINATED BY ");
   pretty_print_str(head, sql_ex.field_term, sql_ex.field_term_len);
 
@@ -5069,7 +5129,6 @@ void Load_log_event::print(FILE* file_ar
   my_b_printf(head," LINES TERMINATED BY ");
   pretty_print_str(head, sql_ex.line_term, sql_ex.line_term_len);
 
-
   if (sql_ex.line_start)
   {
     my_b_printf(head," STARTING BY ");
@@ -5087,8 +5146,9 @@ void Load_log_event::print(FILE* file_ar
     {
       if (i)
         my_b_printf(head, ",");
-      my_b_printf(head, "%s", field);
 
+      Log_event::quote_name(quoted_id, field);
+      my_b_printf(head, "%s", quoted_id);
       field += field_lens[i]  + 1;
     }
     my_b_printf(head, ")");
@@ -6062,7 +6122,15 @@ Xid_log_event::do_shall_skip(Relay_log_i
 void User_var_log_event::pack_info(Protocol* protocol)
 {
   char *buf= 0;
-  uint val_offset= 4 + name_len;
+  /*
+    Statically allocates room to store '\0' and an identifier
+    that may have NAME_LEN * 2 due to quoting and there are
+    two quoting characters that wrap them.
+  */
+  char quoted_id[1 + NAME_LEN * 2 + 2];
+  Log_event::quote_name(quoted_id, name);
+  size_t size= strlen(quoted_id);
+  uint val_offset= 2 + size;
   uint event_len= val_offset;
 
   if (is_null)
@@ -6131,16 +6199,13 @@ void User_var_log_event::pack_info(Proto
     }
   }
   buf[0]= '@';
-  buf[1]= '`';
-  memcpy(buf+2, name, name_len);
-  buf[2+name_len]= '`';
-  buf[3+name_len]= '=';
+  memcpy(buf + 1, quoted_id, size);
+  buf[1 + size]= '=';
   protocol->store(buf, event_len, &my_charset_bin);
   my_free(buf);
 }
 #endif /* !MYSQL_CLIENT */
 
-
 User_var_log_event::
 User_var_log_event(const char* buf,
                    const Format_description_log_event* description_event)
@@ -6281,6 +6346,12 @@ bool User_var_log_event::write(IO_CACHE*
 #ifdef MYSQL_CLIENT
 void User_var_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 {
+  /*
+    Statically allocates room to store '\0' and an identifier
+    that may have NAME_LEN * 2 due to quoting and there are
+    two quoting characters that wrap them.
+  */
+  char quoted_id[1 + NAME_LEN * 2 + 2];
   IO_CACHE *const head= &print_event_info->head_cache;
 
   if (!print_event_info->short_form)
@@ -6289,9 +6360,9 @@ void User_var_log_event::print(FILE* fil
     my_b_printf(head, "\tUser_var\n");
   }
 
-  my_b_printf(head, "SET @`");
-  my_b_write(head, (uchar*) name, (uint) (name_len));
-  my_b_printf(head, "`");
+  my_b_printf(head, "SET @");
+  Log_event::quote_name(quoted_id, name);
+  my_b_write(head, (uchar*) quoted_id, (uint) strlen(quoted_id));
 
   if (is_null)
   {
@@ -6367,7 +6438,7 @@ void User_var_log_event::print(FILE* fil
       else
         my_b_printf(head, ":=_%s %s COLLATE `%s`%s\n",
                     cs->csname, hex_str, cs->name,
-                    print_event_info->delimiter);
+                    print_event_info->delimiter);  // Alfranio
       my_afree(hex_str);
     }
       break;
@@ -7426,14 +7497,24 @@ void Execute_load_query_log_event::print
 void Execute_load_query_log_event::pack_info(Protocol *protocol)
 {
   char *buf, *pos;
-  if (!(buf= (char*) my_malloc(9 + db_len + q_len + 10 + 21, MYF(MY_WME))))
+  if (!(buf= (char*) my_malloc(9 + (db_len * 2) + 2 + q_len + 10 + 21, MYF(MY_WME))))
     return;
   pos= buf;
   if (db && db_len)
   {
-    pos= strmov(buf, "use `");
-    memcpy(pos, db, db_len);
-    pos= strmov(pos+db_len, "`; ");
+    /*
+      Statically allocates room to store '\0' and an identifier
+      that may have NAME_LEN * 2 due to quoting and there are
+      two quoting characters that wrap them.
+    */
+    char quoted_db[1 + NAME_LEN * 2 + 2];
+    size_t size= 0;
+    Log_event::quote_name(quoted_db, db);
+    size= strlen(quoted_db);
+
+    pos= strmov(buf, "use ");
+    memcpy(pos, quoted_db, size);
+    pos= strmov(pos + size, "; ");
   }
   if (query && q_len)
   {
@@ -7446,7 +7527,6 @@ void Execute_load_query_log_event::pack_
   my_free(buf);
 }
 
-
 int
 Execute_load_query_log_event::do_apply_event(Relay_log_info const *rli)
 {
@@ -8910,10 +8990,19 @@ void Table_map_log_event::print(FILE *,
 {
   if (!print_event_info->short_form)
   {
+    /*
+      Statically allocates room to store '\0' and an identifier
+      that may have NAME_LEN * 2 due to quoting and there are
+      two quoting characters that wrap them.
+    */
+    char quoted_db[1 + NAME_LEN * 2 + 2];
+    char quoted_table[1 + NAME_LEN * 2 + 2];
     print_header(&print_event_info->head_cache, print_event_info, TRUE);
+    Log_event::quote_name(quoted_db, m_dbnam);
+    Log_event::quote_name(quoted_table, m_tblnam);
     my_b_printf(&print_event_info->head_cache,
-                "\tTable_map: `%s`.`%s` mapped to number %lu\n",
-                m_dbnam, m_tblnam, m_table_id);
+                "\tTable_map: %s.%s mapped to number %lu\n",
+                quoted_db, quoted_table, m_table_id);
     print_base64(&print_event_info->body_cache, print_event_info, TRUE);
   }
 }

=== modified file 'sql/log_event.h'
--- a/sql/log_event.h	2011-01-11 05:13:23 +0000
+++ b/sql/log_event.h	2011-01-19 15:48:29 +0000
@@ -33,6 +33,7 @@
 #endif
 
 #include <my_bitmap.h>
+#include <m_string.h>
 #include "rpl_constants.h"
 
 #ifdef MYSQL_CLIENT
@@ -1123,6 +1124,10 @@ public:
     return my_time(0);
   }
 #endif
+  static char *quote_name(char *buffer, const char *name)
+  {
+    return (quote_str(buffer, name, '`'));
+  }
   virtual Log_event_type get_type_code() = 0;
   virtual bool is_valid() const = 0;
   void set_artificial_event() { flags |= LOG_EVENT_ARTIFICIAL_F; }

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2011-01-11 11:45:02 +0000
+++ b/sql/sql_base.cc	2011-01-19 15:48:29 +0000
@@ -3758,22 +3758,45 @@ static bool open_table_entry_fini(THD *t
     entry->file->implicit_emptied= 0;
     if (mysql_bin_log.is_open())
     {
-      char *query, *end;
-      uint query_buf_size= 20 + share->db.length + share->table_name.length +1;
-      if ((query= (char*) my_malloc(query_buf_size,MYF(MY_WME))))
+      /*
+        Dynamically allocates room to store delete from, '\0', dot
+        and some identifiers: db and table_name.
+
+        Each identifier may have NAME_LEN * 2 due to quoting and
+        there are two quoting characters that wrap them.
+      */
+      char *buffer= NULL;
+      uint buffer_size= 13 + 1 + 1 + (share->db.length * 2) + 2 +
+                        (share->table_name.length * 2) + 2;
+      if ((buffer= (char*) my_malloc(buffer_size, MYF(MY_WME))))
       {
+        /*
+          Defines a buffer in the stack to avoid having dynamic allocation
+          issues within the String object.
+        */
+        String log_query(buffer, buffer_size, system_charset_info);
+        log_query.length(0);
+
         /* this DELETE FROM is needed even with row-based binlogging */
-        end = strxmov(strmov(query, "DELETE FROM `"),
-                      share->db.str,"`.`",share->table_name.str,"`", NullS);
+        if (log_query.append("DELETE FROM ")  ||
+            append_identifier(thd, &log_query, share->db.str,
+                              share->db.length) ||
+            log_query.append(".") ||
+            append_identifier(thd, &log_query, share->table_name.str,
+                              share->table_name.length))
+        {
+          my_free(buffer);
+          return TRUE;
+        }
+
         int errcode= query_error_code(thd, TRUE);
-        if (thd->binlog_query(THD::STMT_QUERY_TYPE,
-                              query, (ulong)(end-query),
-                              FALSE, FALSE, FALSE, errcode))
+        if (thd->binlog_query(THD::STMT_QUERY_TYPE, log_query.c_ptr_safe(),
+                              log_query.length(), FALSE, FALSE, FALSE, errcode))
         {
-          my_free(query);
+          my_free(buffer);
           return TRUE;
         }
-        my_free(query);
+        my_free(buffer);
       }
       else
       {

=== modified file 'sql/sql_db.cc'
--- a/sql/sql_db.cc	2010-12-10 12:52:55 +0000
+++ b/sql/sql_db.cc	2011-01-19 15:48:29 +0000
@@ -30,6 +30,7 @@
 #include "log_event.h"                   // Query_log_event
 #include "sql_base.h"                    // lock_table_names, tdc_remove_table
 #include "sql_handler.h"                 // mysql_ha_rm_tables
+#include "sql_show.h"                    // append_identifier
 #include <mysys_err.h>
 #include "sp.h"
 #include "events.h"
@@ -541,7 +542,6 @@ int mysql_create_db(THD *thd, char *db,
                      bool silent)
 {
   char	 path[FN_REFLEN+16];
-  char	 tmp_query[FN_REFLEN+16];
   long result= 1;
   int error= 0;
   MY_STAT stat_info;
@@ -618,12 +618,25 @@ not_silent:
   {
     char *query;
     uint query_length;
+    /*
+      Statically allocates room to store create database, '\0' and
+      an identifier that may have NAME_LEN * 2 due to quoting and
+      there are two quoting characters that wrap them.
+    */
+    char buffer[16 + 1 + NAME_LEN * 2 + 2];
+    String log_query(buffer, sizeof(buffer), system_charset_info);
+    log_query.length(0);
 
     if (!thd->query())                          // Only in replication
     {
-      query= 	     tmp_query;
-      query_length= (uint) (strxmov(tmp_query,"create database `",
-                                    db, "`", NullS) - tmp_query);
+      if (log_query.append("create database ") ||
+          append_identifier(thd, &log_query, db, strlen(db)))
+      {
+        error= -1;
+        goto exit;
+      }
+      query= log_query.c_ptr_safe();
+      query_length= log_query.length();
     }
     else
     {
@@ -885,12 +898,26 @@ update_binlog:
   {
     const char *query;
     ulong query_length;
+    /*
+      Statically allocates room to store drop database, '\0' and
+      an identifier that may have NAME_LEN * 2 due to quoting and
+      there are two quoting characters that wrap them.
+    */
+    char buffer[16 + 1 + NAME_LEN * 2 + 2];
+    String log_query(buffer, sizeof(buffer), system_charset_info);
+    log_query.length(0);
+
     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);
+      if (log_query.append("drop database ") ||
+          append_identifier(thd, &log_query, db, strlen(db)))
+      {
+        error= true;
+        goto exit;
+      }
+      query= log_query.c_ptr_safe();
+      query_length= log_query.length();
     }
     else
     {
@@ -938,11 +965,22 @@ update_binlog:
 
     for (tbl= tables; tbl; tbl= tbl->next_local)
     {
-      uint tbl_name_len;
-
-      /* 3 for the quotes and the comma*/
-      tbl_name_len= strlen(tbl->table_name) + 3;
-      if (query_pos + tbl_name_len + 1 >= query_end)
+      size_t size= 0;
+      /*
+        Statically allocates room to store an identifier that may
+        have NAME_LEN * 2 due to quoting and there are two quoting
+        characters that wrap them.
+      */
+      char buffer[1 + NAME_LEN * 2 + 2];
+      String log_query(buffer, sizeof(buffer), system_charset_info);
+      log_query.length(0);
+
+      append_identifier(thd, &log_query, tbl->table_name,
+                        strlen(tbl->table_name));
+ 
+      /* we add 1 to the size for the comma*/
+      size= log_query.length() + 1;
+      if (query_pos + size + 1 >= query_end)
       {
         /*
           These DDL methods and logging are protected with the exclusive
@@ -956,9 +994,7 @@ update_binlog:
         query_pos= query_data_start;
       }
 
-      *query_pos++ = '`';
-      query_pos= strmov(query_pos,tbl->table_name);
-      *query_pos++ = '`';
+      query_pos= strmov(query_pos, log_query.c_ptr_safe());
       *query_pos++ = ',';
     }
 

=== modified file 'sql/sql_load.cc'
--- a/sql/sql_load.cc	2010-12-10 16:55:50 +0000
+++ b/sql/sql_load.cc	2011-01-19 15:48:29 +0000
@@ -29,6 +29,7 @@
                         // prepare_triggers_for_insert_stmt,
                         // write_record
 #include "sql_acl.h"    // INSERT_ACL, UPDATE_ACL
+#include "sql_show.h"   // append_identifier
 #include "log_event.h"  // Delete_file_log_event,
                         // Execute_load_query_log_event,
                         // LOG_EVENT_UPDATE_TABLE_MAP_VERSION_F
@@ -672,10 +673,23 @@ static bool write_execute_load_query_log
   Item                *item, *val;
   String               pfield, pfields;
   int                  n;
-  const char          *tbl= table_name_arg;
+  const char          *tbl= NULL; 
   const char          *tdb= (thd->db != NULL ? thd->db : db_arg);
   String              string_buf;
 
+  /*
+    The SQL statement is not written to the event and is automaticaly
+    constructed based on information, such as table and fields, that
+    is stored in the event.
+
+    In the future, if we decide to filter on the master, this may
+    cause problems because the table name is written to the binary
+    log with quote information. See WL#2387.
+
+    This is necessary because we need to ensure that tables with
+    names like xxx`.`yyy or xxx.yyy, i.e. with dots, are correctly
+    replicated.
+  */
   if (!thd->db || strcmp(db_arg, thd->db)) 
   {
     /*
@@ -684,13 +698,18 @@ static bool write_execute_load_query_log
       becomes a FQ name.
      */
     string_buf.set_charset(system_charset_info);
-    string_buf.append(db_arg);
-    string_buf.append("`");
+    append_identifier(thd, &string_buf, db_arg, strlen(db_arg));
     string_buf.append(".");
-    string_buf.append("`");
-    string_buf.append(table_name_arg);
-    tbl= string_buf.c_ptr_safe();
+    append_identifier(thd, &string_buf, table_name_arg,
+                     strlen(table_name_arg));
+  }
+  else
+  {
+    string_buf.set_charset(system_charset_info);
+    append_identifier(thd, &string_buf, table_name_arg,
+                     strlen(table_name_arg));
   }
+  tbl= string_buf.c_ptr_safe();
 
   Load_log_event       lle(thd, ex, tdb, tbl, fv, is_concurrent,
                            duplicates, ignore, transactional_table);
@@ -716,11 +735,8 @@ static bool write_execute_load_query_log
       if (n++)
         pfields.append(", ");
       if (item->type() == Item::FIELD_ITEM)
-      {
-        pfields.append("`");
-        pfields.append(item->name);
-        pfields.append("`");
-      }
+        append_identifier(thd, &pfields, item->name,
+                          strlen(item->name));
       else
         item->print(&pfields, QT_ORDINARY);
     }
@@ -740,9 +756,8 @@ static bool write_execute_load_query_log
       val= lv++;
       if (n++)
         pfields.append(", ");
-      pfields.append("`");
-      pfields.append(item->name);
-      pfields.append("`");
+      append_identifier(thd, &pfields, item->name,
+                        strlen(item->name));
       pfields.append("=");
       val->print(&pfields, QT_ORDINARY);
     }

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	2011-01-07 12:03:21 +0000
+++ b/sql/sql_show.cc	2011-01-19 15:48:29 +0000
@@ -940,7 +940,9 @@ static const char *require_quotes(const
 
 /*
   Quote the given identifier if needed and append it to the target string.
-  If the given identifier is empty, it will be quoted.
+  If the given identifier is empty, it will be quoted. Note that this routine
+  does not check errors. So, either the packet has enough room to get the
+  identifier or the server will crash. / Alfranio
 
   SYNOPSIS
   append_identifier()
@@ -950,7 +952,7 @@ static const char *require_quotes(const
   name_length           length of the appending identifier
 */
 
-void
+bool
 append_identifier(THD *thd, String *packet, const char *name, uint length)
 {
   const char *name_end;
@@ -960,7 +962,7 @@ append_identifier(THD *thd, String *pack
   if (q == EOF)
   {
     packet->append(name, length, packet->charset());
-    return;
+    return FALSE;
   }
 
   /*
@@ -990,6 +992,8 @@ append_identifier(THD *thd, String *pack
     packet->append(name, length, system_charset_info);
   }
   packet->append(&quote_char, 1, system_charset_info);
+  
+  return FALSE;
 }
 
 

=== modified file 'sql/sql_show.h'
--- a/sql/sql_show.h	2010-10-22 12:37:58 +0000
+++ b/sql/sql_show.h	2011-01-19 15:48:29 +0000
@@ -90,8 +90,8 @@ int view_store_create_info(THD *thd, TAB
 
 int copy_event_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table);
 
-void append_identifier(THD *thd, String *packet, const char *name,
-		       uint length);
+bool append_identifier(THD *thd, String *packet, const char *name,
+                       uint length);
 void mysqld_list_fields(THD *thd,TABLE_LIST *table, const char *wild);
 bool mysqld_show_create(THD *thd, TABLE_LIST *table_list);
 bool mysqld_show_create_db(THD *thd, char *dbname, HA_CREATE_INFO *create);

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2010-12-17 18:43:38 +0000
+++ b/sql/sql_table.cc	2011-01-19 15:48:29 +0000
@@ -2161,6 +2161,7 @@ int mysql_rm_table_no_locks(THD *thd, TA
   bool non_tmp_table_deleted= 0;
   String built_query;
   String built_trans_tmp_query, built_non_trans_tmp_query;
+
   DBUG_ENTER("mysql_rm_table_no_locks");
 
   /*
@@ -2280,14 +2281,14 @@ int mysql_rm_table_no_locks(THD *thd, TA
           Don't write the database name if it is the current one (or if
           thd->db is NULL).
         */
-        built_ptr_query->append("`");
         if (thd->db == NULL || strcmp(db,thd->db) != 0)
         {
-          built_ptr_query->append(db);
-          built_ptr_query->append("`.`");
+          append_identifier(thd, built_ptr_query, db, strlen(db));
+          built_ptr_query->append(".");
         }
-        built_ptr_query->append(table->table_name);
-        built_ptr_query->append("`,");
+        append_identifier(thd, built_ptr_query, table->table_name,
+                          strlen(table->table_name));
+        built_ptr_query->append(",");
       }
       /*
         This means that a temporary table was droped and as such there
@@ -2346,15 +2347,14 @@ int mysql_rm_table_no_locks(THD *thd, TA
           Don't write the database name if it is the current one (or if
           thd->db is NULL).
         */
-        built_query.append("`");
         if (thd->db == NULL || strcmp(db,thd->db) != 0)
         {
-          built_query.append(db);
-          built_query.append("`.`");
+          append_identifier(thd, &built_query, db, strlen(db));
+          built_query.append(".");
         }
-
-        built_query.append(table->table_name);
-        built_query.append("`,");
+        append_identifier(thd, &built_query, table->table_name,
+                          strlen(table->table_name));
+        built_query.append(",");
       }
     }
     DEBUG_SYNC(thd, "rm_table_no_locks_before_delete_table");
@@ -4107,7 +4107,6 @@ bool mysql_create_table_no_lock(THD *thd
   DBUG_PRINT("enter", ("db: '%s'  table: '%s'  tmp: %d",
                        db, table_name, internal_tmp_table));
 
-
   /* Check for duplicate fields and check type of table to create */
   if (!alter_info->create_list.elements)
   {

=== modified file 'strings/strfill.c'
--- a/strings/strfill.c	2007-05-10 09:59:39 +0000
+++ b/strings/strfill.c	2011-01-19 15:48:29 +0000
@@ -32,3 +32,30 @@ char * strfill(char *s, size_t len, pcha
   *(s) = '\0';
   return(s);
 } /* strfill */
+
+/**
+  Wraps up name with qtype, doubles any qtype in name and stores the
+  result string in buffer, i.e., this function quotes name.
+
+  @param[in,out] buffer Where the quoted name is stored.
+  @param[in]     name   String that will be quoted.
+  @param[in]     qtype  Token used to quote name.
+
+  @return
+    @c buffer where the result string is placed.
+*/
+char *quote_str(char *buffer, const char *name, char qtype)
+{
+  char *to= buffer;
+
+  *to++= qtype;
+  while (*name)
+  {
+    if (*name == qtype)
+      *to++= qtype;
+    *to++= *name++;
+  }
+  to[0]= qtype;
+  to[1]= 0;
+  return buffer;
+}


Attachment: [text/bzr-bundle] bzr/alfranio.correia@oracle.com-20110119154829-x0je4xfyztmw27i7.bundle
Thread
bzr commit into mysql-trunk branch (alfranio.correia:3527) Bug#57873Alfranio Correia19 Jan
  • Re: bzr commit into mysql-trunk branch (alfranio.correia:3527)Bug#57873anders31 Jan
    • Re: bzr commit into mysql-trunk branch (alfranio.correia:3527) Bug#57873Alfranio Correia31 Jan
      • Re: bzr commit into mysql-trunk branch (alfranio.correia:3527)Bug#57873anders31 Jan
  • Re: bzr commit into mysql-trunk branch (alfranio.correia:3527)Bug#57873anders1 Feb
  • Re: bzr commit into mysql-trunk branch (alfranio.correia:3527) Bug#57873Luís Soares1 Mar