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;
}
doc_Drupal
2016-10-29 09:20:46
Comments
Leave a Comment

Please login to continue.