summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-06-08 14:47:04 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-06-08 14:47:04 -0400
commita80bb5393484ed2579266c8780ddea1507515e37 (patch)
tree959cf47a09a7e8754e27aa0892248fa923ba3466
parent8bf1d3fd4e561c7a1dae2a76ca91fcf948889bde (diff)
downloadsqlalchemy-a80bb5393484ed2579266c8780ddea1507515e37.tar.gz
- changelog for [ticket:2704]
- use an isinstance() check, concerned a TypeError might be indiscriminate
-rw-r--r--doc/build/changelog/changelog_08.rst9
-rw-r--r--doc/build/changelog/changelog_09.rst9
-rw-r--r--lib/sqlalchemy/dialects/mysql/base.py22
3 files changed, 31 insertions, 9 deletions
diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst
index e3b14bc28..00d8c121b 100644
--- a/doc/build/changelog/changelog_08.rst
+++ b/doc/build/changelog/changelog_08.rst
@@ -7,6 +7,15 @@
:version: 0.8.2
.. change::
+ :tags: feature, mysql
+ :tickets: 2704
+
+ The ``mysql_length`` parameter used with :class:`.Index` can now
+ be passed as a dictionary of column names/lengths, for use
+ with composite indexes. Big thanks to Roman Podolyaka for the
+ patch.
+
+ .. change::
:tags: bug, mssql
:tickets: 2747
diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst
index 10921476b..9b68b32e9 100644
--- a/doc/build/changelog/changelog_09.rst
+++ b/doc/build/changelog/changelog_09.rst
@@ -7,6 +7,15 @@
:version: 0.9.0
.. change::
+ :tags: feature, mysql
+ :tickets: 2704
+
+ The ``mysql_length`` parameter used with :class:`.Index` can now
+ be passed as a dictionary of column names/lengths, for use
+ with composite indexes. Big thanks to Roman Podolyaka for the
+ patch. Also in 0.8.2.
+
+ .. change::
:tags: bug, ext, associationproxy
:tickets: 2751
diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py
index b7cff43eb..9d856e271 100644
--- a/lib/sqlalchemy/dialects/mysql/base.py
+++ b/lib/sqlalchemy/dialects/mysql/base.py
@@ -226,6 +226,7 @@ become part of the index. SQLAlchemy provides this feature via the
``mysql_length`` parameter::
Index('my_index', my_table.c.data, mysql_length=10)
+
Index('a_b_idx', my_table.c.a, my_table.c.b, mysql_length={'a': 4, 'b': 9})
Prefix lengths are given in characters for nonbinary string types and in bytes
@@ -236,6 +237,9 @@ prefix length values for corresponding columns. MySQL only allows a length for
a column of an index if it is for a CHAR, VARCHAR, TEXT, BINARY, VARBINARY and
BLOB.
+.. versionadded:: 0.8.2 ``mysql_length`` may now be specified as a dictionary
+ for use with composite indexes.
+
Index Types
~~~~~~~~~~~~~
@@ -1525,19 +1529,19 @@ class MySQLDDLCompiler(compiler.DDLCompiler):
if 'mysql_length' in index.kwargs:
length = index.kwargs['mysql_length']
- # length value can be an integer value specifying the same
- # prefix length for all columns of the index
- try:
+ if isinstance(length, dict):
+ # length value can be a (column_name --> integer value) mapping
+ # specifying the prefix length for each column of the index
columns = ', '.join(
- '%s(%d)' % (col, length)
+ ('%s(%d)' % (col, length[col])
+ if col in length else '%s' % col)
for col in columns
)
- # otherwise it's a (column_name --> integer value) mapping
- # specifying the prefix length for each column of the index
- except TypeError:
+ else:
+ # or can be an integer value specifying the same
+ # prefix length for all columns of the index
columns = ', '.join(
- ('%s(%d)' % (col, length[col])
- if col in length else '%s' % col)
+ '%s(%d)' % (col, length)
for col in columns
)
else: