__toString

  1. drupal
    1. drupal7
Versionen
drupal7 public MergeQuery_mysql::__toString()

Verwandte Themen

Code

includes/database/mysql/query.inc, line 143

<?php
public function __toString() {

  // Set defaults.
  if ($this->updateFields) {
    $update_fields = $this->updateFields;
  }
  else {
    $update_fields = $this->insertFields;
    // If there are no exclude fields, this is a no-op.
    foreach ($this->excludeFields as $exclude_field) {
      unset($update_fields[$exclude_field]);
    }
  }

  // If the merge query has no fields to update, add the first key as an
  // update field so the query will not fail if a duplicate key is found.
  if (!$update_fields && !$this->expressionFields) {
    $update_fields = array_slice($this->keyFields, 0, 1, TRUE);
  }

  $insert_fields = $this->insertFields + $this->keyFields;

  $query = "INSERT INTO {" . $this->table . '} (' . implode(', ', array_keys($insert_fields)) . ') VALUES ';

  $max_placeholder = 0;
  $values = array();
  // We don't need the $field, but this is a convenient way to count.
  foreach ($insert_fields as $field) {
    $values[] = ':db_insert_placeholder_' . $max_placeholder++;
  }

  $query .= '(' . implode(', ', $values) . ') ON DUPLICATE KEY UPDATE ';

  // Expressions take priority over literal fields, so we process those first
  // and remove any literal fields that conflict.
  $max_placeholder = 0;
  $update = array();
  foreach ($this->expressionFields as $field => $data) {
    $update[] = $field . '=' . $data['expression'];
    unset($update_fields[$field]);
  }

  // Build update fields clauses based on caller supplied list, or derived
  // from insert supplied values using the VALUES(col_name) function.
  foreach ($update_fields as $field => $value) {
    if ($this->updateFields) {
      $update[] = ($field . '=:db_update_placeholder_' . $max_placeholder++);
    }
    else {
      $update[] = ($field . '=VALUES(' . $field . ')');
    }
  }

  $query .= implode(', ', $update);

  return $query;
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen