protected function InsertTrait::getInsertPlaceholderFragment in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Database/Query/InsertTrait.php \Drupal\Core\Database\Query\InsertTrait::getInsertPlaceholderFragment()
- 10 core/lib/Drupal/Core/Database/Query/InsertTrait.php \Drupal\Core\Database\Query\InsertTrait::getInsertPlaceholderFragment()
Returns the query placeholders for values that will be inserted.
Parameters
array $nested_insert_values: A nested array of values to insert.
array $default_fields: An array of fields that should be set to their database-defined defaults.
Return value
array An array of insert placeholders.
5 calls to InsertTrait::getInsertPlaceholderFragment()
- Insert::__toString in core/
lib/ Drupal/ Core/ Database/ Driver/ pgsql/ Insert.php - Implements PHP magic __toString method to convert the query to a string.
- Insert::__toString in core/
lib/ Drupal/ Core/ Database/ Driver/ mysql/ Insert.php - Implements PHP magic __toString method to convert the query to a string.
- Upsert::__toString in core/
lib/ Drupal/ Core/ Database/ Driver/ sqlite/ Upsert.php - Implements PHP magic __toString method to convert the query to a string.
- Upsert::__toString in core/
lib/ Drupal/ Core/ Database/ Driver/ pgsql/ Upsert.php - Implements PHP magic __toString method to convert the query to a string.
- Upsert::__toString in core/
lib/ Drupal/ Core/ Database/ Driver/ mysql/ Upsert.php - Implements PHP magic __toString method to convert the query to a string.
File
- core/
lib/ Drupal/ Core/ Database/ Query/ InsertTrait.php, line 151
Class
- InsertTrait
- Provides common functionality for INSERT and UPSERT queries.
Namespace
Drupal\Core\Database\QueryCode
protected function getInsertPlaceholderFragment(array $nested_insert_values, array $default_fields) {
$max_placeholder = 0;
$values = [];
if ($nested_insert_values) {
foreach ($nested_insert_values as $insert_values) {
$placeholders = [];
// Default fields aren't really placeholders, but this is the most convenient
// way to handle them.
$placeholders = array_pad($placeholders, count($default_fields), 'default');
$new_placeholder = $max_placeholder + count($insert_values);
for ($i = $max_placeholder; $i < $new_placeholder; ++$i) {
$placeholders[] = ':db_insert_placeholder_' . $i;
}
$max_placeholder = $new_placeholder;
$values[] = '(' . implode(', ', $placeholders) . ')';
}
}
else {
// If there are no values, then this is a default-only query. We still need to handle that.
$placeholders = array_fill(0, count($default_fields), 'default');
$values[] = '(' . implode(', ', $placeholders) . ')';
}
return $values;
}