MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Sanjay Manwani Date:October 16 2009 3:24pm
Subject:bzr commit into mysql-6.0-backup branch (sanjay.manwani:2882) Bug#33354
View as plain text  
#At file:///C:/Work/mysql_checkouts/mysql-6.0-backup-02/ based on revid:charles.bell@stripped91015154239-zboe2on7hmx3wuwb

 2882 Sanjay Manwani	2009-10-16
      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

    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-10-16 15:24:22 +0000
@@ -0,0 +1,63 @@
+#
+# 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 `ニホï¾�ï to 'image3.bak';
+backup_id
+#
+RESTORE FROM 'image3.bak' overwrite;
+backup_id
+#
+SELECT DATABASE();
+DATABASE()
+ニホï¾b1.t;
+DROP DATABASE IF EXISTS db1;
+DROP DATABASE `ニホ�ゴ`;

=== added file 'mysql-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-10-16 15:24:22 +0000
@@ -0,0 +1,83 @@
+--echo #
+--echo # This test ensures that if there is a database in use before a "restore" 
+--echo # command, then the same database remains the default database even after
+--echo # restore.
+--echo #
+--echo # for details see : Bug#33354 : Backup: restore changes current database to null 
+--echo # 
+
+--disable_warnings
+DROP DATABASE IF EXISTS db1;
+
+# 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
+
+DROP DATABASE IF EXISTS `ニホ�ゴ`;
+
+SET NAMES utf8;
+SET character_set_database = utf8;
+
+CREATE DATABASE `ニホï¾�コï`;
+
+# Ensure that our international 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();
+
+
+--enable_warnings
+
+--echo #
+--echo # Cleanup
+--echo #
+
+DROP TABLE db1.t;
+DROP DATABASE IF EXISTS db1;
+DROP DATABASE `ニï¾`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-09 13:03:56 +0000
+++ b/sql/si_objects.cc	2009-10-16 15:24:22 +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,13 @@
   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 
+    /*Clean up any old data in the saved DB since there is no default db*/
+    if (!m_db_saved_string.is_empty())
+      m_db_saved_string= 0; 
   DBUG_VOID_RETURN;
 }
 
@@ -156,6 +164,12 @@
 {
   DBUG_ENTER("Si_session_context::restore_si_ctx");
 
+  /* Restoring the default database */
+  if (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-20091016152422-8rrvyuz15vu3pzes.bundle
Thread
bzr commit into mysql-6.0-backup branch (sanjay.manwani:2882) Bug#33354Sanjay Manwani16 Oct
  • Re: bzr commit into mysql-6.0-backup branch (sanjay.manwani:2882)Bug#33354Charles Bell16 Oct