1 backup.mysql.inc private BackupMySql::readSqlCommandFromFile(BackupFile $file)

Read a multiline sql command from a file.

Supports the formatting created by mysqldump, but won't handle multiline comments.

File

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

Class

BackupMySql
Creates and restores backups from a MySQL database source.

Code

private function readSqlCommandFromFile(BackupFile $file) {
  $out = '';
  while ($line = $file->read()) {
    $first2 = substr($line, 0, 2);
    $first3 = substr($line, 0, 2);

    // Ignore single line comments. This function doesn't support multiline
    // comments or inline comments.
    if ($first2 != '--' && ($first2 != '/*' || $first3 == '/*!')) {
      $out .= ' ' . trim($line);
      // If a line ends in ; or */ it is a sql command.
      if (substr($out, strlen($out) - 1, 1) == ';') {
        return trim($out);
      }
    }
  }
  return trim($out);
}