/** * @param string $name * @return static */ public function dropColumn($name) { if (!empty($this->renameColumns)) { trigger_error('One statement must rename a column, other separate statements must change table definition.', E_USER_DEPRECATED); return $this; } return parent::dropColumn($name); }
public function dropColumn($columnName, $tableName = null) { if ($tableName == null) { $tableName = $this->table; } if (!TableSchema::hasTableColumn($tableName, $columnName, true)) { return false; } if (!$this->acl->hasTablePrivilege($tableName, 'alter')) { $aclErrorPrefix = $this->acl->getErrorMessagePrefix(); throw new UnauthorizedTableAddException($aclErrorPrefix . 'Table alter access forbidden on table ' . $tableName); } // Drop table column if is a non-alias column if (!array_key_exists($columnName, array_flip(TableSchema::getAllAliasTableColumns($tableName, true)))) { $sql = new Sql($this->adapter); $alterTable = new Ddl\AlterTable($tableName); $dropColumn = $alterTable->dropColumn($columnName); $query = $sql->getSqlStringForSqlObject($dropColumn); $this->adapter->query($query)->execute(); } // Remove column from directus_columns $columnsTableGateway = new TableGateway('directus_columns', $this->adapter); $columnsTableGateway->delete(['table_name' => $tableName, 'column_name' => $columnName]); // Remove column from directus_ui $uisTableGateway = new TableGateway('directus_ui', $this->adapter); $uisTableGateway->delete(['table_name' => $tableName, 'column_name' => $columnName]); return true; }
public function dropColumn($columnName, $tableName = null) { if ($tableName == null) { $tableName = $this->table; } if (!TableSchema::hasTableColumn($tableName, $columnName, true)) { return false; } // Drop table column if is a non-alias column if (!array_key_exists($columnName, array_flip(TableSchema::getAllAliasTableColumns($tableName, true)))) { $sql = new Sql($this->adapter); $alterTable = new Ddl\AlterTable($tableName); $dropColumn = $alterTable->dropColumn($columnName); $query = $sql->getSqlStringForSqlObject($dropColumn); $this->adapter->query($query)->execute(); } // Remove column from directus_columns $columnsTableGateway = new TableGateway('directus_columns', $this->adapter); $columnsTableGateway->delete(['table_name' => $tableName, 'column_name' => $columnName]); // Remove column from directus_ui $uisTableGateway = new TableGateway('directus_ui', $this->adapter); $uisTableGateway->delete(['table_name' => $tableName, 'column_name' => $columnName]); return true; }
/** * @covers Zend\Db\Sql\Ddl\AlterTable::getSqlString * @todo Implement testGetSqlString(). */ public function testGetSqlString() { $at = new AlterTable('foo'); $at->addColumn(new Column\Varchar('another', 255)); $at->changeColumn('name', new Column\Varchar('new_name', 50)); $at->dropColumn('foo'); $at->addConstraint(new Constraint\ForeignKey('my_fk', 'other_id', 'other_table', 'id', 'CASCADE', 'CASCADE')); $at->dropConstraint('my_index'); $expected = <<<EOS ALTER TABLE "foo" ADD COLUMN "another" VARCHAR(255) NOT NULL , CHANGE COLUMN "name" "new_name" VARCHAR(50) NOT NULL , DROP COLUMN "foo", ADD CONSTRAINT "my_fk" FOREIGN KEY ("other_id") REFERENCES "other_table" ("id") ON DELETE CASCADE ON UPDATE CASCADE, DROP CONSTRAINT "my_index" EOS; $this->assertEquals($expected, $at->getSqlString()); }