You are here

protected function MySQLiSource::_readSqlCommand in Backup and Migrate 5.0.x

Read a multiline sql command from a file.

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

Parameters

\Drupal\backup_migrate\Core\File\BackupFileReadableInterface $file:

Return value

string

2 calls to MySQLiSource::_readSqlCommand()
DrupalMySQLiSource::importFromFile in src/Drupal/Source/DrupalMySQLiSource.php
Import to this source from the given backup file.
MySQLiSource::importFromFile in src/Core/Source/MySQLiSource.php
Import to this source from the given backup file.

File

src/Core/Source/MySQLiSource.php, line 275

Class

MySQLiSource
@package Drupal\backup_migrate\Core\Source

Namespace

Drupal\backup_migrate\Core\Source

Code

protected function _readSqlCommand(BackupFileReadableInterface $file) {
  $out = '';
  while ($line = $file
    ->readLine()) {
    $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);
}