Upsert
class Upsert extends Upsert (View source)
PostgreSQL implementation of \Drupal\Core\Database\Query\Upsert.
Traits
Provides common functionality for INSERT and UPSERT queries.
Properties
| protected Connection | $connection | The connection object on which to run this query. |
from Query |
| protected string | $connectionTarget | The target of the connection object. |
from Query |
| protected string | $connectionKey | The key of the connection object. |
from Query |
| protected array | $queryOptions | The query options to pass on to the connection object. |
from Query |
| protected string | $uniqueIdentifier | A unique identifier for this query object. |
from Query |
| protected int | $nextPlaceholder | The placeholder counter. |
from Query |
| protected array | $comments | An array of comments that can be prepended to a query. |
from Query |
| protected string | $table | The table on which to insert. |
from InsertTrait |
| protected array | $insertFields | An array of fields on which to insert. |
from InsertTrait |
| protected array | $defaultFields | An array of fields that should be set to their database-defined defaults. |
from InsertTrait |
| protected array | $insertValues | A nested array of values to insert. |
from InsertTrait |
| protected string | $key | The unique or primary key of the table. |
from Upsert |
Methods
Constructs an Upsert object.
Executes the UPSERT operation.
Implements PHP magic __toString method to convert the query to a string.
Adds a set of field->value pairs to be inserted.
Adds another set of values to the query to be inserted.
Specifies fields for which the database defaults should be used.
Returns the query placeholders for values that will be inserted.
Details
in
Upsert at line 37
__construct(Connection $connection, string $table, array $options = [])
Constructs an Upsert object.
in
Query at line 86
__sleep()
Implements the magic __sleep function to disconnect from the database.
in
Query at line 95
__wakeup()
Implements the magic __wakeup function to reconnect to the database.
in
Query at line 102
__clone()
Implements the magic __clone function.
StatementInterface|null
execute()
Executes the UPSERT operation.
string
__toString()
Implements PHP magic __toString method to convert the query to a string.
The toString operation is how we compile a query object to a prepared statement.
in
Query at line 128
uniqueIdentifier()
Returns a unique identifier for this object.
in
Query at line 138
The
nextPlaceholder()
Gets the next placeholder value for this query object.
in
Query at line 158
$this
comment($comment)
Adds a comment to the query.
By adding a comment to a query, you can more easily find it in your query log or the list of active queries on an SQL server. This allows for easier debugging and allows you to more easily find where a query with a performance problem is being generated.
The comment string will be sanitized to remove * / and other characters that may terminate the string early so as to avoid SQL injection attacks.
in
Query at line 178
array
getComments()
Returns a reference to the comments array for the query.
Because this method returns by reference, alter hooks may edit the comments array directly to make their changes. If just adding comments, however, the use of comment() is preferred.
Note that this method must be called by reference as well:
in
Query at line 188
Connection
getConnection()
Gets the database connection to be used for the query.
$this
fields(array $fields, array $values = [])
Adds a set of field->value pairs to be inserted.
This method may only be called once. Calling it a second time will be ignored. To queue up multiple sets of values to be inserted at once, use the values() method.
$this
values(array $values)
Adds another set of values to the query to be inserted.
If $values is a numeric-keyed array, it will be assumed to be in the same order as the original fields() call. If it is associative, it may be in any order as long as the keys of the array match the names of the fields.
$this
useDefaults(array $fields)
Specifies fields for which the database defaults should be used.
If you want to force a given field to use the database-defined default, not NULL or undefined, use this method to instruct the database to use default values explicitly. In most cases this will not be necessary unless you are inserting a row that is all default values, as you cannot specify no values in an INSERT query.
Specifying a field both in fields() and in useDefaults() is an error and will not execute.
protected array
getInsertPlaceholderFragment(array $nested_insert_values, array $default_fields)
Returns the query placeholders for values that will be inserted.
count()
{@inheritdoc}
in
Upsert at line 51
$this
key(string $field)
Sets the unique / primary key field to be used as condition for this query.
in
Upsert at line 67
protected bool
preExecute()
Preprocesses and validates the query.