From b4112538dbd46ee7d3c25fc35f3c43aed342e429 Mon Sep 17 00:00:00 2001 From: Rick Morrison Date: Wed, 27 Sep 2006 00:01:16 +0000 Subject: NCHAR and NVARCHAR support for MS-SQL. Patch from Kent Johnson --- lib/sqlalchemy/databases/mssql.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/databases') diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index 1274174f0..0a6dfbe1f 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -148,9 +148,15 @@ class MSText(sqltypes.TEXT): class MSString(sqltypes.String): def get_col_spec(self): return "VARCHAR(%(length)s)" % {'length' : self.length} +class MSUnicode(sqltypes.Unicode): + def get_col_spec(self): + return "NVARCHAR(%(length)s)" % {'length' : self.length} class MSChar(sqltypes.CHAR): def get_col_spec(self): return "CHAR(%(length)s)" % {'length' : self.length} +class MSNChar(sqltypes.NCHAR): + def get_col_spec(self): + return "NCHAR(%(length)s)" % {'length' : self.length} class MSBinary(sqltypes.Binary): def get_col_spec(self): return "IMAGE" @@ -179,10 +185,12 @@ colspecs = { sqltypes.DateTime : MSDateTime, sqltypes.Date : MSDate, sqltypes.String : MSString, + sqltypes.Unicode : MSUnicode, sqltypes.Binary : MSBinary, sqltypes.Boolean : MSBoolean, sqltypes.TEXT : MSText, sqltypes.CHAR: MSChar, + sqltypes.NCHAR: MSNChar, } ischema_names = { @@ -190,7 +198,9 @@ ischema_names = { 'smallint' : MSSmallInteger, 'tinyint' : MSTinyInteger, 'varchar' : MSString, + 'nvarchar' : MSUnicode, 'char' : MSChar, + 'nchar' : MSNChar, 'text' : MSText, 'decimal' : MSNumeric, 'numeric' : MSNumeric, @@ -237,8 +247,8 @@ class MSSQLExecutionContext(default.DefaultExecutionContext): break if self.IINSERT: proxy("SET IDENTITY_INSERT %s ON" % compiled.statement.table.name) - super(MSSQLExecutionContext, self).pre_exec(engine, proxy, compiled, parameters, **kwargs) - + super(MSSQLExecutionContext, self).pre_exec(engine, proxy, compiled, parameters, **kwargs) + def post_exec(self, engine, proxy, compiled, parameters, **kwargs): """ Turn off the INDENTITY_INSERT mode if it's been activated, and fetch recently inserted IDENTIFY values (works only for one column) """ if getattr(compiled, "isinsert", False): -- cgit v1.2.1