Commits

paj committed 37c8ea6

Add some new types to MSSQL; ticket #721

Comments (0)

Files changed (3)

     - fixed specification of YEAR columns when generating schema
 - mssql
     - added support for TIME columns (simulated using DATETIME) [ticket:679]
+    - added support for BIGINT, MONEY, SMALLMONEY, UNIQUEIDENTIFIER and 
+      SQL_VARIANT [ticket:721]
     - index names are now quoted when dropping from reflected tables [ticket:684]
 - postgres
     - when reflecting tables from alternate schemas, the "default" placed upon

lib/sqlalchemy/databases/mssql.py

 
 * No support for more than one ``IDENTITY`` column per table
 
-* No support for ``GUID`` type columns (yet)
-
 * pymssql has problems with binary and unicode data that this module
   does **not** work around
   
     def get_col_spec(self):
         return "INTEGER"
 
-class MSTinyInteger(sqltypes.Integer): 
+class MSBigInteger(MSInteger):
+    def get_col_spec(self):
+        return "BIGINT"
+
+class MSTinyInteger(MSInteger):
     def get_col_spec(self):
         return "TINYINT"
 
-class MSSmallInteger(sqltypes.Smallinteger):
+class MSSmallInteger(MSInteger):
     def get_col_spec(self):
         return "SMALLINT"
 
     def get_col_spec(self):
         return "TIMESTAMP"
         
+class MSMoney(sqltypes.TypeEngine):
+    def get_col_spec(self):
+        return "MONEY"
+        
+class MSSmallMoney(MSMoney):
+    def get_col_spec(self):
+        return "SMALLMONEY"
+        
+class MSUniqueIdentifier(sqltypes.TypeEngine):
+    def get_col_spec(self):
+        return "UNIQUEIDENTIFIER"
+        
+class MSVariant(sqltypes.TypeEngine):
+    def get_col_spec(self):
+        return "SQL_VARIANT"
+        
 def descriptor():
     return {'name':'mssql',
     'description':'MSSQL',
 
     ischema_names = {
         'int' : MSInteger,
+        'bigint': MSBigInteger,
         'smallint' : MSSmallInteger,
         'tinyint' : MSTinyInteger,
         'varchar' : MSString,
         'datetime' : MSDateTime,
         'smalldatetime' : MSDate,
         'binary' : MSBinary,
+        'varbinary' : MSBinary,
         'bit': MSBoolean,
         'real' : MSFloat,
         'image' : MSBinary,
         'timestamp': MSTimeStamp,
+        'money': MSMoney,
+        'smallmoney': MSSmallMoney,
+        'uniqueidentifier': MSUniqueIdentifier,
+        'sql_variant': MSVariant,
     }
 
     def __new__(cls, dbapi=None, *args, **kwargs):

test/dialect/mssql.py

+from testbase import AssertMixin
+import testbase
+from sqlalchemy import *
+from sqlalchemy.databases import mssql
+import datetime
+
+db = testbase.db
+
+class TestTypes(AssertMixin):
+
+    @testbase.supported('mssql')
+    def test_types(self):
+        tbl = Table('test', testbase.metadata,
+            Column('a', mssql.MSMoney),
+            Column('b', mssql.MSSmallMoney),
+            Column('c', mssql.MSBigInteger),
+            Column('d', mssql.MSVariant),
+            Column('e', mssql.MSUniqueIdentifier))
+        tbl.create()
+        
+        try:
+            m = BoundMetaData(db)
+            Table('test', m, autoload=True)
+            
+        finally:
+            tbl.drop()
+
+if __name__ == "__main__":
+    testbase.main()