SchemaObjectExistsException example

return $map;
  }

  /** * {@inheritdoc} */
  public function renameTable($table$new_name) {
    if (!$this->tableExists($table)) {
      throw new SchemaObjectDoesNotExistException("Cannot rename '$table' to '$new_name': table '$table' doesn't exist.");
    }
    if ($this->tableExists($new_name)) {
      throw new SchemaObjectExistsException("Cannot rename '$table' to '$new_name': table '$new_name' already exists.");
    }

    $schema = $this->introspectSchema($table);

    // SQLite doesn't allow you to rename tables outside of the current     // database. So the syntax '... RENAME TO database.table' would fail.     // So we must determine the full table name here rather than surrounding     // the table with curly braces in case the db_prefix contains a reference     // to a database outside of our existing database.     $info = $this->getPrefixInfo($new_name);
    $this->connection->query('ALTER TABLE {' . $table . '} RENAME TO [' . $info['table'] . ']');

    

  public function createTable($name$table) {
    if ($this->tableExists($name)) {
      throw new SchemaObjectExistsException("Table '$name' already exists.");
    }
    $statements = $this->createTableSql($name$table);
    foreach ($statements as $statement) {
      $this->connection->query($statement);
    }
  }

  /** * Generate SQL to create a new table from a Drupal schema definition. * * This method should be implemented in extending classes. * * @param string $name * The name of the table to create. * @param array $table * A Schema API table definition array. * * @return array * An array of SQL statements to create the table. * * @throws \BadMethodCallException * If the method is not implemented in the concrete driver class. * * @todo This method is called by Schema::createTable on the abstract class, and * therefore should be defined as well on the abstract class to prevent static * analysis errors. In D11, consider changing it to an abstract method, or to * make it private for each driver, and ::createTable actually an abstract * method here for implementation in each driver. */
return $tables;
  }

  /** * {@inheritdoc} */
  public function renameTable($table$new_name) {
    if (!$this->tableExists($table)) {
      throw new SchemaObjectDoesNotExistException("Cannot rename '$table' to '$new_name': table '$table' doesn't exist.");
    }
    if ($this->tableExists($new_name)) {
      throw new SchemaObjectExistsException("Cannot rename '$table' to '$new_name': table '$new_name' already exists.");
    }

    // Get the schema and tablename for the old table.     $table_name = $this->connection->getPrefix() . $table;
    // Index names and constraint names are global in PostgreSQL, so we need to     // rename them when renaming the table.     $indexes = $this->connection->query('SELECT indexname FROM pg_indexes WHERE schemaname = :schema AND tablename = :table', [':schema' => $this->defaultSchema, ':table' => $table_name]);

    foreach ($indexes as $index) {
      // Get the index type by suffix, e.g. idx/key/pkey.       $index_type = substr($index->indexname, strrpos($index->indexname, '_') + 1);

      
return implode(', ', $return);
  }

  /** * {@inheritdoc} */
  public function renameTable($table$new_name) {
    if (!$this->tableExists($table)) {
      throw new SchemaObjectDoesNotExistException("Cannot rename '$table' to '$new_name': table '$table' doesn't exist.");
    }
    if ($this->tableExists($new_name)) {
      throw new SchemaObjectExistsException("Cannot rename '$table' to '$new_name': table '$new_name' already exists.");
    }

    $info = $this->getPrefixInfo($new_name);
    $this->connection->query('ALTER TABLE {' . $table . '} RENAME TO [' . $info['table'] . ']');
  }

  /** * {@inheritdoc} */
  public function dropTable($table) {
    if (!$this->tableExists($table)) {
      
Home | Imprint | This part of the site doesn't use cookies.