3 namespace Drupal\Core\Database\Driver\sqlite;
5 use Drupal\Core\Database\Query\Insert as QueryInsert;
8 * SQLite implementation of \Drupal\Core\Database\Query\Insert.
10 * We ignore all the default fields and use the clever SQLite syntax:
11 * INSERT INTO table DEFAULT VALUES
12 * for degenerated "default only" queries.
14 class Insert extends QueryInsert {
16 public function execute() {
17 if (!$this->preExecute()) {
20 if (count($this->insertFields) || !empty($this->fromQuery)) {
21 return parent::execute();
24 return $this->connection->query('INSERT INTO {' . $this->table . '} DEFAULT VALUES', [], $this->queryOptions);
28 public function __toString() {
29 // Create a sanitized comment string to prepend to the query.
30 $comments = $this->connection->makeComment($this->comments);
32 // Produce as many generic placeholders as necessary.
34 if (!empty($this->insertFields)) {
35 $placeholders = array_fill(0, count($this->insertFields), '?');
38 // If we're selecting from a SelectQuery, finish building the query and
39 // pass it back, as any remaining options are irrelevant.
40 if (!empty($this->fromQuery)) {
41 $insert_fields_string = $this->insertFields ? ' (' . implode(', ', $this->insertFields) . ') ' : ' ';
42 return $comments . 'INSERT INTO {' . $this->table . '}' . $insert_fields_string . $this->fromQuery;
45 return $comments . 'INSERT INTO {' . $this->table . '} (' . implode(', ', $this->insertFields) . ') VALUES (' . implode(', ', $placeholders) . ')';