3 namespace Drupal\Core\Database\Driver\pgsql;
5 use Drupal\Core\Database\Database;
6 use Drupal\Core\Database\Query\Update as QueryUpdate;
7 use Drupal\Core\Database\Query\SelectInterface;
10 * PostgreSQL implementation of \Drupal\Core\Database\Query\Update.
12 class Update extends QueryUpdate {
14 public function execute() {
19 // Because we filter $fields the same way here and in __toString(), the
20 // placeholders will all match up properly.
21 $stmt = $this->connection->prepareQuery((string) $this);
23 // Fetch the list of blobs and sequences used on that table.
24 $table_information = $this->connection->schema()->queryTableInformation($this->table);
26 // Expressions take priority over literal fields, so we process those first
27 // and remove any literal fields that conflict.
28 $fields = $this->fields;
29 foreach ($this->expressionFields as $field => $data) {
30 if (!empty($data['arguments'])) {
31 foreach ($data['arguments'] as $placeholder => $argument) {
32 // We assume that an expression will never happen on a BLOB field,
33 // which is a fairly safe assumption to make since in most cases
34 // it would be an invalid query anyway.
35 $stmt->bindParam($placeholder, $data['arguments'][$placeholder]);
38 if ($data['expression'] instanceof SelectInterface) {
39 $data['expression']->compile($this->connection, $this);
40 $select_query_arguments = $data['expression']->arguments();
41 foreach ($select_query_arguments as $placeholder => $argument) {
42 $stmt->bindParam($placeholder, $select_query_arguments[$placeholder]);
45 unset($fields[$field]);
48 foreach ($fields as $field => $value) {
49 $placeholder = ':db_update_placeholder_' . ($max_placeholder++);
51 if (isset($table_information->blob_fields[$field])) {
52 $blobs[$blob_count] = fopen('php://memory', 'a');
53 fwrite($blobs[$blob_count], $value);
54 rewind($blobs[$blob_count]);
55 $stmt->bindParam($placeholder, $blobs[$blob_count], \PDO::PARAM_LOB);
59 $stmt->bindParam($placeholder, $fields[$field]);
63 if (count($this->condition)) {
64 $this->condition->compile($this->connection, $this);
66 $arguments = $this->condition->arguments();
67 foreach ($arguments as $placeholder => $value) {
68 $stmt->bindParam($placeholder, $arguments[$placeholder]);
72 $options = $this->queryOptions;
73 $options['already_prepared'] = TRUE;
74 $options['return'] = Database::RETURN_AFFECTED;
76 $this->connection->addSavepoint();
78 $result = $this->connection->query($stmt, [], $options);
79 $this->connection->releaseSavepoint();
82 catch (\Exception $e) {
83 $this->connection->rollbackSavepoint();