public function Upsert::execute in Drupal 9
Same name in this branch
- 9 core/lib/Drupal/Core/Database/Query/Upsert.php \Drupal\Core\Database\Query\Upsert::execute()
- 9 core/lib/Drupal/Core/Database/Driver/pgsql/Upsert.php \Drupal\Core\Database\Driver\pgsql\Upsert::execute()
- 9 core/tests/fixtures/database_drivers/module/corefake/src/Driver/Database/corefakeWithAllCustomClasses/Upsert.php \Drupal\corefake\Driver\Database\corefakeWithAllCustomClasses\Upsert::execute()
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Database/Query/Upsert.php \Drupal\Core\Database\Query\Upsert::execute()
- 10 core/lib/Drupal/Core/Database/Query/Upsert.php \Drupal\Core\Database\Query\Upsert::execute()
Executes the UPSERT operation.
Return value
int An integer indicating the number of rows affected by the operation. Do not rely on this value as a precise indication of the actual rows affected: different database engines return different values.
Overrides Query::execute
2 methods override Upsert::execute()
- Upsert::execute in core/
lib/ Drupal/ Core/ Database/ Driver/ pgsql/ Upsert.php - Executes the UPSERT operation.
- Upsert::execute in core/
tests/ fixtures/ database_drivers/ module/ corefake/ src/ Driver/ Database/ corefakeWithAllCustomClasses/ Upsert.php - Executes the UPSERT operation.
File
- core/
lib/ Drupal/ Core/ Database/ Query/ Upsert.php, line 98
Class
- Upsert
- General class for an abstracted "Upsert" (UPDATE or INSERT) query operation.
Namespace
Drupal\Core\Database\QueryCode
public function execute() {
if (!$this
->preExecute()) {
return NULL;
}
$max_placeholder = 0;
$values = [];
foreach ($this->insertValues as $insert_values) {
foreach ($insert_values as $value) {
$values[':db_insert_placeholder_' . $max_placeholder++] = $value;
}
}
$stmt = $this->connection
->prepareStatement((string) $this, $this->queryOptions, TRUE);
try {
$stmt
->execute($values, $this->queryOptions);
$affected_rows = $stmt
->rowCount();
} catch (\Exception $e) {
$this->connection
->exceptionHandler()
->handleExecutionException($e, $stmt, $values, $this->queryOptions);
}
// Re-initialize the values array so that we can re-use this query.
$this->insertValues = [];
return $affected_rows;
}