summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2008-06-22 17:52:13 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2008-06-22 17:52:13 +0000
commit8c1f08c8aa9f7fe8253323a457b207a260435dde (patch)
treea488225413d51453d31f0d56e08ca606cb45b7d0 /lib/sqlalchemy
parentb2b754c2ce3a9672a135f01246dcb9521a88e2c4 (diff)
downloadsqlalchemy-8c1f08c8aa9f7fe8253323a457b207a260435dde.tar.gz
merged r4870 from 0.4 branch, index name truncation, [ticket:820]
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/databases/access.py3
-rw-r--r--lib/sqlalchemy/databases/mssql.py2
-rw-r--r--lib/sqlalchemy/databases/mysql.py2
-rw-r--r--lib/sqlalchemy/databases/postgres.py2
-rw-r--r--lib/sqlalchemy/databases/sybase.py2
-rw-r--r--lib/sqlalchemy/sql/compiler.py22
6 files changed, 22 insertions, 11 deletions
diff --git a/lib/sqlalchemy/databases/access.py b/lib/sqlalchemy/databases/access.py
index f33452200..55b48e4bc 100644
--- a/lib/sqlalchemy/databases/access.py
+++ b/lib/sqlalchemy/databases/access.py
@@ -408,7 +408,8 @@ class AccessSchemaGenerator(compiler.SchemaGenerator):
class AccessSchemaDropper(compiler.SchemaDropper):
def visit_index(self, index):
- self.append("\nDROP INDEX [%s].[%s]" % (index.table.name, index.name))
+
+ self.append("\nDROP INDEX [%s].[%s]" % (index.table.name, self._validate_identifier(index.name, False)))
self.execute()
class AccessDefaultRunner(base.DefaultRunner):
diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py
index 1cacd81ef..4f6db935f 100644
--- a/lib/sqlalchemy/databases/mssql.py
+++ b/lib/sqlalchemy/databases/mssql.py
@@ -1031,7 +1031,7 @@ class MSSQLSchemaDropper(compiler.SchemaDropper):
def visit_index(self, index):
self.append("\nDROP INDEX %s.%s" % (
self.preparer.quote_identifier(index.table.name),
- self.preparer.quote_identifier(index.name)
+ self.preparer.quote(self._validate_identifier(index.name, False), index.quote)
))
self.execute()
diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py
index 426e97a81..ed01b77d7 100644
--- a/lib/sqlalchemy/databases/mysql.py
+++ b/lib/sqlalchemy/databases/mysql.py
@@ -2062,7 +2062,7 @@ class MySQLSchemaGenerator(compiler.SchemaGenerator):
class MySQLSchemaDropper(compiler.SchemaDropper):
def visit_index(self, index):
self.append("\nDROP INDEX %s ON %s" %
- (self.preparer.format_index(index),
+ (self.preparer.quote(self._validate_identifier(index.name, False), index.quote),
self.preparer.format_table(index.table)))
self.execute()
diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py
index 124242086..c30ca8b28 100644
--- a/lib/sqlalchemy/databases/postgres.py
+++ b/lib/sqlalchemy/databases/postgres.py
@@ -753,7 +753,7 @@ class PGSchemaGenerator(compiler.SchemaGenerator):
if index.unique:
self.append("UNIQUE ")
self.append("INDEX %s ON %s (%s)" \
- % (preparer.format_index(index),
+ % (preparer.quote(self._validate_identifier(index.name, True), index.quote),
preparer.format_table(index.table),
string.join([preparer.format_column(c) for c in index.columns], ', ')))
whereclause = index.kwargs.get('postgres_where', None)
diff --git a/lib/sqlalchemy/databases/sybase.py b/lib/sqlalchemy/databases/sybase.py
index cc8597068..45a98bec5 100644
--- a/lib/sqlalchemy/databases/sybase.py
+++ b/lib/sqlalchemy/databases/sybase.py
@@ -844,7 +844,7 @@ class SybaseSQLSchemaDropper(compiler.SchemaDropper):
def visit_index(self, index):
self.append("\nDROP INDEX %s.%s" % (
self.preparer.quote_identifier(index.table.name),
- self.preparer.quote_identifier(index.name)
+ self.preparer.quote(self._validate_identifier(index.name, False), index.quote)
))
self.execute()
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index b57fd3b18..28685cabc 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -742,6 +742,19 @@ class DDLBase(engine.SchemaIterator):
findalterables.traverse(c)
return alterables
+ def _validate_identifier(self, ident, truncate):
+ if truncate:
+ if len(ident) > self.dialect.max_identifier_length:
+ counter = getattr(self, 'counter', 0)
+ self.counter = counter + 1
+ return ident[0:self.dialect.max_identifier_length - 6] + "_" + hex(self.counter)[2:]
+ else:
+ return ident
+ else:
+ self.dialect.validate_identifier(ident)
+ return ident
+
+
class SchemaGenerator(DDLBase):
def __init__(self, dialect, connection, checkfirst=False, tables=None, **kwargs):
super(SchemaGenerator, self).__init__(connection, **kwargs)
@@ -901,7 +914,7 @@ class SchemaGenerator(DDLBase):
if index.unique:
self.append("UNIQUE ")
self.append("INDEX %s ON %s (%s)" \
- % (preparer.format_index(index),
+ % (preparer.quote(self._validate_identifier(index.name, True), index.quote),
preparer.format_table(index.table),
string.join([preparer.quote(c.name, c.quote) for c in index.columns], ', ')))
self.execute()
@@ -930,7 +943,7 @@ class SchemaDropper(DDLBase):
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.append("\nDROP INDEX " + self.preparer.quote(index, self._validate_identifier(index.name, False)))
self.execute()
def drop_foreignkey(self, constraint):
@@ -1050,10 +1063,7 @@ class IdentifierPreparer(object):
def format_constraint(self, constraint):
return self.quote(constraint.name, constraint.quote)
-
- def format_index(self, index):
- return self.quote(index.name, index.quote)
-
+
def format_table(self, table, use_schema=True, name=None):
"""Prepare a quoted table and schema name."""