public function MergeQuery::execute

cis7 query.inc public MergeQuery::execute()
cle7 query.inc public MergeQuery::execute()
elmsmedia7 query.inc public MergeQuery::execute()
icor7 query.inc public MergeQuery::execute()
meedjum_blog7 query.inc public MergeQuery::execute()
mooc7 query.inc public MergeQuery::execute()

Runs the query against the database.

Overrides Query::execute

File

includes/database/query.inc, line 1608
Non-specific Database query code. Used by all engines.

Class

MergeQuery
General class for an abstracted MERGE query operation.

Code

public function execute() {
  if (!count($this->condition)) {
    throw new InvalidMergeQueryException(t('Invalid merge query: no conditions'));
  }
  $select = $this->connection->select($this->conditionTable)->condition($this->condition);
  $select->addExpression('1');
  if (!$select->execute()->fetchField()) {
    try {
      $insert = $this->connection->insert($this->table)->fields($this->insertFields);
      if ($this->defaultFields) {
        $insert->useDefaults($this->defaultFields);
      }
      $insert->execute();
      return self::STATUS_INSERT;
    }
    catch (Exception $e) {
      // The insert query failed, maybe it's because a racing insert query
      // beat us in inserting the same row. Retry the select query, if it
      // returns a row, ignore the error and continue with the update
      // query below.
      if (!$select->execute()->fetchField()) {
        throw $e;
      }
    }
  }
  if ($this->needsUpdate) {
    $update = $this->connection->update($this->table)->fields($this->updateFields)->condition($this->condition);
    if ($this->expressionFields) {
      foreach ($this->expressionFields as $field => $data) {
        $update->expression($field, $data['expression'], $data['arguments']);
      }
    }
    $update->execute();
    return self::STATUS_UPDATE;
  }
}
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.