SQLite specific implementation of InsertQuery.
We ignore all the default fields and use the clever SQLite syntax: INSERT INTO table DEFAULT VALUES for degenerated "default only" queries.
Hierarchy
- Query implements QueryPlaceholderInterface
Properties
| Name | Description |
|---|---|
| InsertQuery::$defaultFields | An array of fields that should be set to their database-defined defaults. |
| InsertQuery::$fromQuery | A SelectQuery object to fetch the rows that should be inserted. |
| InsertQuery::$insertFields | An array of fields on which to insert. |
| InsertQuery::$insertValues | A nested array of values to insert. |
| InsertQuery::$table | The table on which to insert. |
| Query::$comments | An array of comments that can be prepended to a query. |
| Query::$connection | The connection object on which to run this query. |
| Query::$connectionKey | The key of the connection object. |
| Query::$connectionTarget | The target of the connection object. |
| Query::$nextPlaceholder | The placeholder counter. |
| Query::$queryOptions | The query options to pass on to the connection object. |
| Query::$uniqueIdentifier | A unique identifier for this query object. |
Functions & methods
| Name | Description |
|---|---|
| InsertQuery::fields | Adds a set of field->value pairs to be inserted. |
| InsertQuery::from | Sets the fromQuery on this InsertQuery object. |
| InsertQuery::preExecute | Preprocesses and validates the query. |
| InsertQuery::useDefaults | Specifies fields for which the database defaults should be used. |
| InsertQuery::values | Adds another set of values to the query to be inserted. |
| InsertQuery::__construct | Constructs an InsertQuery object. Overrides Query::__construct |
| InsertQuery_sqlite::execute | Executes the insert query. Overrides InsertQuery::execute |
| InsertQuery_sqlite::__toString | Implements PHP magic __toString method to convert the query to a string. Overrides InsertQuery::__toString |
| Query::comment | Adds a comment to the query. |
| Query::getComments | Returns a reference to the comments array for the query. |
| Query::nextPlaceholder | Gets the next placeholder value for this query object. Overrides QueryPlaceholderInterface::nextPlaceholder |
| Query::uniqueIdentifier | Returns a unique identifier for this object. Overrides QueryPlaceholderInterface::uniqueIdentifier |
| Query::__clone | Implements the magic __clone function. |
| Query::__sleep | Implements the magic __sleep function to disconnect from the database. |
| Query::__wakeup | Implements the magic __wakeup function to reconnect to the database. |
File
- includes/
database/ sqlite/ query.inc, line 20 - Query code for SQLite embedded database engine.
View source
class InsertQuery_sqlite extends InsertQuery {
public function execute() {
if (!$this->preExecute()) {
return NULL;
}
if (count($this->insertFields)) {
return parent::execute();
}
else {
return $this->connection->query('INSERT INTO {' . $this->table . '} DEFAULT VALUES', array(), $this->queryOptions);
}
}
public function __toString() {
// Create a sanitized comment string to prepend to the query.
$comments = $this->connection->makeComment($this->comments);
// Produce as many generic placeholders as necessary.
$placeholders = array_fill(0, count($this->insertFields), '?');
// If we're selecting from a SelectQuery, finish building the query and
// pass it back, as any remaining options are irrelevant.
if (!empty($this->fromQuery)) {
return $comments . 'INSERT INTO {' . $this->table . '} (' . implode(', ', $this->insertFields) . ') ' . $this->fromQuery;
}
return $comments . 'INSERT INTO {' . $this->table . '} (' . implode(', ', $this->insertFields) . ') VALUES (' . implode(', ', $placeholders) . ')';
}
}