Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Core / Database / Driver / sqlite / Insert.php
1 <?php
2
3 namespace Drupal\Core\Database\Driver\sqlite;
4
5 use Drupal\Core\Database\Query\Insert as QueryInsert;
6
7 /**
8  * SQLite implementation of \Drupal\Core\Database\Query\Insert.
9  *
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.
13  */
14 class Insert extends QueryInsert {
15
16   public function execute() {
17     if (!$this->preExecute()) {
18       return NULL;
19     }
20     if (count($this->insertFields) || !empty($this->fromQuery)) {
21       return parent::execute();
22     }
23     else {
24       return $this->connection->query('INSERT INTO {' . $this->table . '} DEFAULT VALUES', [], $this->queryOptions);
25     }
26   }
27
28   public function __toString() {
29     // Create a sanitized comment string to prepend to the query.
30     $comments = $this->connection->makeComment($this->comments);
31
32     // Produce as many generic placeholders as necessary.
33     $placeholders = [];
34     if (!empty($this->insertFields)) {
35       $placeholders = array_fill(0, count($this->insertFields), '?');
36     }
37
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;
43     }
44
45     return $comments . 'INSERT INTO {' . $this->table . '} (' . implode(', ', $this->insertFields) . ') VALUES (' . implode(', ', $placeholders) . ')';
46   }
47
48 }