]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
MSSQL refactoring of BINARY type and addition of MSVarBinary and MSImage.
authorMichael Trier <mtrier@gmail.com>
Sun, 28 Dec 2008 01:46:44 +0000 (01:46 +0000)
committerMichael Trier <mtrier@gmail.com>
Sun, 28 Dec 2008 01:46:44 +0000 (01:46 +0000)
- Added in new types: MSVarBinary and MSImage
- Modified MSBinary to now return BINARY instead of IMAGE. This is a
  backwards incompatible change. Closes #1249.

CHANGES
lib/sqlalchemy/databases/mssql.py
test/dialect/mssql.py

diff --git a/CHANGES b/CHANGES
index c919e9eddd7244b783e3e03deb3035802c564207..6768a45a4f323fa16ca3f51221a0f2a3d4433934 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -39,6 +39,7 @@ CHANGES
       built from it.
 
 - mssql
+    - Added in new types: MSVarBinary and MSImage. [ticket:1249]
     - Added in the MSReal and MSNText types.
 
 - bugfixes, behavioral changes
@@ -233,6 +234,11 @@ CHANGES
       new doc section "Custom Comparators".
     
 - mssql
+    - ``MSBinary`` now returns a ``BINARY`` instead of an
+      ``IMAGE``. This is a backwards incompatible change in that
+      ``BINARY`` is a fixed length data type whereas ``IMAGE`` is
+      a variable length data type. [ticket:1249]
+
     - ``get_default_schema_name`` is now reflected from the
       database based on the user's default schema. This only works
       with MSSQL 2005 and later. [ticket:1258]
index 5bf7f28aff192d2319bc4695107a6d5654ee63dd..777c86d40f0c645aa442e001cfcd31e06008eb82 100644 (file)
@@ -677,9 +677,26 @@ class MSNChar(_StringType, sqltypes.NCHAR):
 
 
 class MSBinary(sqltypes.Binary):
+    def get_col_spec(self):
+        if self.length:
+            return "BINARY(%s)" % self.length
+        else:
+            return "BINARY"
+
+
+class MSVarBinary(MSBinary):
+    def get_col_spec(self):
+        if self.length:
+            return "VARBINARY(%s)" % self.length
+        else:
+            return "VARBINARY"
+
+
+class MSImage(MSBinary):
     def get_col_spec(self):
         return "IMAGE"
 
+
 class MSBoolean(sqltypes.Boolean):
     def get_col_spec(self):
         return "BIT"
@@ -861,10 +878,10 @@ class MSSQLDialect(default.DefaultDialect):
         'date': MSDate,
         'smalldatetime' : MSSmallDate,
         'binary' : MSBinary,
-        'varbinary' : MSBinary,
+        'varbinary' : MSVarBinary,
         'bit': MSBoolean,
         'real' : MSFloat,
-        'image' : MSBinary,
+        'image' : MSImage,
         'timestamp': MSTimeStamp,
         'money': MSMoney,
         'smallmoney': MSSmallMoney,
index 440221cb6daac907223de39407b4a63c1aabfe63..b87a1566efd37423e3257eb41e340989ba3750ed 100755 (executable)
@@ -548,6 +548,16 @@ class TypesTest2(TestBase, AssertsExecutionResults):
         columns = [
             # column type, args, kwargs, expected ddl
             (mssql.MSBinary, [], {},
+             'BINARY'),
+            (mssql.MSBinary, [10], {},
+             'BINARY(10)'),
+
+            (mssql.MSVarBinary, [], {},
+             'VARBINARY'),
+            (mssql.MSVarBinary, [10], {},
+             'VARBINARY(10)'),
+
+            (mssql.MSImage, [], {},
              'IMAGE')
            ]
 
@@ -570,6 +580,12 @@ class TypesTest2(TestBase, AssertsExecutionResults):
             assert True
         except:
             raise
+
+        reflected_binary = Table('test_mssql_binary', MetaData(testing.db), autoload=True)
+        for col in reflected_binary.c:
+            testing.eq_(col.type.__class__, binary_table.c[col.name].type.__class__)
+            if binary_table.c[col.name].type.length:
+                testing.eq_(col.type.length, binary_table.c[col.name].type.length)
         binary_table.drop()
 
     def test_boolean(self):
@@ -678,8 +694,6 @@ class TypesTest2(TestBase, AssertsExecutionResults):
              'VARCHAR'),
             (mssql.MSString, [1], {},
              'VARCHAR(1)'),
-            (mssql.MSString, ['max'], {},
-             'VARCHAR(max)'),
             (mssql.MSString, [1], {'collation': 'Latin1_General_CI_AS'},
              'VARCHAR(1) COLLATE Latin1_General_CI_AS'),
 
@@ -687,8 +701,6 @@ class TypesTest2(TestBase, AssertsExecutionResults):
              'NVARCHAR'),
             (mssql.MSNVarchar, [1], {},
              'NVARCHAR(1)'),
-            (mssql.MSNVarchar, ['max'], {},
-             'NVARCHAR(max)'),
             (mssql.MSNVarchar, [1], {'collation': 'Latin1_General_CI_AS'},
              'NVARCHAR(1) COLLATE Latin1_General_CI_AS'),