3 namespace Doctrine\DBAL\Schema;
5 class SchemaException extends \Doctrine\DBAL\DBALException
7 const TABLE_DOESNT_EXIST = 10;
8 const TABLE_ALREADY_EXISTS = 20;
9 const COLUMN_DOESNT_EXIST = 30;
10 const COLUMN_ALREADY_EXISTS = 40;
11 const INDEX_DOESNT_EXIST = 50;
12 const INDEX_ALREADY_EXISTS = 60;
13 const SEQUENCE_DOENST_EXIST = 70;
14 const SEQUENCE_ALREADY_EXISTS = 80;
15 const INDEX_INVALID_NAME = 90;
16 const FOREIGNKEY_DOESNT_EXIST = 100;
19 * @param string $tableName
20 * @return SchemaException
22 static public function tableDoesNotExist($tableName)
24 return new self("There is no table with name '".$tableName."' in the schema.", self::TABLE_DOESNT_EXIST);
28 * @param string $indexName
29 * @return SchemaException
31 static public function indexNameInvalid($indexName)
33 return new self("Invalid index-name $indexName given, has to be [a-zA-Z0-9_]", self::INDEX_INVALID_NAME);
37 * @param string $indexName
38 * @return SchemaException
40 static public function indexDoesNotExist($indexName, $table)
42 return new self("Index '$indexName' does not exist on table '$table'.", self::INDEX_DOESNT_EXIST);
46 * @param string $indexName
47 * @return SchemaException
49 static public function indexAlreadyExists($indexName, $table)
51 return new self("An index with name '$indexName' was already defined on table '$table'.", self::INDEX_ALREADY_EXISTS);
55 * @param string $columnName
56 * @return SchemaException
58 static public function columnDoesNotExist($columnName, $table)
60 return new self("There is no column with name '$columnName' on table '$table'.", self::COLUMN_DOESNT_EXIST);
65 * @param string $tableName
66 * @return SchemaException
68 static public function tableAlreadyExists($tableName)
70 return new self("The table with name '".$tableName."' already exists.", self::TABLE_ALREADY_EXISTS);
75 * @param string $tableName
76 * @param string $columnName
77 * @return SchemaException
79 static public function columnAlreadyExists($tableName, $columnName)
82 "The column '".$columnName."' on table '".$tableName."' already exists.", self::COLUMN_ALREADY_EXISTS
87 * @param string $sequenceName
88 * @return SchemaException
90 static public function sequenceAlreadyExists($sequenceName)
92 return new self("The sequence '".$sequenceName."' already exists.", self::SEQUENCE_ALREADY_EXISTS);
96 * @param string $sequenceName
97 * @return SchemaException
99 static public function sequenceDoesNotExist($sequenceName)
101 return new self("There exists no sequence with the name '".$sequenceName."'.", self::SEQUENCE_DOENST_EXIST);
105 * @param string $fkName
106 * @return SchemaException
108 static public function foreignKeyDoesNotExist($fkName, $table)
110 return new self("There exists no foreign key with the name '$fkName' on table '$table'.", self::FOREIGNKEY_DOESNT_EXIST);
113 static public function namedForeignKeyRequired(Table $localTable, ForeignKeyConstraint $foreignKey)
116 "The performed schema operation on ".$localTable->getName()." requires a named foreign key, ".
117 "but the given foreign key from (".implode(", ", $foreignKey->getColumns()).") onto foreign table ".
118 "'".$foreignKey->getForeignTableName()."' (".implode(", ", $foreignKey->getForeignColumns()).") is currently ".
123 static public function alterTableChangeNotSupported($changeName) {
124 return new self ("Alter table change not supported, given '$changeName'");