You are here

public function MigrateSourceMSSQL::performRewind in Migrate 6.2

Same name and namespace in other branches
  1. 7.2 plugins/sources/sqlsrv.inc \MigrateSourceMSSQL::performRewind()

Implementation of MigrateSource::performRewind().

File

plugins/sources/mssql.inc, line 141
Define a MigrateSource for importing from Microsoft SQL Server databases.

Class

MigrateSourceMSSQL
Implementation of MigrateSource, to handle imports from remote MS SQL Server db servers.

Code

public function performRewind() {

  /*
   * Replace :criteria placeholder with idlist or highwater clauses. We
   * considered supporting both but it is not worth the complexity. Run twice
   * instead.
   */
  if (!empty($this->idList)) {
    $keys = array();
    foreach ($this->activeMap
      ->getSourceKey() as $field_name => $field_schema) {

      // Allow caller to provide an alias to table containing the primary key.
      if (!empty($field_schema['alias'])) {
        $field_name = $field_schema['alias'] . '.' . $field_name;
      }
      $keys[] = $field_name;
    }

    // TODO: Sanitize. not critical as this is admin supplied data in drush.
    $this->query = str_replace(':criteria', $keys[0] . ' IN (' . implode(',', $this->idList) . ')', $this->query);
  }
  else {
    if (isset($this->highwaterField['name']) && ($highwater = $this->activeMigration
      ->getHighwater())) {
      if (empty($this->highwaterField['alias'])) {
        $highwater_name = $this->highwaterField['name'];
      }
      else {
        $highwater_name = $this->highwaterField['alias'] . '.' . $this->highwaterField['name'];
      }
      $this->query = str_replace(':criteria', "{$highwater_name} > '{$highwater}'", $this->query);
    }
    else {

      // No idlist or highwater. Replace :criteria placeholder with harmless WHERE
      // clause instead of empty since we don't know if an AND follows.
      $this->query = str_replace(':criteria', '1=1', $this->query);
    }
  }
  migrate_instrument_start('mssql_query');
  $this
    ->connect();
  $this->result = mssql_query($this->query, $this->connection, $this->batchSize);
  migrate_instrument_stop('mssql_query');
}