From 084b559b44bba73becc7e7fa7636d4c5ac99bb55 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 10 Oct 2012 19:34:29 -0400 Subject: - [feature] Added "collation" parameter to all String types. When present, renders as COLLATE . 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. --- lib/sqlalchemy/sql/compiler.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'lib/sqlalchemy/sql/compiler.py') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index cc41e6182..f705a216e 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -2055,11 +2055,6 @@ class DDLCompiler(engine.Compiled): class GenericTypeCompiler(engine.TypeCompiler): - def visit_CHAR(self, type_): - return "CHAR" + (type_.length and "(%d)" % type_.length or "") - - def visit_NCHAR(self, type_): - return "NCHAR" + (type_.length and "(%d)" % type_.length or "") def visit_FLOAT(self, type_): return "FLOAT" @@ -2108,11 +2103,29 @@ class GenericTypeCompiler(engine.TypeCompiler): def visit_NCLOB(self, type_): return "NCLOB" + def _render_string_type(self, type_, name): + + text = name + if type_.length: + text += "(%d)" % type_.length + if type_.collation: + text += ' COLLATE "%s"' % type_.collation + return text + + def visit_CHAR(self, type_): + return self._render_string_type(type_, "CHAR") + + def visit_NCHAR(self, type_): + return self._render_string_type(type_, "NCHAR") + def visit_VARCHAR(self, type_): - return "VARCHAR" + (type_.length and "(%d)" % type_.length or "") + return self._render_string_type(type_, "VARCHAR") def visit_NVARCHAR(self, type_): - return "NVARCHAR" + (type_.length and "(%d)" % type_.length or "") + return self._render_string_type(type_, "NVARCHAR") + + def visit_TEXT(self, type_): + return self._render_string_type(type_, "TEXT") def visit_BLOB(self, type_): return "BLOB" @@ -2126,8 +2139,6 @@ class GenericTypeCompiler(engine.TypeCompiler): def visit_BOOLEAN(self, type_): return "BOOLEAN" - def visit_TEXT(self, type_): - return "TEXT" def visit_large_binary(self, type_): return self.visit_BLOB(type_) -- cgit v1.2.1