handleExecutionException example

if (count($this->condition)) {
      $this->condition->compile($this->connection, $this);
      $update_values = array_merge($update_values$this->condition->arguments());
    }

    $stmt = $this->connection->prepareStatement((string) $this$this->queryOptions, TRUE);
    try {
      $stmt->execute($update_values$this->queryOptions);
      return $stmt->rowCount();
    }
    catch (\Exception $e) {
      $this->connection->exceptionHandler()->handleExecutionException($e$stmt$update_values$this->queryOptions);
    }
  }

  /** * Implements PHP magic __toString method to convert the query to a string. * * @return string * The prepared statement. */
  public function __toString() {
    // Create a sanitized comment string to prepend to the query.

    else {
      $values = $this->fromQuery->getArguments();
    }

    $stmt = $this->connection->prepareStatement((string) $this$this->queryOptions);
    try {
      $stmt->execute($values$this->queryOptions);
      $last_insert_id = $this->connection->lastInsertId();
    }
    catch (\Exception $e) {
      $this->connection->exceptionHandler()->handleExecutionException($e$stmt$values$this->queryOptions);
    }

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

    return $last_insert_id;
  }

  public function __toString() {
    // Create a sanitized comment string to prepend to the query.     $comments = $this->connection->makeComment($this->comments);

    
    // example, \Drupal\Core\Cache\DatabaseBackend.     $this->connection->addSavepoint();
    try {
      $stmt->execute(NULL, $this->queryOptions);
      if (isset($table_information->serial_fields[0])) {
        $last_insert_id = $stmt->fetchField();
      }
      $this->connection->releaseSavepoint();
    }
    catch (\Exception $e) {
      $this->connection->rollbackSavepoint();
      $this->connection->exceptionHandler()->handleExecutionException($e$stmt[]$this->queryOptions);
    }

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

    return $last_insert_id ?? NULL;
  }

  public function __toString() {
    // Create a sanitized comment string to prepend to the query.     $comments = $this->connection->makeComment($this->comments);

    
    if (count($this->insertFields)) {
      $stmt = $this->connection->prepareStatement((string) $this$this->queryOptions);

      if (count($this->insertValues) === 1) {
        // Inserting a single row does not require a transaction to be atomic,         // and executes faster without a transaction wrapper.         $insert_values = $this->insertValues[0];
        try {
          $stmt->execute($insert_values$this->queryOptions);
        }
        catch (\Exception $e) {
          $this->connection->exceptionHandler()->handleExecutionException($e$stmt$insert_values$this->queryOptions);
        }
      }
      else {
        // Inserting multiple rows requires a transaction to be atomic, and         // executes faster as a single transaction.         try {
          $transaction = $this->connection->startTransaction();
        }
        catch (\PDOException $e) {
          // $this->connection->exceptionHandler()->handleExecutionException()           // requires a $statement argument, so we cannot use that.
    // builder because if a given database breaks here then it can simply     // override nextId. However, this is unlikely as we deal with short strings     // and integers and no known databases require special handling for those     // simple cases. If another transaction wants to write the same row, it will     // wait until this transaction commits.     $stmt = $this->prepareStatement('UPDATE {sequences} SET [value] = GREATEST([value], :existing_id) + 1', [], TRUE);
    $args = [':existing_id' => $existing_id];
    try {
      $stmt->execute($args);
    }
    catch (\Exception $e) {
      $this->exceptionHandler()->handleExecutionException($e$stmt$args[]);
    }
    if ($stmt->rowCount() === 0) {
      $this->query('INSERT INTO {sequences} ([value]) VALUES (:existing_id + 1)', $args);
    }
    // The transaction gets committed when the transaction object gets destroyed     // because it gets out of scope.     return $this->query('SELECT [value] FROM {sequences}')->fetchField();
  }

  /** * {@inheritdoc} */
foreach ($insert_values as $value) {
        $values[':db_insert_placeholder_' . $max_placeholder++] = $value;
      }
    }

    $stmt = $this->connection->prepareStatement((string) $this$this->queryOptions, TRUE);
    try {
      $stmt->execute($values$this->queryOptions);
      $affected_rows = $stmt->rowCount();
    }
    catch (\Exception $e) {
      $this->connection->exceptionHandler()->handleExecutionException($e$stmt$values$this->queryOptions);
    }

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

    return $affected_rows;
  }

}
    // mimic MySQL and SQLite transactions which don't fail if a single query     // fails. This is important for tables that are created on demand. For     // example, \Drupal\Core\Cache\DatabaseBackend.     $this->connection->addSavepoint();
    try {
      $stmt->execute(NULL, $options);
      $this->connection->releaseSavepoint();
      return $stmt->rowCount();
    }
    catch (\Exception $e) {
      $this->connection->rollbackSavepoint();
      $this->connection->exceptionHandler()->handleExecutionException($e$stmt[]$options);
    }
  }

  /** * {@inheritdoc} */
  public function __toString() {
    // Create a sanitized comment string to prepend to the query.     $comments = $this->connection->makeComment($this->comments);

    // Default fields are always placed first for consistency.
return $this->lastInsertId($sequence_name);

        case Database::RETURN_NULL:
          return NULL;

        default:
          throw new \PDOException('Invalid return directive: ' . $options['return']);

      }
    }
    catch (\Exception $e) {
      $this->exceptionHandler()->handleExecutionException($e$stmt$args$options);
    }
  }

  /** * Expands out shorthand placeholders. * * Drupal supports an alternate syntax for doing arrays of values. We * therefore need to expand them out into a full, executable query string. * * @param string $query * The query string to modify. * @param array $args * The arguments for the query. * * @return bool * TRUE if the query was modified, FALSE otherwise. * * @throws \InvalidArgumentException * This exception is thrown when: * - A placeholder that ends in [] is supplied, and the supplied value is * not an array. * - A placeholder that does not end in [] is supplied, and the supplied * value is an array. */

  public function execute() {
    $stmt = $this->connection->prepareStatement((string) $this$this->queryOptions, TRUE);
    try {
      $stmt->execute([]$this->queryOptions);
      return $stmt->rowCount();
    }
    catch (\Exception $e) {
      $this->connection->exceptionHandler()->handleExecutionException($e$stmt[]$this->queryOptions);
    }

    return NULL;
  }

  /** * Implements PHP magic __toString method to convert the query to a string. * * @return string * The prepared statement. */
  

    }

    $this->connection->addSavepoint();
    try {
      $stmt->execute(NULL, $this->queryOptions);
      $this->connection->releaseSavepoint();
      return $stmt->rowCount();
    }
    catch (\Exception $e) {
      $this->connection->rollbackSavepoint();
      $this->connection->exceptionHandler()->handleExecutionException($e$stmt[]$this->queryOptions);
    }
  }

}
if (count($this->condition)) {
      $this->condition->compile($this->connection, $this);
      $values = $this->condition->arguments();
    }

    $stmt = $this->connection->prepareStatement((string) $this$this->queryOptions, TRUE);
    try {
      $stmt->execute($values$this->queryOptions);
      return $stmt->rowCount();
    }
    catch (\Exception $e) {
      $this->connection->exceptionHandler()->handleExecutionException($e$stmt$values$this->queryOptions);
    }
  }

  /** * Implements PHP magic __toString method to convert the query to a string. * * @return string * The prepared statement. */
  public function __toString() {
    // Create a sanitized comment string to prepend to the query.
Home | Imprint | This part of the site doesn't use cookies.