Same filename in this branch
- 10 core/lib/Drupal/Core/Database/Query/Insert.php
- 10 core/lib/Drupal/Core/Database/Driver/mysql/Insert.php
- 10 core/lib/Drupal/Core/Database/Driver/pgsql/Insert.php
- 10 core/lib/Drupal/Core/Database/Driver/sqlite/Insert.php
- 10 core/modules/mysql/src/Driver/Database/mysql/Insert.php
- 10 core/modules/pgsql/src/Driver/Database/pgsql/Insert.php
- 10 core/modules/sqlite/src/Driver/Database/sqlite/Insert.php
Same filename and directory in other branches
- 9 core/modules/sqlite/src/Driver/Database/sqlite/Insert.php
Namespace
Drupal\sqlite\Driver\Database\sqlite
File
core/modules/sqlite/src/Driver/Database/sqlite/Insert.php
View source
<?php
namespace Drupal\sqlite\Driver\Database\sqlite;
use Drupal\Core\Database\DatabaseExceptionWrapper;
use Drupal\Core\Database\Query\Insert as QueryInsert;
class Insert extends QueryInsert {
public function __construct(Connection $connection, string $table, array $options = []) {
parent::__construct($connection, $table, $options);
unset($this->queryOptions['return']);
}
public function execute() {
if (!$this
->preExecute()) {
return NULL;
}
if (!empty($this->fromQuery)) {
return $this->connection
->query((string) $this, $this->fromQuery
->getArguments(), $this->queryOptions);
}
if (count($this->insertFields)) {
$stmt = $this->connection
->prepareStatement((string) $this, $this->queryOptions);
if (count($this->insertValues) === 1) {
$insert_values = $this->insertValues[0];
try {
$stmt
->execute($insert_values, $this->queryOptions);
} catch (\Exception $e) {
$this->connection
->exceptionHandler()
->handleExecutionException($e, $stmt, $insert_values, $this->queryOptions);
}
}
else {
try {
$transaction = $this->connection
->startTransaction();
} catch (\PDOException $e) {
throw new DatabaseExceptionWrapper($e
->getMessage(), 0, $e);
}
foreach ($this->insertValues as $insert_values) {
try {
$stmt
->execute($insert_values, $this->queryOptions);
} catch (\Exception $e) {
$transaction
->rollBack();
$this->connection
->exceptionHandler()
->handleExecutionException($e, $stmt, $insert_values, $this->queryOptions);
}
}
}
$this->insertValues = [];
}
else {
$stmt = $this->connection
->prepareStatement("INSERT INTO {{$this->table}} DEFAULT VALUES", $this->queryOptions);
try {
$stmt
->execute(NULL, $this->queryOptions);
} catch (\Exception $e) {
$this->connection
->exceptionHandler()
->handleExecutionException($e, $stmt, [], $this->queryOptions);
}
}
return $this->connection
->lastInsertId();
}
public function __toString() {
$comments = $this->connection
->makeComment($this->comments);
$placeholders = [];
if (!empty($this->insertFields)) {
$placeholders = array_fill(0, count($this->insertFields), '?');
}
$insert_fields = array_map(function ($field) {
return $this->connection
->escapeField($field);
}, $this->insertFields);
if (!empty($this->fromQuery)) {
$insert_fields_string = $insert_fields ? ' (' . implode(', ', $insert_fields) . ') ' : ' ';
return $comments . 'INSERT INTO {' . $this->table . '}' . $insert_fields_string . $this->fromQuery;
}
return $comments . 'INSERT INTO {' . $this->table . '} (' . implode(', ', $insert_fields) . ') VALUES (' . implode(', ', $placeholders) . ')';
}
}
Classes