List:Commits« Previous MessageNext Message »
From:Sanjay Manwani Date:November 4 2009 2:38pm
Subject:bzr commit into mysql-6.0-backup branch (sanjay.manwani:2854) Bug#33354
View as plain text  
#At file:///C:/Work/mysql_checkouts/mysql-6.0-backup-02/ based on revid:rafal.somla@stripped1102140519-nywm403dksch0u6u

 2854 Sanjay Manwani	2009-11-04
      BUG#33354 Backup: restore changes current database to null  
      
      Added a variable m_db_saved_string to Si_session_context 
      to save the default database if available.
      
      added test backup_use_db_restore.test and its result file
      to the backup suite.

    added:
      mysql-test/suite/backup/r/backup_use_db_restore.result
      mysql-test/suite/backup/t/backup_use_db_restore.test
    modified:
      sql/si_objects.cc
=== added file 'mysql-test/suite/backup/r/backup_use_db_restore.result'
=== added file 'mysql-test/suite/backup/r/backup_use_db_restore.result'
--- a/mysql-test/suite/backup/r/backup_use_db_restore.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup/r/backup_use_db_restore.result	2009-11-04 13:38:43 +0000
@@ -0,0 +1,64 @@
+#
+# This test ensures that if there is a database in use before
+# a "restore" command, then the same database remains the 
+# default database even after restore.
+#
+# for details see : Bug#33354 : Backup: restore changes current 
+# database to null 
+#
+DROP DATABASE IF EXISTS db1;
+USE test;
+SELECT DATABASE();
+DATABASE()
+test
+CREATE DATABASE db1;
+CREATE TABLE db1.t (i int, j int) engine=myisam;
+INSERT INTO db1.t values(10, 11);
+BACKUP DATABASE db1 to 'image1.bak';
+backup_id
+#
+RESTORE FROM 'image1.bak' overwrite;
+backup_id
+#
+SELECT DATABASE();
+DATABASE()
+test
+#
+# Try again now using the database which is being restored
+#
+USE db1;
+SELECT DATABASE();
+DATABASE()
+db1
+BACKUP DATABASE db1 to 'image2.bak';
+backup_id
+#
+RESTORE FROM 'image2.bak' overwrite;
+backup_id
+#
+SELECT DATABASE();
+DATABASE()
+db1
+DROP DATABASE IF EXISTS
`ニホ�ゴ`;
+SET NAMES utf8;
+SET character_set_database = utf8;
+CREATE DATABASE
`ニホï¾�コï¾SELECT DATABASE();
+DATABASE()
+ニホge3.bak';
+backup_id
+#
+RESTORE FROM 'image3.bak' overwrite;
+backup_id
+#
+SELECT DATABASE();
+DATABASE()
+ニホ�コDROP DATABASE db1;
+DROP DATABASE `ニï¾test/suite/backup/t/backup_use_db_restore.test'
--- a/mysql-test/suite/backup/t/backup_use_db_restore.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup/t/backup_use_db_restore.test	2009-11-04 13:38:43 +0000
@@ -0,0 +1,84 @@
+--echo #
+--echo # This test ensures that if there is a database in use before
+--echo # a "restore" command, then the same database remains the 
+--echo # default database even after restore.
+--echo #
+--echo # for details see : Bug#33354 : Backup: restore changes current 
+--echo # database to null 
+--echo #
+
+
+--disable_warnings
+DROP DATABASE IF EXISTS db1;
+--enable_warnings
+
+# Use the test database
+USE test;
+SELECT DATABASE();
+
+# Now create a database abd backup and restore it
+CREATE DATABASE db1;
+CREATE TABLE db1.t (i int, j int) engine=myisam;
+INSERT INTO db1.t values(10, 11);
+
+--replace_column 1 # 
+BACKUP DATABASE db1 to 'image1.bak';
+
+--replace_column 1 # 
+RESTORE FROM 'image1.bak' overwrite;
+
+# The database 'test' should still be the default database
+SELECT DATABASE();
+
+--echo #
+--echo # Try again now using the database which is being restored
+--echo #
+
+USE db1;
+SELECT DATABASE();
+
+--replace_column 1 # 
+BACKUP DATABASE db1 to 'image2.bak';
+
+--replace_column 1 # 
+RESTORE FROM 'image2.bak' overwrite;
+
+# The restored database should be the default database
+SELECT DATABASE();
+
+# Now lets try a UTF8 character set database
+
+--disable_warnings
+DROP DATABASE IF EXISTS `ニホ�ゴ`;
+--enable_warnings
+
+SET NAMES utf8;
+SET character_set_database = utf8;
+
+CREATE DATABASE `ニホ�ゴ`;
+
+USE `ニホï¾�ï database is indeed the default
+SELECT DATABASE();
+
+--replace_column 1 # 
+BACKUP DATABASE db1 to 'image3.bak';
+
+--replace_column 1 # 
+RESTORE FROM 'image3.bak' overwrite;
+
+# After restore the default database should be the international database
+SELECT DATABASE();
+
+--echo #
+--echo # Cleanup
+--echo #
+
+DROP TABLE db1.t;
+DROP DATABASE db1;
+DROP DATABASE
`ニホ�ゴ`;
+let $MYSQLD_BACKUPDIR= `select @@backupdir`;
+remove_file $MYSQLD_BACKUPDIR/image1.bak;
+remove_file $MYSQLD_BACKUPDIR/image2.bak;
+remove_file $MYSQLD_BACKUPDIR/image3.bak;

=== modified file 'sql/si_objects.cc'
--- a/sql/si_objects.cc	2009-10-23 21:26:11 +0000
+++ b/sql/si_objects.cc	2009-11-04 13:38:43 +0000
@@ -75,6 +75,7 @@
   Time_zone *m_tz_saved;
   TABLE *m_tmp_tables_saved;
   bool m_engage_general_log;  
+  String m_db_saved_string;
 
 private:
   Si_session_context(const Si_session_context &);
@@ -104,6 +105,16 @@
   m_tz_saved= thd->variables.time_zone;
   m_tmp_tables_saved= thd->temporary_tables;
   m_old_db_collation= thd->variables.collation_database;
+  /* Saving the default database */
+  if (thd->db)
+    m_db_saved_string.copy(thd->db, thd->db_length, thd->db_charset);
+  else 
+  /*
+    Clear up and old data in the saved database since there is no default
+    database set.
+  */
+    if (!m_db_saved_string.is_empty())
+      m_db_saved_string= 0; 
   DBUG_VOID_RETURN;
 }
 
@@ -156,6 +167,14 @@
 {
   DBUG_ENTER("Si_session_context::restore_si_ctx");
 
+  /* Restoring the default database */
+  if ((m_db_saved_string != 0) &&
+      (thd->db != 0) &&
+      sortcmp(&m_db_saved_string, 
+              &String(thd->db, thd->db_length, thd->db_charset),
+              m_db_saved_string.charset()) != 0)
+    mysql_change_db(thd, &m_db_saved_string.lex_string(), FALSE);
+
   thd->variables.sql_mode= m_sql_mode_saved;
   thd->variables.time_zone= m_tz_saved;
 

Attachment: [text/bzr-bundle] bzr/sanjay.manwani@sun.com-20091104133843-xp7ynm4s3s19ul54.bundle
Thread
bzr commit into mysql-6.0-backup branch (sanjay.manwani:2854) Bug#33354Sanjay Manwani4 Nov 2009
  • Re: bzr commit into mysql-6.0-backup branch (sanjay.manwani:2854)Bug#33354Charles Bell5 Nov 2009
Re: bzr commit into mysql-6.0-backup branch (sanjay.manwani:2854)Bug#33354sanjay Manwani11 Nov 2009