function Merge::execute

Same name in this branch
  1. main core/lib/Drupal/Core/Database/Query/Merge.php \Drupal\Core\Database\Query\Merge::execute()
Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Database/Query/Merge.php \Drupal\Core\Database\Query\Merge::execute()
  2. 10 core/lib/Drupal/Core/Database/Query/Merge.php \Drupal\Core\Database\Query\Merge::execute()
  3. 9 core/lib/Drupal/Core/Database/Query/Merge.php \Drupal\Core\Database\Query\Merge::execute()
  4. 8.9.x core/lib/Drupal/Core/Database/Query/Merge.php \Drupal\Core\Database\Query\Merge::execute()

File

core/modules/pgsql/src/Driver/Database/pgsql/Merge.php, line 39

Class

Merge
PostgreSQL implementation of \Drupal\Core\Database\Query\Merge.

Namespace

Drupal\pgsql\Driver\Database\pgsql

Code

public function execute() {
  if (!count($this->condition)) {
    throw new InvalidMergeQueryException('Invalid merge query: no conditions');
  }
  if (!$this->isNativeMerge()) {
    return parent::execute();
  }
  // Fetch the list of blobs and sequences used on that table.
  $table_information = $this->connection
    ->schema()
    ->queryTableInformation($this->table);
  // Inserting values into serial fields requires synchronizing the
  // sequence afterwards, which the generic insert path takes care of.
  if (!empty($table_information->serial_fields) && array_intersect($table_information->serial_fields, array_keys($this->insertFields))) {
    return parent::execute();
  }
  try {
    return $this->executeNativeMerge($table_information);
  } catch (IntegrityConstraintViolationException) {
    // The merge query failed. Maybe it's because a racing insert query
    // beat us in inserting the same row. Retry once: the racing row will
    // now be matched and updated instead.
    return $this->executeNativeMerge($table_information);
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.