public function InsertQuery::execute

cis7 query.inc public InsertQuery::execute()
cle7 query.inc public InsertQuery::execute()
elmsmedia7 query.inc public InsertQuery::execute()
icor7 query.inc public InsertQuery::execute()
meedjum_blog7 query.inc public InsertQuery::execute()
mooc7 query.inc public InsertQuery::execute()

Executes the insert query.

Return value

The last insert ID of the query, if one exists. If the query was given multiple sets of values to insert, the return value is undefined. If no fields are specified, this method will do nothing and return NULL. That makes it safe to use in multi-insert loops.

Overrides Query::execute

3 methods override InsertQuery::execute()
InsertQuery_mysql::execute in includes/database/mysql/query.inc
Executes the insert query.
InsertQuery_pgsql::execute in includes/database/pgsql/query.inc
Executes the insert query.
InsertQuery_sqlite::execute in includes/database/sqlite/query.inc
Executes the insert query.

File

includes/database/query.inc, line 619
Non-specific Database query code. Used by all engines.

Class

InsertQuery
General class for an abstracted INSERT query.

Code

public function execute() {
  // If validation fails, simply return NULL. Note that validation routines
  // in preExecute() may throw exceptions instead.
  if (!$this->preExecute()) {
    return NULL;
  }

  // If we're selecting from a SelectQuery, finish building the query and
  // pass it back, as any remaining options are irrelevant.
  if (!empty($this->fromQuery)) {
    $sql = (string) $this;
    // The SelectQuery may contain arguments, load and pass them through.
    return $this->connection->query($sql, $this->fromQuery->getArguments(), $this->queryOptions);
  }

  $last_insert_id = 0;

  // Each insert happens in its own query in the degenerate case. However,
  // we wrap it in a transaction so that it is atomic where possible. On many
  // databases, such as SQLite, this is also a notable performance boost.
  $transaction = $this->connection->startTransaction();

  try {
    $sql = (string) $this;
    foreach ($this->insertValues as $insert_values) {
      $last_insert_id = $this->connection->query($sql, $insert_values, $this->queryOptions);
    }
  }
  catch (Exception $e) {
    // One of the INSERTs failed, rollback the whole batch.
    $transaction->rollback();
    // Rethrow the exception for the calling code.
    throw $e;
  }

  // Re-initialize the values array so that we can re-use this query.
  $this->insertValues = array();

  // Transaction commits here where $transaction looses scope.

  return $last_insert_id;
}
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.