diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-06-22 16:56:16 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-06-22 16:56:16 +0000 |
commit | b2b754c2ce3a9672a135f01246dcb9521a88e2c4 (patch) | |
tree | f8fa80996b3087adbf63c915d38a9f34c95f786f /lib/sqlalchemy/sql/compiler.py | |
parent | be2d349ade99ff83580f4197f3afa823f6be3b3a (diff) | |
download | sqlalchemy-b2b754c2ce3a9672a135f01246dcb9521a88e2c4.tar.gz |
- merged r4868, disallow overly long names from create/drop, from 0.4 branch, [ticket:571]
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 8c8374b9a..b57fd3b18 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -753,8 +753,14 @@ class SchemaGenerator(DDLBase): def get_column_specification(self, column, first_pk=False): raise NotImplementedError() + def _can_create(self, table): + self.dialect.validate_identifier(table.name) + if table.schema: + self.dialect.validate_identifier(table.schema) + return not self.checkfirst or not self.dialect.has_table(self.connection, table.name, schema=table.schema) + def visit_metadata(self, metadata): - collection = [t for t in metadata.table_iterator(reverse=False, tables=self.tables) if (not self.checkfirst or not self.dialect.has_table(self.connection, t.name, schema=t.schema))] + collection = [t for t in metadata.table_iterator(reverse=False, tables=self.tables) if self._can_create(t)] for table in collection: self.traverse_single(table) if self.dialect.supports_alter: @@ -910,13 +916,19 @@ class SchemaDropper(DDLBase): self.dialect = dialect def visit_metadata(self, metadata): - collection = [t for t in metadata.table_iterator(reverse=True, tables=self.tables) if (not self.checkfirst or self.dialect.has_table(self.connection, t.name, schema=t.schema))] + collection = [t for t in metadata.table_iterator(reverse=True, tables=self.tables) if self._can_drop(t)] if self.dialect.supports_alter: for alterable in self.find_alterables(collection): self.drop_foreignkey(alterable) for table in collection: self.traverse_single(table) + def _can_drop(self, table): + self.dialect.validate_identifier(table.name) + if table.schema: + self.dialect.validate_identifier(table.schema) + return not self.checkfirst or self.dialect.has_table(self.connection, table.name, schema=table.schema) + def visit_index(self, index): self.append("\nDROP INDEX " + self.preparer.format_index(index)) self.execute() |