diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-10-11 00:15:43 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-10-11 00:15:43 -0400 |
| commit | a0cc36c23966bb2a5884e6760ea3efde44fc3518 (patch) | |
| tree | 2a41c3fc51f556b9f6cf012a5e3b8ec2e00f1f2e /lib | |
| parent | 879c932018fd22573163c76042761ce98ccaaaa3 (diff) | |
| download | sqlalchemy-a0cc36c23966bb2a5884e6760ea3efde44fc3518.tar.gz | |
- adjust some tests and such to work better with a mysql 5.5 install
- Added mysql_length parameter to Index construct,
specifies "length" for indexes. [ticket:2293]
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sqlalchemy/dialects/mysql/base.py | 50 | ||||
| -rw-r--r-- | lib/sqlalchemy/schema.py | 2 |
2 files changed, 52 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index 80067f9dc..1a30e15fd 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -197,6 +197,32 @@ within an application, overrides the compilation of the fully rendering CAST; else the internal element of the construct is rendered directly. + +.. _mysql_indexes: + +MySQL Specific Index Options +---------------------------- + +MySQL-specific extensions to the :class:`.Index` construct are available. + +Index Length +~~~~~~~~~~~~~ + +MySQL provides an option to create index entries with a certain length, where +"length" refers to the number of characters or bytes in each value which will +become part of the index. SQLAlchemy provides this feature via the +``mysql_length`` parameter:: + + Index('my_index', my_table.c.data, mysql_length=10) + +Prefix lengths are given in characters for nonbinary string types and in bytes +for binary string types. The value passed to the keyword argument will be +simply passed through to the underlying CREATE INDEX command, so it *must* be +an integer. MySQL only allows a length for an index if it is for a CHAR, +VARCHAR, TEXT, BINARY, VARBINARY and BLOB. + +More information can be found at: +http://dev.mysql.com/doc/refman/5.0/en/create-index.html """ import datetime, inspect, re, sys @@ -1395,6 +1421,30 @@ class MySQLDDLCompiler(compiler.DDLCompiler): table_opts.append(joiner.join((opt, arg))) return ' '.join(table_opts) + def visit_create_index(self, create): + index = create.element + preparer = self.preparer + text = "CREATE " + if index.unique: + text += "UNIQUE " + text += "INDEX %s ON %s " \ + % (preparer.quote(self._index_identifier(index.name), + index.quote),preparer.format_table(index.table)) + if 'mysql_length' in index.kwargs: + length = index.kwargs['mysql_length'] + else: + length = None + if length is not None: + text+= "(%s(%d))" \ + % (', '.join(preparer.quote(c.name, c.quote) + for c in index.columns), length) + else: + text+= "(%s)" \ + % (', '.join(preparer.quote(c.name, c.quote) + for c in index.columns)) + return text + + def visit_drop_index(self, drop): index = drop.element diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index 99c8acbfe..3d00b3197 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -2086,6 +2086,8 @@ class Index(ColumnCollectionMixin, SchemaItem): :ref:`schema_indexes` - General information on :class:`.Index`. :ref:`postgresql_indexes` - PostgreSQL-specific options available for the :class:`.Index` construct. + + :ref:`mysql_indexes` - MySQL-specific options available for the :class:`.Index` construct. """ __visit_name__ = 'index' |
