]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
NCHAR and NVARCHAR support for MS-SQL. Patch from Kent Johnson
authorRick Morrison <rickmorrison@gmail.com>
Wed, 27 Sep 2006 00:01:16 +0000 (00:01 +0000)
committerRick Morrison <rickmorrison@gmail.com>
Wed, 27 Sep 2006 00:01:16 +0000 (00:01 +0000)
CHANGES
lib/sqlalchemy/databases/mssql.py
lib/sqlalchemy/types.py

diff --git a/CHANGES b/CHANGES
index 69abfce04b84a06f12dc20eff24e925983987571..65946b4c4986f43c4dc1ca9933a594ce04be5f9f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -15,6 +15,7 @@ to orm to allow tracking of mapper configurations, row iteration.
    -- introduces new "auto_identity_insert" option for auto-switching between "SET IDENTITY_INSERT" mode when values specified for IDENTITY columns 
    -- now supports multi-column foreign keys
    -- fix to reflecting date/datetime columns
+   -- NCHAR and NVARCHAR type support added
 - more rearrangements of unit-of-work commit scheme to better allow
 dependencies within circular flushes to work properly...updated
 task traversal/logging implementation
index 1274174f0481adc0b9ca818a44060234b72137a4..0a6dfbe1f4ac08262d39bf077a76de99dc6e295b 100644 (file)
@@ -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):
index 6f4892530fecf00f45f47015f1fa8de1ed8be61c..31c6a232ed06c27b8d82e99e54f5c165adcabe40 100644 (file)
@@ -5,7 +5,7 @@
 # the MIT License: http://www.opensource.org/licenses/mit-license.php
 
 __all__ = [ 'TypeEngine', 'TypeDecorator', 'NullTypeEngine',
-            'INT', 'CHAR', 'VARCHAR', 'TEXT', 'FLOAT', 'DECIMAL', 
+            'INT', 'CHAR', 'VARCHAR', 'NCHAR', 'TEXT', 'FLOAT', 'DECIMAL', 
             'TIMESTAMP', 'DATETIME', 'CLOB', 'BLOB', 'BOOLEAN', 'String', 'Integer', 'Smallinteger',
             'Numeric', 'Float', 'DateTime', 'Date', 'Time', 'Binary', 'Boolean', 'Unicode', 'PickleType', 'NULLTYPE',
         'SMALLINT', 'DATE', 'TIME'
@@ -270,6 +270,7 @@ class TIME(Time): pass
 class CLOB(String): pass
 class VARCHAR(String): pass
 class CHAR(String):pass
+class NCHAR(Unicode):pass
 class BLOB(Binary): pass
 class BOOLEAN(Boolean): pass