summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
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/sql
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/sql')
-rw-r--r--lib/sqlalchemy/sql/compiler.py29
1 files changed, 20 insertions, 9 deletions
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_)