? 447522-view-support-1.patch ? 447522-view-support-2.patch ? 447522-view-support.patch Index: includes/destinations.db.mysql.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/backup_migrate/includes/Attic/destinations.db.mysql.inc,v retrieving revision 1.1.2.4 diff -u -p -b -r1.1.2.4 destinations.db.mysql.inc --- includes/destinations.db.mysql.inc 26 Nov 2009 21:58:21 -0000 1.1.2.4 +++ includes/destinations.db.mysql.inc 11 Jan 2011 14:59:29 -0000 @@ -90,6 +90,7 @@ class backup_migrate_destination_db_mysq if ($file->open(TRUE)) { $file->write($this->_get_sql_file_header()); $alltables = $this->_get_tables(); + $allviews = $this->_get_views(); foreach ($alltables as $table) { if (_backup_migrate_check_timeout()) { return FALSE; @@ -102,6 +103,13 @@ class backup_migrate_destination_db_mysq } } } + foreach ($allviews as $view) { + if (_backup_migrate_check_timeout()) { + return FALSE; + } + $file->write($this->_get_view_create_sql($view)); + + } $file->write($this->_get_sql_file_footer()); $file->close(); return $lines; @@ -179,8 +187,25 @@ class backup_migrate_destination_db_mysq // get auto_increment values and names of all tables $tables = db_query("show table status"); while ($table = db_fetch_array($tables)) { + if (!empty($table['Engine'])) { $out[$table['Name']] = $table; } + } + return $out; + } + + /** + * Get a list of views in the db. + */ + function _get_views() { + $out = array(); + // get auto_increment values and names of all tables + $tables = db_query("show table status"); + while ($table = db_fetch_array($tables)) { + if (empty($table['Engine'])) { + $out[$table['Name']] = $table; + } + } return $out; } @@ -202,6 +227,25 @@ class backup_migrate_destination_db_mysq } /** + * Get the sql for the structure of the given table. + */ + function _get_view_create_sql($view) { + $out = ""; + // Switch SQL mode to get rid of "CREATE ALGORITHM..." what requires more permissions + troubles with the DEFINER user + $sql_mode = db_result(db_query("SELECT @@SESSION.sql_mode")); + db_query("SET sql_mode = 'ANSI'"); + $result = db_query("SHOW CREATE VIEW `". $view['Name'] ."`"); + db_query("SET SQL_mode = '%s'", $sql_mode); + if ($create = db_fetch_array($result)) { + $out .= "DROP VIEW IF EXISTS `". $view['Name'] ."`;\n"; + $out .= "SET sql_mode = 'ANSI';\n"; + $out .= strtr($create['Create View'], "\n", " ") . ";\n"; + $out .= "SET sql_mode = '$sql_mode';\n"; + } + return $out; + } + + /** * Get the sql to insert the data for a given table */ function _dump_table_data_sql_to_file($file, $table) {