/** * Executes the UPDATE query. * * @return * The number of rows matched by the update query. This includes rows that * actually didn't have to be updated because the values didn't change. */ public function execute() { // Expressions take priority over literal fields, so we process those first // and remove any literal fields that conflict. $fields = $this->fields; $update_values = array(); foreach ($this->expressionFields as $field => $data) { if (!empty($data['arguments'])) { $update_values += $data['arguments']; } if ($data['expression'] instanceof SelectInterface) { $data['expression']->compile($this->connection, $this); $update_values += $data['expression']->arguments(); } unset($fields[$field]); } // Because we filter $fields the same way here and in __toString(), the // placeholders will all match up properly. $max_placeholder = 0; foreach ($fields as $value) { $update_values[':db_update_placeholder_' . $max_placeholder++] = $value; } if (count($this->condition)) { $this->condition->compile($this->connection, $this); $update_values = array_merge($update_values, $this->condition->arguments()); } return $this->connection->query((string) $this, $update_values, $this->queryOptions); }
/** * Executes the DELETE query. * * @return * The return value is dependent on the database connection. */ public function execute() { $values = array(); if (count($this->condition)) { $this->condition->compile($this->connection, $this); $values = $this->condition->arguments(); } return $this->connection->query((string) $this, $values, $this->queryOptions); }
/** * @covers ::compile * * @dataProvider dataProviderTestCompileWithKnownOperators() * * @param string $expected * The expected generated SQL condition. * @param string $field * The field to pass into the condition() method. * @param mixed $value * The value to pass into the condition() method. * @param string $operator * The operator to pass into the condition() method. * @param mixed $expected_arguments * (optional) The expected set arguments. */ public function testCompileWithKnownOperators($expected, $field, $value, $operator, $expected_arguments = NULL) { $connection = $this->prophesize(Connection::class); $connection->escapeField(Argument::any())->will(function ($args) { return preg_replace('/[^A-Za-z0-9_.]+/', '', $args[0]); }); $connection->mapConditionOperator(Argument::any())->willReturn(NULL); $connection = $connection->reveal(); $query_placeholder = $this->prophesize(PlaceholderInterface::class); $counter = 0; $query_placeholder->nextPlaceholder()->will(function () use(&$counter) { return $counter++; }); $query_placeholder->uniqueIdentifier()->willReturn(4); $query_placeholder = $query_placeholder->reveal(); $condition = new Condition('AND'); $condition->condition($field, $value, $operator); $condition->compile($connection, $query_placeholder); $this->assertEquals($expected, $condition->__toString()); if (isset($expected_arguments)) { $this->assertEquals($expected_arguments, $condition->arguments()); } }
/** * Implements Drupal\Core\Database\Query\ConditionInterface::arguments(). */ public function arguments() { return $this->condition->arguments(); }
/** * Gets a list of all values to insert into the HAVING clause. * * @return array * An associative array of placeholders and values. */ public function havingArguments() { return $this->having->arguments(); }