class InsertQuery_sqlite in Drupal 7
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
- class \Query implements QueryPlaceholderInterface
- class \InsertQuery
- class \InsertQuery_sqlite
- class \InsertQuery
Expanded class hierarchy of InsertQuery_sqlite
Related topics
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) || !empty($this->fromQuery)) {
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();
if (!empty($this->insertFields)) {
$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)) {
$insert_fields_string = $this->insertFields ? ' (' . implode(', ', $this->insertFields) . ') ' : ' ';
return $comments . 'INSERT INTO {' . $this->table . '}' . $insert_fields_string . $this->fromQuery;
}
return $comments . 'INSERT INTO {' . $this->table . '} (' . implode(', ', $this->insertFields) . ') VALUES (' . implode(', ', $placeholders) . ')';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
InsertQuery:: |
protected | property | An array of fields that should be set to their database-defined defaults. | |
InsertQuery:: |
protected | property | A SelectQuery object to fetch the rows that should be inserted. | |
InsertQuery:: |
protected | property | An array of fields on which to insert. | |
InsertQuery:: |
protected | property | A nested array of values to insert. | |
InsertQuery:: |
protected | property | The table on which to insert. | |
InsertQuery:: |
public | function | Adds a set of field->value pairs to be inserted. | |
InsertQuery:: |
public | function | Sets the fromQuery on this InsertQuery object. | |
InsertQuery:: |
public | function | Preprocesses and validates the query. | |
InsertQuery:: |
public | function | Specifies fields for which the database defaults should be used. | |
InsertQuery:: |
public | function | Adds another set of values to the query to be inserted. | |
InsertQuery:: |
public | function |
Constructs an InsertQuery object. Overrides Query:: |
|
InsertQuery_sqlite:: |
public | function |
Executes the insert query. Overrides InsertQuery:: |
|
InsertQuery_sqlite:: |
public | function |
Implements PHP magic __toString method to convert the query to a string. Overrides InsertQuery:: |
|
Query:: |
protected | property | An array of comments that can be prepended to a query. | |
Query:: |
protected | property | The connection object on which to run this query. | |
Query:: |
protected | property | The key of the connection object. | |
Query:: |
protected | property | The target of the connection object. | |
Query:: |
protected | property | The placeholder counter. | |
Query:: |
protected | property | The query options to pass on to the connection object. | |
Query:: |
protected | property | A unique identifier for this query object. | |
Query:: |
public | function | Adds a comment to the query. | |
Query:: |
public | function | Returns a reference to the comments array for the query. | |
Query:: |
public | function |
Gets the next placeholder value for this query object. Overrides QueryPlaceholderInterface:: |
|
Query:: |
public | function |
Returns a unique identifier for this object. Overrides QueryPlaceholderInterface:: |
|
Query:: |
public | function | Implements the magic __clone function. | 1 |
Query:: |
public | function | Implements the magic __sleep function to disconnect from the database. | |
Query:: |
public | function | Implements the magic __wakeup function to reconnect to the database. |