From b2c0b50bbfa43f662afd16b7ca51bcfe17e4c351 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 2 Aug 2010 01:12:03 -0400 Subject: - The generated index name also is based on a "max index name length" attribute which is separate from the "max identifier length" - this to appease MySQL who has a max length of 64 for index names, separate from their overall max length of 255. [ticket:1412] --- lib/sqlalchemy/dialects/mysql/base.py | 2 ++ lib/sqlalchemy/engine/default.py | 11 +++++++++++ lib/sqlalchemy/sql/compiler.py | 6 ++++-- 3 files changed, 17 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy') diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index 1c61f47e1..a2d3748f3 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -1607,8 +1607,10 @@ class MySQLDialect(default.DefaultDialect): name = 'mysql' supports_alter = True + # identifiers are 64, however aliases can be 255... max_identifier_length = 255 + max_index_name_length = 64 supports_native_enum = True diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index 0724d1fb9..390094c7d 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -59,7 +59,18 @@ class DefaultDialect(base.Dialect): # end Py2K name = 'default' + + # length at which to truncate + # any identifier. max_identifier_length = 9999 + + # length at which to truncate + # the name of an index. + # Usually None to indicate + # 'use max_identifier_length'. + # thanks to MySQL, sigh + max_index_name_length = None + supports_sane_rowcount = True supports_sane_multi_rowcount = True dbapi_type_map = {} diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 0383f9690..fcff5e355 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -1182,8 +1182,10 @@ class DDLCompiler(engine.Compiled): def _index_identifier(self, ident): if isinstance(ident, sql._generated_label): - if len(ident) > self.dialect.max_identifier_length: - return ident[0:self.dialect.max_identifier_length - 8] + \ + max = self.dialect.max_index_name_length or \ + self.dialect.max_identifier_length + if len(ident) > max: + return ident[0:max - 8] + \ "_" + util.md5_hex(ident)[-4:] else: return ident -- cgit v1.2.1