summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/mysql/base.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-10-10 19:34:29 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-10-10 19:34:29 -0400
commit084b559b44bba73becc7e7fa7636d4c5ac99bb55 (patch)
tree482912c75e6bb9cea188f4b55951c43bb1d74d7a /lib/sqlalchemy/dialects/mysql/base.py
parentce2c4509176da6c125ec239931f05a946ac44d58 (diff)
downloadsqlalchemy-084b559b44bba73becc7e7fa7636d4c5ac99bb55.tar.gz
- [feature] Added "collation" parameter to all
String types. When present, renders as COLLATE <collation>. This to support the COLLATE keyword now supported by several databases including MySQL, SQLite, and Postgresql. [ticket:2276] - [change] The Text() type renders the length given to it, if a length was specified.
Diffstat (limited to 'lib/sqlalchemy/dialects/mysql/base.py')
-rw-r--r--lib/sqlalchemy/dialects/mysql/base.py30
1 files changed, 11 insertions, 19 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py
index 1ba567682..c69ed24e8 100644
--- a/lib/sqlalchemy/dialects/mysql/base.py
+++ b/lib/sqlalchemy/dialects/mysql/base.py
@@ -389,8 +389,10 @@ class _StringType(sqltypes.String):
ascii=False, binary=False,
national=False, **kw):
self.charset = charset
+
# allow collate= or collation=
- self.collation = kw.pop('collate', collation)
+ kw.setdefault('collation', kw.pop('collate', collation))
+
self.ascii = ascii
# We have to munge the 'unicode' param strictly as a dict
# otherwise 2to3 will turn it into str.
@@ -402,19 +404,6 @@ class _StringType(sqltypes.String):
self.national = national
super(_StringType, self).__init__(**kw)
- def __repr__(self):
- attributes = inspect.getargspec(self.__init__)[0][1:]
- attributes.extend(inspect.getargspec(_StringType.__init__)[0][1:])
-
- params = {}
- for attr in attributes:
- val = getattr(self, attr)
- if val is not None and val is not False:
- params[attr] = val
-
- return "%s(%s)" % (self.__class__.__name__,
- ', '.join(['%s=%r' % (k, params[k]) for k in params]))
-
class NUMERIC(_NumericType, sqltypes.NUMERIC):
"""MySQL NUMERIC type."""
@@ -1489,7 +1478,7 @@ class MySQLDDLCompiler(compiler.DDLCompiler):
opts = dict(
(
- k[len(self.dialect.name)+1:].upper(),
+ k[len(self.dialect.name) + 1:].upper(),
v
)
for k, v in table.kwargs.items()
@@ -1772,7 +1761,8 @@ class MySQLTypeCompiler(compiler.GenericTypeCompiler):
def visit_CHAR(self, type_):
if type_.length:
- return self._extend_string(type_, {}, "CHAR(%(length)s)" % {'length' : type_.length})
+ return self._extend_string(type_, {}, "CHAR(%(length)s)" %
+ {'length': type_.length})
else:
return self._extend_string(type_, {}, "CHAR")
@@ -1780,7 +1770,8 @@ class MySQLTypeCompiler(compiler.GenericTypeCompiler):
# We'll actually generate the equiv. "NATIONAL VARCHAR" instead
# of "NVARCHAR".
if type_.length:
- return self._extend_string(type_, {'national':True}, "VARCHAR(%(length)s)" % {'length': type_.length})
+ return self._extend_string(type_, {'national': True},
+ "VARCHAR(%(length)s)" % {'length': type_.length})
else:
raise exc.CompileError(
"NVARCHAR requires a length on dialect %s" %
@@ -1789,9 +1780,10 @@ class MySQLTypeCompiler(compiler.GenericTypeCompiler):
def visit_NCHAR(self, type_):
# We'll actually generate the equiv. "NATIONAL CHAR" instead of "NCHAR".
if type_.length:
- return self._extend_string(type_, {'national':True}, "CHAR(%(length)s)" % {'length': type_.length})
+ return self._extend_string(type_, {'national': True},
+ "CHAR(%(length)s)" % {'length': type_.length})
else:
- return self._extend_string(type_, {'national':True}, "CHAR")
+ return self._extend_string(type_, {'national': True}, "CHAR")
def visit_VARBINARY(self, type_):
return "VARBINARY(%d)" % type_.length