1 backup.mysql.inc protected BackupMySql::getTableStructureSql($table)

Get the SQL for the structure of the given table.

File

core/includes/backup/backup.mysql.inc, line 278
Contains the BackupMySQL class.

Class

BackupMySql
Creates and restores backups from a MySQL database source.

Code

protected function getTableStructureSql($table) {
  $out = "";
  $result = $this->query("SHOW CREATE TABLE `" . $table['name'] . "`", array(), array('fetch' => PDO::FETCH_ASSOC));
  foreach ($result as $create) {
    // Lowercase the keys because between Drupal 7.12 and 7.13/14 the default
    // query behavior was changed. See: http://drupal.org/node/1171866
    $create = array_change_key_case($create);
    $out .= "DROP TABLE IF EXISTS `" . $table['name'] . "`;\n";
    // Remove newlines and convert " to ` because PDO seems to convert those
    // for some reason.
    $out .= strtr($create['create table'], array("\n" => ' ', '"' => '`'));
    if ($table['auto_increment']) {
      $out .= " AUTO_INCREMENT=" . $table['auto_increment'];
    }
    $out .= ";\n";
  }
  return $out;
}