Mike Bayer avatar Mike Bayer committed caff495

- mssql VARBINARY emits 'max' for length when no length specified, as is
the case already for VARCHAR, NVARCHAR [ticket:1833]

Comments (0)

Files changed (3)

 - mssql
   - the String/Unicode types, and their counterparts VARCHAR/
     NVARCHAR, emit "max" as the length when no length is 
-    specified.   This makes it more compatible with Postgresql's
-    VARCHAR type which is similarly unbounded when no length
-    specified.
+    specified, so that the default length, normally '1' 
+    as per SQL server documentation, is instead
+    'unbounded'.  This also occurs for the VARBINARY type.
+    [ticket:1833].
+
+    This behavior makes these types more closely compatible 
+    with Postgresql's VARCHAR type which is similarly unbounded 
+    when no length is specified.
 
 - mysql
   - New DBAPI support for pymysql, a pure Python port

lib/sqlalchemy/dialects/mssql/base.py

     def visit_IMAGE(self, type_):
         return "IMAGE"
 
+    def visit_VARBINARY(self, type_):
+        return self._extend(
+                        "VARBINARY", 
+                        type_, 
+                        length=type_.length or 'max')
+
     def visit_boolean(self, type_):
         return self.visit_BIT(type_)
 

test/dialect/test_mssql.py

              'BINARY(10)'),
 
             (mssql.MSVarBinary, [], {},
-             'VARBINARY'),
+             'VARBINARY(max)'),
             (mssql.MSVarBinary, [10], {},
              'VARBINARY(10)'),
 
-            (types.VARBINARY, [], {},
-             'VARBINARY'),
             (types.VARBINARY, [10], {},
              'VARBINARY(10)'),
+            (types.VARBINARY, [], {},
+             'VARBINARY(max)'),
 
             (mssql.MSImage, [], {},
              'IMAGE'),
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.