diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-08-02 01:12:03 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-08-02 01:12:03 -0400 |
| commit | b2c0b50bbfa43f662afd16b7ca51bcfe17e4c351 (patch) | |
| tree | d98573e0d6ed5308cde1c6aa32709afa86f0d7fc /lib/sqlalchemy | |
| parent | 2f844f231cbcd86dad5d4094565858424ea2c3c7 (diff) | |
| download | sqlalchemy-b2c0b50bbfa43f662afd16b7ca51bcfe17e4c351.tar.gz | |
- 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]
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/dialects/mysql/base.py | 2 | ||||
| -rw-r--r-- | lib/sqlalchemy/engine/default.py | 11 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 6 |
3 files changed, 17 insertions, 2 deletions
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 |
