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.4.5
diff -u -p -r1.1.4.5 destinations.db.mysql.inc
--- includes/destinations.db.mysql.inc	1 Feb 2011 03:48:49 -0000	1.1.4.5
+++ includes/destinations.db.mysql.inc	3 Feb 2011 16:29:43 -0000
@@ -93,6 +93,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;
@@ -105,6 +106,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;
@@ -184,7 +192,24 @@ class backup_migrate_destination_db_mysq
     // get auto_increment values and names of all tables
     $tables = $this->query("show table status", array(), array('fetch' => PDO::FETCH_ASSOC));
     foreach ($tables as $table) {
-      $out[$table['name']] = $table;
+      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;
   }
@@ -208,6 +233,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) {
