From: Paul Johnston Date: Fri, 17 Aug 2007 16:30:02 +0000 (+0000) Subject: Add some new types to MSSQL; ticket #721 X-Git-Tag: rel_0_3_11~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d4373607668796f4503e5c27ad20866a8ff45220;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Add some new types to MSSQL; ticket #721 --- diff --git a/CHANGES b/CHANGES index 7c2adea706..983cd1dc75 100644 --- a/CHANGES +++ b/CHANGES @@ -17,6 +17,8 @@ - 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 diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index 875fa59528..72aef8f467 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -32,8 +32,6 @@ Known issues / TODO: * 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 @@ -82,11 +80,15 @@ class MSInteger(sqltypes.Integer): 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" @@ -227,6 +229,22 @@ class MSTimeStamp(sqltypes.TIMESTAMP): 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', @@ -346,6 +364,7 @@ class MSSQLDialect(ansisql.ANSIDialect): ischema_names = { 'int' : MSInteger, + 'bigint': MSBigInteger, 'smallint' : MSSmallInteger, 'tinyint' : MSTinyInteger, 'varchar' : MSString, @@ -360,10 +379,15 @@ class MSSQLDialect(ansisql.ANSIDialect): '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): diff --git a/test/dialect/mssql.py b/test/dialect/mssql.py new file mode 100644 index 0000000000..b04179177b --- /dev/null +++ b/test/dialect/mssql.py @@ -0,0 +1,29 @@ +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()