W3cubDocs

/Drupal 8

protected function InsertTrait::getInsertPlaceholderFragment

protected InsertTrait::getInsertPlaceholderFragment(array $nested_insert_values, array $default_fields)

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.

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

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Database!Query!InsertTrait.php/function/InsertTrait::getInsertPlaceholderFragment/8.1.x