| Versionen | |
|---|---|
| drupal7 | public MergeQuery_mysql::execute() |
includes/
<?php
public function execute() {
// A merge query without any key field is invalid.
if (count($this->keyFields) == 0) {
throw new InvalidMergeQueryException("You need to specify key fields before executing a merge query");
}
// Set defaults.
if ($this->updateFields) {
$update_fields = $this->updateFields;
}
else {
// When update fields are derived from insert fields, we don't need
// placeholders since we can tell MySQL to reuse insert supplied
// values using the VALUES(col_name) function.
$update_fields = array();
}
$insert_fields = $this->insertFields + $this->keyFields;
$max_placeholder = 0;
$values = array();
// We assume that the order here is the same as in __toString(). If that's
// not the case, then we have serious problems.
foreach ($insert_fields as $value) {
$values[':db_insert_placeholder_' . $max_placeholder++] = $value;
}
// Expressions take priority over literal fields, so we process those first
// and remove any literal fields that conflict.
foreach ($this->expressionFields as $field => $data) {
if (!empty($data['arguments'])) {
$values += $data['arguments'];
}
unset($update_fields[$field]);
}
// Because we filter $fields the same way here and in __toString(), the
// placeholders will all match up properly.
$max_placeholder = 0;
foreach ($update_fields as $field => $value) {
$values[':db_update_placeholder_' . ($max_placeholder++)] = $value;
}
$last_insert_id = $this->connection->query((string) $this, $values, $this->queryOptions);
return $last_insert_id;
}
?>
Kommentare
Kommentar hinzufügen