You are here

protected function InsertTrait::getInsertPlaceholderFragment in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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.
NativeUpsert::__toString in core/lib/Drupal/Core/Database/Driver/pgsql/NativeUpsert.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/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 156
Contains \Drupal\Core\Database\Query\InsertTrait.

Class

InsertTrait
Provides common functionality for INSERT and UPSERT queries.

Namespace

Drupal\Core\Database\Query

Code

protected function getInsertPlaceholderFragment(array $nested_insert_values, array $default_fields) {
  $max_placeholder = 0;
  $values = array();
  if ($nested_insert_values) {
    foreach ($nested_insert_values as $insert_values) {
      $placeholders = array();

      // 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;
}