You are here

protected function MySQLiSource::_readSQLCommand in Backup and Migrate 8.4

Read a multiline sql command from a file.

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

Parameters

\BackupMigrate\Core\File\BackupFileReadableInterface $file:

Return value

string

2 calls to MySQLiSource::_readSQLCommand()
DrupalMySQLiSource::importFromFile in src/Source/DrupalMySQLiSource.php
Import to this source from the given backup file. This is the main restore function for this source.
MySQLiSource::importFromFile in lib/backup_migrate_core/src/Source/MySQLiSource.php
Import to this source from the given backup file. This is the main restore function for this source.

File

lib/backup_migrate_core/src/Source/MySQLiSource.php, line 265

Class

MySQLiSource
Class MySQLiSource.

Namespace

BackupMigrate\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);
}